From 1ea7fcb2c43d21d96c63a9e556869828b7897e9e Mon Sep 17 00:00:00 2001 From: RogueException Date: Thu, 9 Jun 2016 02:29:24 -0300 Subject: [PATCH] Refactored to use TAP naming scheme --- src/Discord.Net/API/DiscordAPIClient.cs | 470 +++++++++--------- src/Discord.Net/DiscordClient.cs | 100 ++-- src/Discord.Net/DiscordSocketClient.cs | 224 ++++----- .../Entities/Channels/DMChannel.cs | 52 +- .../Entities/Channels/GuildChannel.cs | 48 +- src/Discord.Net/Entities/Channels/IChannel.cs | 6 +- .../Entities/Channels/IDMChannel.cs | 2 +- .../Entities/Channels/IGuildChannel.cs | 18 +- .../Entities/Channels/IMessageChannel.cs | 16 +- .../Entities/Channels/ITextChannel.cs | 2 +- .../Entities/Channels/IVoiceChannel.cs | 2 +- .../Entities/Channels/TextChannel.cs | 48 +- .../Entities/Channels/VoiceChannel.cs | 10 +- src/Discord.Net/Entities/Guilds/Guild.cs | 108 ++-- .../Entities/Guilds/GuildIntegration.cs | 12 +- src/Discord.Net/Entities/Guilds/IGuild.cs | 44 +- src/Discord.Net/Entities/Guilds/UserGuild.cs | 8 +- src/Discord.Net/Entities/IDeletable.cs | 2 +- src/Discord.Net/Entities/IUpdateable.cs | 2 +- src/Discord.Net/Entities/Invites/IInvite.cs | 2 +- src/Discord.Net/Entities/Invites/Invite.cs | 8 +- src/Discord.Net/Entities/Messages/IMessage.cs | 2 +- src/Discord.Net/Entities/Messages/Message.cs | 16 +- src/Discord.Net/Entities/Roles/IRole.cs | 2 +- src/Discord.Net/Entities/Roles/Role.cs | 8 +- src/Discord.Net/Entities/Users/GuildUser.cs | 18 +- src/Discord.Net/Entities/Users/IGuildUser.cs | 4 +- src/Discord.Net/Entities/Users/ISelfUser.cs | 2 +- src/Discord.Net/Entities/Users/IUser.cs | 2 +- src/Discord.Net/Entities/Users/SelfUser.cs | 8 +- src/Discord.Net/Entities/Users/User.cs | 4 +- .../Entities/WebSocket/CachedDMChannel.cs | 18 +- .../Entities/WebSocket/CachedGuild.cs | 16 +- .../Entities/WebSocket/CachedTextChannel.cs | 18 +- .../Entities/WebSocket/CachedVoiceChannel.cs | 6 +- .../Extensions/DiscordClientExtensions.cs | 4 +- src/Discord.Net/Extensions/EventExtensions.cs | 10 +- src/Discord.Net/Extensions/GuildExtensions.cs | 8 +- src/Discord.Net/IDiscordClient.cs | 34 +- src/Discord.Net/Logging/ILogger.cs | 36 +- src/Discord.Net/Logging/LogManager.cs | 144 +++--- src/Discord.Net/Logging/Logger.cs | 80 +-- src/Discord.Net/Net/Queue/IQueuedRequest.cs | 2 +- src/Discord.Net/Net/Queue/RequestQueue.cs | 12 +- .../Net/Queue/RequestQueueBucket.cs | 18 +- src/Discord.Net/Net/Queue/RestRequest.cs | 8 +- src/Discord.Net/Net/Queue/WebSocketRequest.cs | 4 +- src/Discord.Net/Net/Rest/DefaultRestClient.cs | 14 +- src/Discord.Net/Net/Rest/IRestClient.cs | 6 +- .../Net/WebSockets/DefaultWebsocketClient.cs | 16 +- .../Net/WebSockets/IWebSocketClient.cs | 6 +- src/Discord.Net/Utilities/MessageCache.cs | 8 +- 52 files changed, 859 insertions(+), 859 deletions(-) diff --git a/src/Discord.Net/API/DiscordAPIClient.cs b/src/Discord.Net/API/DiscordAPIClient.cs index c6007d2dd..95b331b1e 100644 --- a/src/Discord.Net/API/DiscordAPIClient.cs +++ b/src/Discord.Net/API/DiscordAPIClient.cs @@ -66,14 +66,14 @@ namespace Discord.API using (var reader = new StreamReader(decompressed)) { var msg = JsonConvert.DeserializeObject(reader.ReadToEnd()); - await ReceivedGatewayEvent.Raise((GatewayOpCode)msg.Operation, msg.Sequence, msg.Type, msg.Payload).ConfigureAwait(false); + await ReceivedGatewayEvent.RaiseAsync((GatewayOpCode)msg.Operation, msg.Sequence, msg.Type, msg.Payload).ConfigureAwait(false); } } }; _gatewayClient.TextMessage += async text => { var msg = JsonConvert.DeserializeObject(text); - await ReceivedGatewayEvent.Raise((GatewayOpCode)msg.Operation, msg.Sequence, msg.Type, msg.Payload).ConfigureAwait(false); + await ReceivedGatewayEvent.RaiseAsync((GatewayOpCode)msg.Operation, msg.Sequence, msg.Type, msg.Payload).ConfigureAwait(false); }; } @@ -93,19 +93,19 @@ namespace Discord.API } public void Dispose() => Dispose(true); - public async Task Login(TokenType tokenType, string token, RequestOptions options = null) + public async Task LoginAsync(TokenType tokenType, string token, RequestOptions options = null) { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await LoginInternal(tokenType, token, options).ConfigureAwait(false); + await LoginInternalAsync(tokenType, token, options).ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task LoginInternal(TokenType tokenType, string token, RequestOptions options = null) + private async Task LoginInternalAsync(TokenType tokenType, string token, RequestOptions options = null) { if (LoginState != LoginState.LoggedOut) - await LogoutInternal().ConfigureAwait(false); + await LogoutInternalAsync().ConfigureAwait(false); LoginState = LoginState.LoggingIn; try @@ -115,7 +115,7 @@ namespace Discord.API AuthTokenType = TokenType.User; _authToken = null; _restClient.SetHeader("authorization", null); - await _requestQueue.SetCancelToken(_loginCancelToken.Token).ConfigureAwait(false); + await _requestQueue.SetCancelTokenAsync(_loginCancelToken.Token).ConfigureAwait(false); _restClient.SetCancelToken(_loginCancelToken.Token); AuthTokenType = tokenType; @@ -139,21 +139,21 @@ namespace Discord.API } catch (Exception) { - await LogoutInternal().ConfigureAwait(false); + await LogoutInternalAsync().ConfigureAwait(false); throw; } } - public async Task Logout() + public async Task LogoutAsync() { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await LogoutInternal().ConfigureAwait(false); + await LogoutInternalAsync().ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task LogoutInternal() + private async Task LogoutInternalAsync() { //TODO: An exception here will lock the client into the unusable LoggingOut state. How should we handle? (Add same solution to both DiscordClients too) if (LoginState == LoginState.LoggedOut) return; @@ -162,25 +162,25 @@ namespace Discord.API try { _loginCancelToken?.Cancel(false); } catch { } - await DisconnectInternal().ConfigureAwait(false); - await _requestQueue.Clear().ConfigureAwait(false); + await DisconnectInternalAsync().ConfigureAwait(false); + await _requestQueue.ClearAsync().ConfigureAwait(false); - await _requestQueue.SetCancelToken(CancellationToken.None).ConfigureAwait(false); + await _requestQueue.SetCancelTokenAsync(CancellationToken.None).ConfigureAwait(false); _restClient.SetCancelToken(CancellationToken.None); LoginState = LoginState.LoggedOut; } - public async Task Connect() + public async Task ConnectAsync() { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await ConnectInternal().ConfigureAwait(false); + await ConnectInternalAsync().ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task ConnectInternal() + private async Task ConnectInternalAsync() { if (LoginState != LoginState.LoggedIn) throw new InvalidOperationException("You must log in before connecting."); @@ -194,29 +194,29 @@ namespace Discord.API if (_gatewayClient != null) _gatewayClient.SetCancelToken(_connectCancelToken.Token); - var gatewayResponse = await GetGateway().ConfigureAwait(false); + var gatewayResponse = await GetGatewayAsync().ConfigureAwait(false); var url = $"{gatewayResponse.Url}?v={DiscordConfig.GatewayAPIVersion}&encoding={DiscordConfig.GatewayEncoding}"; - await _gatewayClient.Connect(url).ConfigureAwait(false); + await _gatewayClient.ConnectAsync(url).ConfigureAwait(false); ConnectionState = ConnectionState.Connected; } catch (Exception) { - await DisconnectInternal().ConfigureAwait(false); + await DisconnectInternalAsync().ConfigureAwait(false); throw; } } - public async Task Disconnect() + public async Task DisconnectAsync() { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await DisconnectInternal().ConfigureAwait(false); + await DisconnectInternalAsync().ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task DisconnectInternal() + private async Task DisconnectInternalAsync() { if (_gatewayClient == null) throw new NotSupportedException("This client is not configured with websocket support."); @@ -227,105 +227,105 @@ namespace Discord.API try { _connectCancelToken?.Cancel(false); } catch { } - await _gatewayClient.Disconnect().ConfigureAwait(false); + await _gatewayClient.DisconnectAsync().ConfigureAwait(false); ConnectionState = ConnectionState.Disconnected; } //Core - public Task Send(string method, string endpoint, + public Task SendAsync(string method, string endpoint, GlobalBucket bucket = GlobalBucket.GeneralRest, RequestOptions options = null) - => SendInternal(method, endpoint, null, true, bucket, options); - public Task Send(string method, string endpoint, object payload, + => SendInternalAsync(method, endpoint, null, true, bucket, options); + public Task SendAsync(string method, string endpoint, object payload, GlobalBucket bucket = GlobalBucket.GeneralRest, RequestOptions options = null) - => SendInternal(method, endpoint, payload, true, bucket, options); - public Task Send(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, + => SendInternalAsync(method, endpoint, payload, true, bucket, options); + public Task SendAsync(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, GlobalBucket bucket = GlobalBucket.GeneralRest, RequestOptions options = null) - => SendInternal(method, endpoint, multipartArgs, true, bucket, options); - public async Task Send(string method, string endpoint, + => SendInternalAsync(method, endpoint, multipartArgs, true, bucket, options); + public async Task SendAsync(string method, string endpoint, GlobalBucket bucket = GlobalBucket.GeneralRest, RequestOptions options = null) where TResponse : class - => DeserializeJson(await SendInternal(method, endpoint, null, false, bucket, options).ConfigureAwait(false)); - public async Task Send(string method, string endpoint, object payload, GlobalBucket bucket = + => DeserializeJson(await SendInternalAsync(method, endpoint, null, false, bucket, options).ConfigureAwait(false)); + public async Task SendAsync(string method, string endpoint, object payload, GlobalBucket bucket = GlobalBucket.GeneralRest, RequestOptions options = null) where TResponse : class - => DeserializeJson(await SendInternal(method, endpoint, payload, false, bucket, options).ConfigureAwait(false)); - public async Task Send(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, + => DeserializeJson(await SendInternalAsync(method, endpoint, payload, false, bucket, options).ConfigureAwait(false)); + public async Task SendAsync(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, GlobalBucket bucket = GlobalBucket.GeneralRest, RequestOptions options = null) where TResponse : class - => DeserializeJson(await SendInternal(method, endpoint, multipartArgs, false, bucket, options).ConfigureAwait(false)); + => DeserializeJson(await SendInternalAsync(method, endpoint, multipartArgs, false, bucket, options).ConfigureAwait(false)); - public Task Send(string method, string endpoint, + public Task SendAsync(string method, string endpoint, GuildBucket bucket, ulong guildId, RequestOptions options = null) - => SendInternal(method, endpoint, null, true, bucket, guildId, options); - public Task Send(string method, string endpoint, object payload, + => SendInternalAsync(method, endpoint, null, true, bucket, guildId, options); + public Task SendAsync(string method, string endpoint, object payload, GuildBucket bucket, ulong guildId, RequestOptions options = null) - => SendInternal(method, endpoint, payload, true, bucket, guildId, options); - public Task Send(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, + => SendInternalAsync(method, endpoint, payload, true, bucket, guildId, options); + public Task SendAsync(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, GuildBucket bucket, ulong guildId, RequestOptions options = null) - => SendInternal(method, endpoint, multipartArgs, true, bucket, guildId, options); - public async Task Send(string method, string endpoint, + => SendInternalAsync(method, endpoint, multipartArgs, true, bucket, guildId, options); + public async Task SendAsync(string method, string endpoint, GuildBucket bucket, ulong guildId, RequestOptions options = null) where TResponse : class - => DeserializeJson(await SendInternal(method, endpoint, null, false, bucket, guildId, options).ConfigureAwait(false)); - public async Task Send(string method, string endpoint, object payload, + => DeserializeJson(await SendInternalAsync(method, endpoint, null, false, bucket, guildId, options).ConfigureAwait(false)); + public async Task SendAsync(string method, string endpoint, object payload, GuildBucket bucket, ulong guildId, RequestOptions options = null) where TResponse : class - => DeserializeJson(await SendInternal(method, endpoint, payload, false, bucket, guildId, options).ConfigureAwait(false)); - public async Task Send(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, + => DeserializeJson(await SendInternalAsync(method, endpoint, payload, false, bucket, guildId, options).ConfigureAwait(false)); + public async Task SendAsync(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs, GuildBucket bucket, ulong guildId, RequestOptions options = null) where TResponse : class - => DeserializeJson(await SendInternal(method, endpoint, multipartArgs, false, bucket, guildId, options).ConfigureAwait(false)); + => DeserializeJson(await SendInternalAsync(method, endpoint, multipartArgs, false, bucket, guildId, options).ConfigureAwait(false)); - private Task SendInternal(string method, string endpoint, object payload, bool headerOnly, + private Task SendInternalAsync(string method, string endpoint, object payload, bool headerOnly, GlobalBucket bucket, RequestOptions options) - => SendInternal(method, endpoint, payload, headerOnly, BucketGroup.Global, (int)bucket, 0, options); - private Task SendInternal(string method, string endpoint, object payload, bool headerOnly, + => SendInternalAsync(method, endpoint, payload, headerOnly, BucketGroup.Global, (int)bucket, 0, options); + private Task SendInternalAsync(string method, string endpoint, object payload, bool headerOnly, GuildBucket bucket, ulong guildId, RequestOptions options) - => SendInternal(method, endpoint, payload, headerOnly, BucketGroup.Guild, (int)bucket, guildId, options); - private Task SendInternal(string method, string endpoint, IReadOnlyDictionary multipartArgs, bool headerOnly, + => SendInternalAsync(method, endpoint, payload, headerOnly, BucketGroup.Guild, (int)bucket, guildId, options); + private Task SendInternalAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, bool headerOnly, GlobalBucket bucket, RequestOptions options) - => SendInternal(method, endpoint, multipartArgs, headerOnly, BucketGroup.Global, (int)bucket, 0, options); - private Task SendInternal(string method, string endpoint, IReadOnlyDictionary multipartArgs, bool headerOnly, + => SendInternalAsync(method, endpoint, multipartArgs, headerOnly, BucketGroup.Global, (int)bucket, 0, options); + private Task SendInternalAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, bool headerOnly, GuildBucket bucket, ulong guildId, RequestOptions options) - => SendInternal(method, endpoint, multipartArgs, headerOnly, BucketGroup.Guild, (int)bucket, guildId, options); + => SendInternalAsync(method, endpoint, multipartArgs, headerOnly, BucketGroup.Guild, (int)bucket, guildId, options); - private async Task SendInternal(string method, string endpoint, object payload, bool headerOnly, + private async Task SendInternalAsync(string method, string endpoint, object payload, bool headerOnly, BucketGroup group, int bucketId, ulong guildId, RequestOptions options = null) { var stopwatch = Stopwatch.StartNew(); string json = null; if (payload != null) json = SerializeJson(payload); - var responseStream = await _requestQueue.Send(new RestRequest(_restClient, method, endpoint, json, headerOnly, options), group, bucketId, guildId).ConfigureAwait(false); + var responseStream = await _requestQueue.SendAsync(new RestRequest(_restClient, method, endpoint, json, headerOnly, options), group, bucketId, guildId).ConfigureAwait(false); stopwatch.Stop(); double milliseconds = ToMilliseconds(stopwatch); - await SentRequest.Raise(method, endpoint, milliseconds).ConfigureAwait(false); + await SentRequest.RaiseAsync(method, endpoint, milliseconds).ConfigureAwait(false); return responseStream; } - private async Task SendInternal(string method, string endpoint, IReadOnlyDictionary multipartArgs, bool headerOnly, + private async Task SendInternalAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, bool headerOnly, BucketGroup group, int bucketId, ulong guildId, RequestOptions options = null) { var stopwatch = Stopwatch.StartNew(); - var responseStream = await _requestQueue.Send(new RestRequest(_restClient, method, endpoint, multipartArgs, headerOnly, options), group, bucketId, guildId).ConfigureAwait(false); + var responseStream = await _requestQueue.SendAsync(new RestRequest(_restClient, method, endpoint, multipartArgs, headerOnly, options), group, bucketId, guildId).ConfigureAwait(false); int bytes = headerOnly ? 0 : (int)responseStream.Length; stopwatch.Stop(); double milliseconds = ToMilliseconds(stopwatch); - await SentRequest.Raise(method, endpoint, milliseconds).ConfigureAwait(false); + await SentRequest.RaiseAsync(method, endpoint, milliseconds).ConfigureAwait(false); return responseStream; } - public Task SendGateway(GatewayOpCode opCode, object payload, + public Task SendGatewayAsync(GatewayOpCode opCode, object payload, GlobalBucket bucket = GlobalBucket.GeneralGateway, RequestOptions options = null) - => SendGateway(opCode, payload, BucketGroup.Global, (int)bucket, 0, options); - public Task SendGateway(GatewayOpCode opCode, object payload, + => SendGatewayAsync(opCode, payload, BucketGroup.Global, (int)bucket, 0, options); + public Task SendGatewayAsync(GatewayOpCode opCode, object payload, GuildBucket bucket, ulong guildId, RequestOptions options = null) - => SendGateway(opCode, payload, BucketGroup.Guild, (int)bucket, guildId, options); - private async Task SendGateway(GatewayOpCode opCode, object payload, + => SendGatewayAsync(opCode, payload, BucketGroup.Guild, (int)bucket, guildId, options); + private async Task SendGatewayAsync(GatewayOpCode opCode, object payload, BucketGroup group, int bucketId, ulong guildId, RequestOptions options) { //TODO: Add ETF @@ -333,22 +333,22 @@ namespace Discord.API payload = new WebSocketMessage { Operation = (int)opCode, Payload = payload }; if (payload != null) bytes = Encoding.UTF8.GetBytes(SerializeJson(payload)); - await _requestQueue.Send(new WebSocketRequest(_gatewayClient, bytes, true, options), group, bucketId, guildId).ConfigureAwait(false); - await SentGatewayMessage.Raise((int)opCode).ConfigureAwait(false); + await _requestQueue.SendAsync(new WebSocketRequest(_gatewayClient, bytes, true, options), group, bucketId, guildId).ConfigureAwait(false); + await SentGatewayMessage.RaiseAsync((int)opCode).ConfigureAwait(false); } //Auth - public async Task ValidateToken(RequestOptions options = null) + public async Task ValidateTokenAsync(RequestOptions options = null) { - await Send("GET", "auth/login", options: options).ConfigureAwait(false); + await SendAsync("GET", "auth/login", options: options).ConfigureAwait(false); } //Gateway - public async Task GetGateway(RequestOptions options = null) + public async Task GetGatewayAsync(RequestOptions options = null) { - return await Send("GET", "gateway", options: options).ConfigureAwait(false); + return await SendAsync("GET", "gateway", options: options).ConfigureAwait(false); } - public async Task SendIdentify(int largeThreshold = 100, bool useCompression = true, RequestOptions options = null) + public async Task SendIdentifyAsync(int largeThreshold = 100, bool useCompression = true, RequestOptions options = null) { var props = new Dictionary { @@ -361,82 +361,82 @@ namespace Discord.API LargeThreshold = largeThreshold, UseCompression = useCompression }; - await SendGateway(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false); + await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false); } - public async Task SendHeartbeat(int lastSeq, RequestOptions options = null) + public async Task SendHeartbeatAsync(int lastSeq, RequestOptions options = null) { - await SendGateway(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false); + await SendGatewayAsync(GatewayOpCode.Heartbeat, lastSeq, options: options).ConfigureAwait(false); } - public async Task SendRequestMembers(IEnumerable guildIds, RequestOptions options = null) + public async Task SendRequestMembersAsync(IEnumerable guildIds, RequestOptions options = null) { - await SendGateway(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options).ConfigureAwait(false); + await SendGatewayAsync(GatewayOpCode.RequestGuildMembers, new RequestMembersParams { GuildIds = guildIds, Query = "", Limit = 0 }, options: options).ConfigureAwait(false); } //Channels - public async Task GetChannel(ulong channelId, RequestOptions options = null) + public async Task GetChannelAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); try { - return await Send("GET", $"channels/{channelId}", options: options).ConfigureAwait(false); + return await SendAsync("GET", $"channels/{channelId}", options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task GetChannel(ulong guildId, ulong channelId, RequestOptions options = null) + public async Task GetChannelAsync(ulong guildId, ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(channelId, 0, nameof(channelId)); try { - var model = await Send("GET", $"channels/{channelId}", options: options).ConfigureAwait(false); + var model = await SendAsync("GET", $"channels/{channelId}", options: options).ConfigureAwait(false); if (model.GuildId != guildId) return null; return model; } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task> GetGuildChannels(ulong guildId, RequestOptions options = null) + public async Task> GetGuildChannelsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send>("GET", $"guilds/{guildId}/channels", options: options).ConfigureAwait(false); + return await SendAsync>("GET", $"guilds/{guildId}/channels", options: options).ConfigureAwait(false); } - public async Task CreateGuildChannel(ulong guildId, CreateGuildChannelParams args, RequestOptions options = null) + public async Task CreateGuildChannelAsync(ulong guildId, CreateGuildChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); Preconditions.GreaterThan(args.Bitrate, 0, nameof(args.Bitrate)); Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); - return await Send("POST", $"guilds/{guildId}/channels", args, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"guilds/{guildId}/channels", args, options: options).ConfigureAwait(false); } - public async Task DeleteChannel(ulong channelId, RequestOptions options = null) + public async Task DeleteChannelAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); - return await Send("DELETE", $"channels/{channelId}", options: options).ConfigureAwait(false); + return await SendAsync("DELETE", $"channels/{channelId}", options: options).ConfigureAwait(false); } - public async Task ModifyGuildChannel(ulong channelId, ModifyGuildChannelParams args, RequestOptions options = null) + public async Task ModifyGuildChannelAsync(ulong channelId, ModifyGuildChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); - return await Send("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); } - public async Task ModifyGuildChannel(ulong channelId, ModifyTextChannelParams args, RequestOptions options = null) + public async Task ModifyGuildChannelAsync(ulong channelId, ModifyTextChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); - return await Send("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); } - public async Task ModifyGuildChannel(ulong channelId, ModifyVoiceChannelParams args, RequestOptions options = null) + public async Task ModifyGuildChannelAsync(ulong channelId, ModifyVoiceChannelParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -445,9 +445,9 @@ namespace Discord.API Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); - return await Send("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); } - public async Task ModifyGuildChannels(ulong guildId, IEnumerable args, RequestOptions options = null) + public async Task ModifyGuildChannelsAsync(ulong guildId, IEnumerable args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -458,58 +458,58 @@ namespace Discord.API case 0: return; case 1: - await ModifyGuildChannel(channels[0].Id, new ModifyGuildChannelParams { Position = channels[0].Position }).ConfigureAwait(false); + await ModifyGuildChannelAsync(channels[0].Id, new ModifyGuildChannelParams { Position = channels[0].Position }).ConfigureAwait(false); break; default: - await Send("PATCH", $"guilds/{guildId}/channels", channels, options: options).ConfigureAwait(false); + await SendAsync("PATCH", $"guilds/{guildId}/channels", channels, options: options).ConfigureAwait(false); break; } } //Channel Permissions - public async Task ModifyChannelPermissions(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) + public async Task ModifyChannelPermissionsAsync(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); - await Send("PUT", $"channels/{channelId}/permissions/{targetId}", args, options: options).ConfigureAwait(false); + await SendAsync("PUT", $"channels/{channelId}/permissions/{targetId}", args, options: options).ConfigureAwait(false); } - public async Task DeleteChannelPermission(ulong channelId, ulong targetId, RequestOptions options = null) + public async Task DeleteChannelPermissionAsync(ulong channelId, ulong targetId, RequestOptions options = null) { - await Send("DELETE", $"channels/{channelId}/permissions/{targetId}", options: options).ConfigureAwait(false); + await SendAsync("DELETE", $"channels/{channelId}/permissions/{targetId}", options: options).ConfigureAwait(false); } //Guilds - public async Task GetGuild(ulong guildId, RequestOptions options = null) + public async Task GetGuildAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); try { - return await Send("GET", $"guilds/{guildId}", options: options).ConfigureAwait(false); + return await SendAsync("GET", $"guilds/{guildId}", options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task CreateGuild(CreateGuildParams args, RequestOptions options = null) + public async Task CreateGuildAsync(CreateGuildParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); Preconditions.NotNullOrWhitespace(args.Region, nameof(args.Region)); - return await Send("POST", "guilds", args, options: options).ConfigureAwait(false); + return await SendAsync("POST", "guilds", args, options: options).ConfigureAwait(false); } - public async Task DeleteGuild(ulong guildId, RequestOptions options = null) + public async Task DeleteGuildAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send("DELETE", $"guilds/{guildId}", options: options).ConfigureAwait(false); + return await SendAsync("DELETE", $"guilds/{guildId}", options: options).ConfigureAwait(false); } - public async Task LeaveGuild(ulong guildId, RequestOptions options = null) + public async Task LeaveGuildAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send("DELETE", $"users/@me/guilds/{guildId}", options: options).ConfigureAwait(false); + return await SendAsync("DELETE", $"users/@me/guilds/{guildId}", options: options).ConfigureAwait(false); } - public async Task ModifyGuild(ulong guildId, ModifyGuildParams args, RequestOptions options = null) + public async Task ModifyGuildAsync(ulong guildId, ModifyGuildParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -520,91 +520,91 @@ namespace Discord.API Preconditions.NotNull(args.Region, nameof(args.Region)); Preconditions.AtLeast(args.VerificationLevel, 0, nameof(args.VerificationLevel)); - return await Send("PATCH", $"guilds/{guildId}", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"guilds/{guildId}", args, options: options).ConfigureAwait(false); } - public async Task BeginGuildPrune(ulong guildId, GuildPruneParams args, RequestOptions options = null) + public async Task BeginGuildPruneAsync(ulong guildId, GuildPruneParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Days, 0, nameof(args.Days)); - return await Send("POST", $"guilds/{guildId}/prune", args, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"guilds/{guildId}/prune", args, options: options).ConfigureAwait(false); } - public async Task GetGuildPruneCount(ulong guildId, GuildPruneParams args, RequestOptions options = null) + public async Task GetGuildPruneCountAsync(ulong guildId, GuildPruneParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.Days, 0, nameof(args.Days)); - return await Send("GET", $"guilds/{guildId}/prune", args, options: options).ConfigureAwait(false); + return await SendAsync("GET", $"guilds/{guildId}/prune", args, options: options).ConfigureAwait(false); } //Guild Bans - public async Task> GetGuildBans(ulong guildId, RequestOptions options = null) + public async Task> GetGuildBansAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send>("GET", $"guilds/{guildId}/bans", options: options).ConfigureAwait(false); + return await SendAsync>("GET", $"guilds/{guildId}/bans", options: options).ConfigureAwait(false); } - public async Task CreateGuildBan(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) + public async Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.PruneDays, 0, nameof(args.PruneDays)); - await Send("PUT", $"guilds/{guildId}/bans/{userId}", args, options: options).ConfigureAwait(false); + await SendAsync("PUT", $"guilds/{guildId}/bans/{userId}", args, options: options).ConfigureAwait(false); } - public async Task RemoveGuildBan(ulong guildId, ulong userId, RequestOptions options = null) + public async Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); - await Send("DELETE", $"guilds/{guildId}/bans/{userId}", options: options).ConfigureAwait(false); + await SendAsync("DELETE", $"guilds/{guildId}/bans/{userId}", options: options).ConfigureAwait(false); } //Guild Embeds - public async Task GetGuildEmbed(ulong guildId, RequestOptions options = null) + public async Task GetGuildEmbedAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); try { - return await Send("GET", $"guilds/{guildId}/embed", options: options).ConfigureAwait(false); + return await SendAsync("GET", $"guilds/{guildId}/embed", options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task ModifyGuildEmbed(ulong guildId, ModifyGuildEmbedParams args, RequestOptions options = null) + public async Task ModifyGuildEmbedAsync(ulong guildId, ModifyGuildEmbedParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send("PATCH", $"guilds/{guildId}/embed", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"guilds/{guildId}/embed", args, options: options).ConfigureAwait(false); } //Guild Integrations - public async Task> GetGuildIntegrations(ulong guildId, RequestOptions options = null) + public async Task> GetGuildIntegrationsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send>("GET", $"guilds/{guildId}/integrations", options: options).ConfigureAwait(false); + return await SendAsync>("GET", $"guilds/{guildId}/integrations", options: options).ConfigureAwait(false); } - public async Task CreateGuildIntegration(ulong guildId, CreateGuildIntegrationParams args, RequestOptions options = null) + public async Task CreateGuildIntegrationAsync(ulong guildId, CreateGuildIntegrationParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(args.Id, 0, nameof(args.Id)); - return await Send("POST", $"guilds/{guildId}/integrations", options: options).ConfigureAwait(false); + return await SendAsync("POST", $"guilds/{guildId}/integrations", options: options).ConfigureAwait(false); } - public async Task DeleteGuildIntegration(ulong guildId, ulong integrationId, RequestOptions options = null) + public async Task DeleteGuildIntegrationAsync(ulong guildId, ulong integrationId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(integrationId, 0, nameof(integrationId)); - return await Send("DELETE", $"guilds/{guildId}/integrations/{integrationId}", options: options).ConfigureAwait(false); + return await SendAsync("DELETE", $"guilds/{guildId}/integrations/{integrationId}", options: options).ConfigureAwait(false); } - public async Task ModifyGuildIntegration(ulong guildId, ulong integrationId, ModifyGuildIntegrationParams args, RequestOptions options = null) + public async Task ModifyGuildIntegrationAsync(ulong guildId, ulong integrationId, ModifyGuildIntegrationParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(integrationId, 0, nameof(integrationId)); @@ -612,74 +612,74 @@ namespace Discord.API Preconditions.AtLeast(args.ExpireBehavior, 0, nameof(args.ExpireBehavior)); Preconditions.AtLeast(args.ExpireGracePeriod, 0, nameof(args.ExpireGracePeriod)); - return await Send("PATCH", $"guilds/{guildId}/integrations/{integrationId}", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"guilds/{guildId}/integrations/{integrationId}", args, options: options).ConfigureAwait(false); } - public async Task SyncGuildIntegration(ulong guildId, ulong integrationId, RequestOptions options = null) + public async Task SyncGuildIntegrationAsync(ulong guildId, ulong integrationId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(integrationId, 0, nameof(integrationId)); - return await Send("POST", $"guilds/{guildId}/integrations/{integrationId}/sync", options: options).ConfigureAwait(false); + return await SendAsync("POST", $"guilds/{guildId}/integrations/{integrationId}/sync", options: options).ConfigureAwait(false); } //Guild Invites - public async Task GetInvite(string inviteIdOrXkcd, RequestOptions options = null) + public async Task GetInviteAsync(string inviteIdOrXkcd, RequestOptions options = null) { Preconditions.NotNullOrEmpty(inviteIdOrXkcd, nameof(inviteIdOrXkcd)); try { - return await Send("GET", $"invites/{inviteIdOrXkcd}", options: options).ConfigureAwait(false); + return await SendAsync("GET", $"invites/{inviteIdOrXkcd}", options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task> GetGuildInvites(ulong guildId, RequestOptions options = null) + public async Task> GetGuildInvitesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send>("GET", $"guilds/{guildId}/invites", options: options).ConfigureAwait(false); + return await SendAsync>("GET", $"guilds/{guildId}/invites", options: options).ConfigureAwait(false); } - public async Task GetChannelInvites(ulong channelId, RequestOptions options = null) + public async Task GetChannelInvitesAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); - return await Send("GET", $"channels/{channelId}/invites", options: options).ConfigureAwait(false); + return await SendAsync("GET", $"channels/{channelId}/invites", options: options).ConfigureAwait(false); } - public async Task CreateChannelInvite(ulong channelId, CreateChannelInviteParams args, RequestOptions options = null) + public async Task CreateChannelInviteAsync(ulong channelId, CreateChannelInviteParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); Preconditions.AtLeast(args.MaxAge, 0, nameof(args.MaxAge)); Preconditions.AtLeast(args.MaxUses, 0, nameof(args.MaxUses)); - return await Send("POST", $"channels/{channelId}/invites", args, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"channels/{channelId}/invites", args, options: options).ConfigureAwait(false); } - public async Task DeleteInvite(string inviteCode, RequestOptions options = null) + public async Task DeleteInviteAsync(string inviteCode, RequestOptions options = null) { Preconditions.NotNullOrEmpty(inviteCode, nameof(inviteCode)); - return await Send("DELETE", $"invites/{inviteCode}", options: options).ConfigureAwait(false); + return await SendAsync("DELETE", $"invites/{inviteCode}", options: options).ConfigureAwait(false); } - public async Task AcceptInvite(string inviteCode, RequestOptions options = null) + public async Task AcceptInviteAsync(string inviteCode, RequestOptions options = null) { Preconditions.NotNullOrEmpty(inviteCode, nameof(inviteCode)); - await Send("POST", $"invites/{inviteCode}", options: options).ConfigureAwait(false); + await SendAsync("POST", $"invites/{inviteCode}", options: options).ConfigureAwait(false); } //Guild Members - public async Task GetGuildMember(ulong guildId, ulong userId, RequestOptions options = null) + public async Task GetGuildMemberAsync(ulong guildId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); try { - return await Send("GET", $"guilds/{guildId}/members/{userId}", options: options).ConfigureAwait(false); + return await SendAsync("GET", $"guilds/{guildId}/members/{userId}", options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task> GetGuildMembers(ulong guildId, GetGuildMembersParams args, RequestOptions options = null) + public async Task> GetGuildMembersAsync(ulong guildId, GetGuildMembersParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -699,7 +699,7 @@ namespace Discord.API { int runLimit = (limit >= DiscordConfig.MaxUsersPerBatch) ? DiscordConfig.MaxUsersPerBatch : limit; string endpoint = $"guilds/{guildId}/members?limit={runLimit}&offset={offset}"; - var models = await Send("GET", endpoint, options: options).ConfigureAwait(false); + var models = await SendAsync("GET", endpoint, options: options).ConfigureAwait(false); //Was this an empty batch? if (models.Length == 0) break; @@ -720,43 +720,43 @@ namespace Discord.API else return ImmutableArray.Create(); } - public async Task RemoveGuildMember(ulong guildId, ulong userId, RequestOptions options = null) + public async Task RemoveGuildMemberAsync(ulong guildId, ulong userId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); - await Send("DELETE", $"guilds/{guildId}/members/{userId}", options: options).ConfigureAwait(false); + await SendAsync("DELETE", $"guilds/{guildId}/members/{userId}", options: options).ConfigureAwait(false); } - public async Task ModifyGuildMember(ulong guildId, ulong userId, ModifyGuildMemberParams args, RequestOptions options = null) + public async Task ModifyGuildMemberAsync(ulong guildId, ulong userId, ModifyGuildMemberParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); Preconditions.NotNull(args, nameof(args)); - await Send("PATCH", $"guilds/{guildId}/members/{userId}", args, GuildBucket.ModifyMember, guildId, options: options).ConfigureAwait(false); + await SendAsync("PATCH", $"guilds/{guildId}/members/{userId}", args, GuildBucket.ModifyMember, guildId, options: options).ConfigureAwait(false); } //Guild Roles - public async Task> GetGuildRoles(ulong guildId, RequestOptions options = null) + public async Task> GetGuildRolesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send>("GET", $"guilds/{guildId}/roles", options: options).ConfigureAwait(false); + return await SendAsync>("GET", $"guilds/{guildId}/roles", options: options).ConfigureAwait(false); } - public async Task CreateGuildRole(ulong guildId, RequestOptions options = null) + public async Task CreateGuildRoleAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send("POST", $"guilds/{guildId}/roles", options: options).ConfigureAwait(false); + return await SendAsync("POST", $"guilds/{guildId}/roles", options: options).ConfigureAwait(false); } - public async Task DeleteGuildRole(ulong guildId, ulong roleId, RequestOptions options = null) + public async Task DeleteGuildRoleAsync(ulong guildId, ulong roleId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(roleId, 0, nameof(roleId)); - await Send("DELETE", $"guilds/{guildId}/roles/{roleId}", options: options).ConfigureAwait(false); + await SendAsync("DELETE", $"guilds/{guildId}/roles/{roleId}", options: options).ConfigureAwait(false); } - public async Task ModifyGuildRole(ulong guildId, ulong roleId, ModifyGuildRoleParams args, RequestOptions options = null) + public async Task ModifyGuildRoleAsync(ulong guildId, ulong roleId, ModifyGuildRoleParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(roleId, 0, nameof(roleId)); @@ -765,9 +765,9 @@ namespace Discord.API Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); - return await Send("PATCH", $"guilds/{guildId}/roles/{roleId}", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"guilds/{guildId}/roles/{roleId}", args, options: options).ConfigureAwait(false); } - public async Task> ModifyGuildRoles(ulong guildId, IEnumerable args, RequestOptions options = null) + public async Task> ModifyGuildRolesAsync(ulong guildId, IEnumerable args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotNull(args, nameof(args)); @@ -778,20 +778,20 @@ namespace Discord.API case 0: return ImmutableArray.Create(); case 1: - return ImmutableArray.Create(await ModifyGuildRole(guildId, roles[0].Id, roles[0]).ConfigureAwait(false)); + return ImmutableArray.Create(await ModifyGuildRoleAsync(guildId, roles[0].Id, roles[0]).ConfigureAwait(false)); default: - return await Send>("PATCH", $"guilds/{guildId}/roles", args, options: options).ConfigureAwait(false); + return await SendAsync>("PATCH", $"guilds/{guildId}/roles", args, options: options).ConfigureAwait(false); } } //Messages - public async Task GetChannelMessage(ulong channelId, ulong messageId, RequestOptions options = null) + public async Task GetChannelMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); //TODO: Improve when Discord adds support - var msgs = await GetChannelMessages(channelId, new GetChannelMessagesParams { Limit = 1, RelativeDirection = Direction.Before, RelativeMessageId = messageId + 1 }).ConfigureAwait(false); + var msgs = await GetChannelMessagesAsync(channelId, new GetChannelMessagesParams { Limit = 1, RelativeDirection = Direction.Before, RelativeMessageId = messageId + 1 }).ConfigureAwait(false); return msgs.FirstOrDefault(); /*try @@ -800,7 +800,7 @@ namespace Discord.API } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }*/ } - public async Task> GetChannelMessages(ulong channelId, GetChannelMessagesParams args, RequestOptions options = null) + public async Task> GetChannelMessagesAsync(ulong channelId, GetChannelMessagesParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -823,7 +823,7 @@ namespace Discord.API endpoint = $"channels/{channelId}/messages?limit={runCount}&{relativeDir}={relativeId}"; else endpoint = $"channels/{channelId}/messages?limit={runCount}"; - var models = await Send("GET", endpoint, options: options).ConfigureAwait(false); + var models = await SendAsync("GET", endpoint, options: options).ConfigureAwait(false); //Was this an empty batch? if (models.Length == 0) break; @@ -847,17 +847,17 @@ namespace Discord.API else return ImmutableArray.Create(); } - public Task CreateMessage(ulong guildId, ulong channelId, CreateMessageParams args, RequestOptions options = null) + public Task CreateMessageAsync(ulong guildId, ulong channelId, CreateMessageParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return CreateMessageInternal(guildId, channelId, args); + return CreateMessageInternalAsync(guildId, channelId, args); } - public Task CreateDMMessage(ulong channelId, CreateMessageParams args, RequestOptions options = null) + public Task CreateDMMessageAsync(ulong channelId, CreateMessageParams args, RequestOptions options = null) { - return CreateMessageInternal(0, channelId, args); + return CreateMessageInternalAsync(0, channelId, args); } - public async Task CreateMessageInternal(ulong guildId, ulong channelId, CreateMessageParams args, RequestOptions options = null) + public async Task CreateMessageInternalAsync(ulong guildId, ulong channelId, CreateMessageParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -866,21 +866,21 @@ namespace Discord.API throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); if (guildId != 0) - return await Send("POST", $"channels/{channelId}/messages", args, GuildBucket.SendEditMessage, guildId, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"channels/{channelId}/messages", args, GuildBucket.SendEditMessage, guildId, options: options).ConfigureAwait(false); else - return await Send("POST", $"channels/{channelId}/messages", args, GlobalBucket.DirectMessage, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"channels/{channelId}/messages", args, GlobalBucket.DirectMessage, options: options).ConfigureAwait(false); } - public Task UploadFile(ulong guildId, ulong channelId, Stream file, UploadFileParams args, RequestOptions options = null) + public Task UploadFileAsync(ulong guildId, ulong channelId, Stream file, UploadFileParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return UploadFileInternal(guildId, channelId, file, args); + return UploadFileInternalAsync(guildId, channelId, file, args); } - public Task UploadDMFile(ulong channelId, Stream file, UploadFileParams args, RequestOptions options = null) + public Task UploadDMFileAsync(ulong channelId, Stream file, UploadFileParams args, RequestOptions options = null) { - return UploadFileInternal(0, channelId, file, args); + return UploadFileInternalAsync(0, channelId, file, args); } - private async Task UploadFileInternal(ulong guildId, ulong channelId, Stream file, UploadFileParams args, RequestOptions options = null) + private async Task UploadFileInternalAsync(ulong guildId, ulong channelId, Stream file, UploadFileParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -892,41 +892,41 @@ namespace Discord.API } if (guildId != 0) - return await Send("POST", $"channels/{channelId}/messages", file, args.ToDictionary(), GuildBucket.SendEditMessage, guildId, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"channels/{channelId}/messages", file, args.ToDictionary(), GuildBucket.SendEditMessage, guildId, options: options).ConfigureAwait(false); else - return await Send("POST", $"channels/{channelId}/messages", file, args.ToDictionary(), GlobalBucket.DirectMessage, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"channels/{channelId}/messages", file, args.ToDictionary(), GlobalBucket.DirectMessage, options: options).ConfigureAwait(false); } - public Task DeleteMessage(ulong guildId, ulong channelId, ulong messageId, RequestOptions options = null) + public Task DeleteMessageAsync(ulong guildId, ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return DeleteMessageInternal(guildId, channelId, messageId); + return DeleteMessageInternalAsync(guildId, channelId, messageId); } - public Task DeleteDMMessage(ulong channelId, ulong messageId, RequestOptions options = null) + public Task DeleteDMMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { - return DeleteMessageInternal(0, channelId, messageId); + return DeleteMessageInternalAsync(0, channelId, messageId); } - private async Task DeleteMessageInternal(ulong guildId, ulong channelId, ulong messageId, RequestOptions options = null) + private async Task DeleteMessageInternalAsync(ulong guildId, ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); if (guildId != 0) - await Send("DELETE", $"channels/{channelId}/messages/{messageId}", GuildBucket.DeleteMessage, guildId, options: options).ConfigureAwait(false); + await SendAsync("DELETE", $"channels/{channelId}/messages/{messageId}", GuildBucket.DeleteMessage, guildId, options: options).ConfigureAwait(false); else - await Send("DELETE", $"channels/{channelId}/messages/{messageId}", options: options).ConfigureAwait(false); + await SendAsync("DELETE", $"channels/{channelId}/messages/{messageId}", options: options).ConfigureAwait(false); } - public Task DeleteMessages(ulong guildId, ulong channelId, DeleteMessagesParams args, RequestOptions options = null) + public Task DeleteMessagesAsync(ulong guildId, ulong channelId, DeleteMessagesParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return DeleteMessagesInternal(guildId, channelId, args); + return DeleteMessagesInternalAsync(guildId, channelId, args); } - public Task DeleteDMMessages(ulong channelId, DeleteMessagesParams args, RequestOptions options = null) + public Task DeleteDMMessagesAsync(ulong channelId, DeleteMessagesParams args, RequestOptions options = null) { - return DeleteMessagesInternal(0, channelId, args); + return DeleteMessagesInternalAsync(0, channelId, args); } - private async Task DeleteMessagesInternal(ulong guildId, ulong channelId, DeleteMessagesParams args, RequestOptions options = null) + private async Task DeleteMessagesInternalAsync(ulong guildId, ulong channelId, DeleteMessagesParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); @@ -940,27 +940,27 @@ namespace Discord.API case 0: return; case 1: - await DeleteMessageInternal(guildId, channelId, messageIds[0]).ConfigureAwait(false); + await DeleteMessageInternalAsync(guildId, channelId, messageIds[0]).ConfigureAwait(false); break; default: if (guildId != 0) - await Send("POST", $"channels/{channelId}/messages/bulk_delete", args, GuildBucket.DeleteMessages, guildId, options: options).ConfigureAwait(false); + await SendAsync("POST", $"channels/{channelId}/messages/bulk_delete", args, GuildBucket.DeleteMessages, guildId, options: options).ConfigureAwait(false); else - await Send("POST", $"channels/{channelId}/messages/bulk_delete", args, options: options).ConfigureAwait(false); + await SendAsync("POST", $"channels/{channelId}/messages/bulk_delete", args, options: options).ConfigureAwait(false); break; } } - public Task ModifyMessage(ulong guildId, ulong channelId, ulong messageId, ModifyMessageParams args, RequestOptions options = null) + public Task ModifyMessageAsync(ulong guildId, ulong channelId, ulong messageId, ModifyMessageParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return ModifyMessageInternal(guildId, channelId, messageId, args); + return ModifyMessageInternalAsync(guildId, channelId, messageId, args); } - public Task ModifyDMMessage(ulong channelId, ulong messageId, ModifyMessageParams args, RequestOptions options = null) + public Task ModifyDMMessageAsync(ulong channelId, ulong messageId, ModifyMessageParams args, RequestOptions options = null) { - return ModifyMessageInternal(0, channelId, messageId, args); + return ModifyMessageInternalAsync(0, channelId, messageId, args); } - private async Task ModifyMessageInternal(ulong guildId, ulong channelId, ulong messageId, ModifyMessageParams args, RequestOptions options = null) + private async Task ModifyMessageInternalAsync(ulong guildId, ulong channelId, ulong messageId, ModifyMessageParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); @@ -973,104 +973,104 @@ namespace Discord.API } if (guildId != 0) - return await Send("PATCH", $"channels/{channelId}/messages/{messageId}", args, GuildBucket.SendEditMessage, guildId, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"channels/{channelId}/messages/{messageId}", args, GuildBucket.SendEditMessage, guildId, options: options).ConfigureAwait(false); else - return await Send("PATCH", $"channels/{channelId}/messages/{messageId}", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", $"channels/{channelId}/messages/{messageId}", args, options: options).ConfigureAwait(false); } - public async Task AckMessage(ulong channelId, ulong messageId, RequestOptions options = null) + public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotEqual(messageId, 0, nameof(messageId)); - await Send("POST", $"channels/{channelId}/messages/{messageId}/ack", options: options).ConfigureAwait(false); + await SendAsync("POST", $"channels/{channelId}/messages/{messageId}/ack", options: options).ConfigureAwait(false); } - public async Task TriggerTypingIndicator(ulong channelId, RequestOptions options = null) + public async Task TriggerTypingIndicatorAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); - await Send("POST", $"channels/{channelId}/typing", options: options).ConfigureAwait(false); + await SendAsync("POST", $"channels/{channelId}/typing", options: options).ConfigureAwait(false); } //Users - public async Task GetUser(ulong userId, RequestOptions options = null) + public async Task GetUserAsync(ulong userId, RequestOptions options = null) { Preconditions.NotEqual(userId, 0, nameof(userId)); try { - return await Send("GET", $"users/{userId}", options: options).ConfigureAwait(false); + return await SendAsync("GET", $"users/{userId}", options: options).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task GetUser(string username, string discriminator, RequestOptions options = null) + public async Task GetUserAsync(string username, string discriminator, RequestOptions options = null) { Preconditions.NotNullOrEmpty(username, nameof(username)); Preconditions.NotNullOrEmpty(discriminator, nameof(discriminator)); try { - var models = await QueryUsers($"{username}#{discriminator}", 1, options: options).ConfigureAwait(false); + var models = await QueryUsersAsync($"{username}#{discriminator}", 1, options: options).ConfigureAwait(false); return models.FirstOrDefault(); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } - public async Task> QueryUsers(string query, int limit, RequestOptions options = null) + public async Task> QueryUsersAsync(string query, int limit, RequestOptions options = null) { Preconditions.NotNullOrEmpty(query, nameof(query)); Preconditions.AtLeast(limit, 0, nameof(limit)); - return await Send>("GET", $"users?q={Uri.EscapeDataString(query)}&limit={limit}", options: options).ConfigureAwait(false); + return await SendAsync>("GET", $"users?q={Uri.EscapeDataString(query)}&limit={limit}", options: options).ConfigureAwait(false); } //Current User/DMs - public async Task GetCurrentUser(RequestOptions options = null) + public async Task GetSelfAsync(RequestOptions options = null) { - return await Send("GET", "users/@me", options: options).ConfigureAwait(false); + return await SendAsync("GET", "users/@me", options: options).ConfigureAwait(false); } - public async Task> GetCurrentUserConnections(RequestOptions options = null) + public async Task> GetMyConnectionsAsync(RequestOptions options = null) { - return await Send>("GET", "users/@me/connections", options: options).ConfigureAwait(false); + return await SendAsync>("GET", "users/@me/connections", options: options).ConfigureAwait(false); } - public async Task> GetCurrentUserDMs(RequestOptions options = null) + public async Task> GetMyDMsAsync(RequestOptions options = null) { - return await Send>("GET", "users/@me/channels", options: options).ConfigureAwait(false); + return await SendAsync>("GET", "users/@me/channels", options: options).ConfigureAwait(false); } - public async Task> GetCurrentUserGuilds(RequestOptions options = null) + public async Task> GetMyGuildsAsync(RequestOptions options = null) { - return await Send>("GET", "users/@me/guilds", options: options).ConfigureAwait(false); + return await SendAsync>("GET", "users/@me/guilds", options: options).ConfigureAwait(false); } - public async Task ModifyCurrentUser(ModifyCurrentUserParams args, RequestOptions options = null) + public async Task ModifySelfAsync(ModifyCurrentUserParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotNullOrEmpty(args.Username, nameof(args.Username)); - return await Send("PATCH", "users/@me", args, options: options).ConfigureAwait(false); + return await SendAsync("PATCH", "users/@me", args, options: options).ConfigureAwait(false); } - public async Task ModifyCurrentUserNick(ulong guildId, ModifyCurrentUserNickParams args, RequestOptions options = null) + public async Task ModifyMyNickAsync(ulong guildId, ModifyCurrentUserNickParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEmpty(args.Nickname, nameof(args.Nickname)); - await Send("PATCH", $"guilds/{guildId}/members/@me/nick", args, options: options).ConfigureAwait(false); + await SendAsync("PATCH", $"guilds/{guildId}/members/@me/nick", args, options: options).ConfigureAwait(false); } - public async Task CreateDMChannel(CreateDMChannelParams args, RequestOptions options = null) + public async Task CreateDMChannelAsync(CreateDMChannelParams args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); Preconditions.NotEqual(args.RecipientId, 0, nameof(args.RecipientId)); - return await Send("POST", $"users/@me/channels", args, options: options).ConfigureAwait(false); + return await SendAsync("POST", $"users/@me/channels", args, options: options).ConfigureAwait(false); } //Voice Regions - public async Task> GetVoiceRegions(RequestOptions options = null) + public async Task> GetVoiceRegionsAsync(RequestOptions options = null) { - return await Send>("GET", "voice/regions", options: options).ConfigureAwait(false); + return await SendAsync>("GET", "voice/regions", options: options).ConfigureAwait(false); } - public async Task> GetGuildVoiceRegions(ulong guildId, RequestOptions options = null) + public async Task> GetGuildVoiceRegionsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); - return await Send>("GET", $"guilds/{guildId}/regions", options: options).ConfigureAwait(false); + return await SendAsync>("GET", $"guilds/{guildId}/regions", options: options).ConfigureAwait(false); } //Helpers diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index 43829cca1..1fbd03953 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -35,7 +35,7 @@ namespace Discord public DiscordClient(DiscordConfig config) { _log = new LogManager(config.LogLevel); - _log.Message += async msg => await Log.Raise(msg).ConfigureAwait(false); + _log.Message += async msg => await Log.RaiseAsync(msg).ConfigureAwait(false); _discordLogger = _log.CreateLogger("Discord"); _restLogger = _log.CreateLogger("Rest"); @@ -44,34 +44,34 @@ namespace Discord //TODO: Is there any better way to do this WebSocketProvider access? ApiClient = new API.DiscordApiClient(config.RestClientProvider, (config as DiscordSocketConfig)?.WebSocketProvider, requestQueue: _requestQueue); - ApiClient.SentRequest += async (method, endpoint, millis) => await _log.Verbose("Rest", $"{method} {endpoint}: {millis} ms").ConfigureAwait(false); + ApiClient.SentRequest += async (method, endpoint, millis) => await _log.VerboseAsync("Rest", $"{method} {endpoint}: {millis} ms").ConfigureAwait(false); } /// - public async Task Login(TokenType tokenType, string token, bool validateToken = true) + public async Task LoginAsync(TokenType tokenType, string token, bool validateToken = true) { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await LoginInternal(tokenType, token, validateToken).ConfigureAwait(false); + await LoginInternalAsync(tokenType, token, validateToken).ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task LoginInternal(TokenType tokenType, string token, bool validateToken) + private async Task LoginInternalAsync(TokenType tokenType, string token, bool validateToken) { if (LoginState != LoginState.LoggedOut) - await LogoutInternal().ConfigureAwait(false); + await LogoutInternalAsync().ConfigureAwait(false); LoginState = LoginState.LoggingIn; try { - await ApiClient.Login(tokenType, token).ConfigureAwait(false); + await ApiClient.LoginAsync(tokenType, token).ConfigureAwait(false); if (validateToken) { try { - await ApiClient.ValidateToken().ConfigureAwait(false); + await ApiClient.ValidateTokenAsync().ConfigureAwait(false); } catch (HttpException ex) { @@ -79,63 +79,63 @@ namespace Discord } } - await OnLogin().ConfigureAwait(false); + await OnLoginAsync().ConfigureAwait(false); LoginState = LoginState.LoggedIn; } catch (Exception) { - await LogoutInternal().ConfigureAwait(false); + await LogoutInternalAsync().ConfigureAwait(false); throw; } - await LoggedIn.Raise().ConfigureAwait(false); + await LoggedIn.RaiseAsync().ConfigureAwait(false); } - protected virtual Task OnLogin() => Task.CompletedTask; + protected virtual Task OnLoginAsync() => Task.CompletedTask; /// - public async Task Logout() + public async Task LogoutAsync() { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await LogoutInternal().ConfigureAwait(false); + await LogoutInternalAsync().ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task LogoutInternal() + private async Task LogoutInternalAsync() { if (LoginState == LoginState.LoggedOut) return; LoginState = LoginState.LoggingOut; - await ApiClient.Logout().ConfigureAwait(false); + await ApiClient.LogoutAsync().ConfigureAwait(false); - await OnLogout().ConfigureAwait(false); + await OnLogoutAsync().ConfigureAwait(false); _currentUser = null; LoginState = LoginState.LoggedOut; - await LoggedOut.Raise().ConfigureAwait(false); + await LoggedOut.RaiseAsync().ConfigureAwait(false); } - protected virtual Task OnLogout() => Task.CompletedTask; + protected virtual Task OnLogoutAsync() => Task.CompletedTask; /// - public async Task> GetConnections() + public async Task> GetConnectionsAsync() { - var models = await ApiClient.GetCurrentUserConnections().ConfigureAwait(false); + var models = await ApiClient.GetMyConnectionsAsync().ConfigureAwait(false); return models.Select(x => new Connection(x)).ToImmutableArray(); } /// - public virtual async Task GetChannel(ulong id) + public virtual async Task GetChannelAsync(ulong id) { - var model = await ApiClient.GetChannel(id).ConfigureAwait(false); + var model = await ApiClient.GetChannelAsync(id).ConfigureAwait(false); if (model != null) { if (model.GuildId != null) { - var guildModel = await ApiClient.GetGuild(model.GuildId.Value).ConfigureAwait(false); + var guildModel = await ApiClient.GetGuildAsync(model.GuildId.Value).ConfigureAwait(false); if (guildModel != null) { var guild = new Guild(this, guildModel); @@ -148,97 +148,97 @@ namespace Discord return null; } /// - public virtual async Task> GetDMChannels() + public virtual async Task> GetDMChannelsAsync() { - var models = await ApiClient.GetCurrentUserDMs().ConfigureAwait(false); + var models = await ApiClient.GetMyDMsAsync().ConfigureAwait(false); return models.Select(x => new DMChannel(this, new User(this, x.Recipient), x)).ToImmutableArray(); } /// - public virtual async Task GetInvite(string inviteIdOrXkcd) + public virtual async Task GetInviteAsync(string inviteIdOrXkcd) { - var model = await ApiClient.GetInvite(inviteIdOrXkcd).ConfigureAwait(false); + var model = await ApiClient.GetInviteAsync(inviteIdOrXkcd).ConfigureAwait(false); if (model != null) return new Invite(this, model); return null; } /// - public virtual async Task GetGuild(ulong id) + public virtual async Task GetGuildAsync(ulong id) { - var model = await ApiClient.GetGuild(id).ConfigureAwait(false); + var model = await ApiClient.GetGuildAsync(id).ConfigureAwait(false); if (model != null) return new Guild(this, model); return null; } /// - public virtual async Task GetGuildEmbed(ulong id) + public virtual async Task GetGuildEmbedAsync(ulong id) { - var model = await ApiClient.GetGuildEmbed(id).ConfigureAwait(false); + var model = await ApiClient.GetGuildEmbedAsync(id).ConfigureAwait(false); if (model != null) return new GuildEmbed(model); return null; } /// - public virtual async Task> GetGuilds() + public virtual async Task> GetGuildsAsync() { - var models = await ApiClient.GetCurrentUserGuilds().ConfigureAwait(false); + var models = await ApiClient.GetMyGuildsAsync().ConfigureAwait(false); return models.Select(x => new UserGuild(this, x)).ToImmutableArray(); } /// - public virtual async Task CreateGuild(string name, IVoiceRegion region, Stream jpegIcon = null) + public virtual async Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) { var args = new CreateGuildParams(); - var model = await ApiClient.CreateGuild(args).ConfigureAwait(false); + var model = await ApiClient.CreateGuildAsync(args).ConfigureAwait(false); return new Guild(this, model); } /// - public virtual async Task GetUser(ulong id) + public virtual async Task GetUserAsync(ulong id) { - var model = await ApiClient.GetUser(id).ConfigureAwait(false); + var model = await ApiClient.GetUserAsync(id).ConfigureAwait(false); if (model != null) return new User(this, model); return null; } /// - public virtual async Task GetUser(string username, string discriminator) + public virtual async Task GetUserAsync(string username, string discriminator) { - var model = await ApiClient.GetUser(username, discriminator).ConfigureAwait(false); + var model = await ApiClient.GetUserAsync(username, discriminator).ConfigureAwait(false); if (model != null) return new User(this, model); return null; } /// - public virtual async Task GetCurrentUser() + public virtual async Task GetCurrentUserAsync() { var user = _currentUser; if (user == null) { - var model = await ApiClient.GetCurrentUser().ConfigureAwait(false); + var model = await ApiClient.GetSelfAsync().ConfigureAwait(false); user = new SelfUser(this, model); _currentUser = user; } return user; } /// - public virtual async Task> QueryUsers(string query, int limit) + public virtual async Task> QueryUsersAsync(string query, int limit) { - var models = await ApiClient.QueryUsers(query, limit).ConfigureAwait(false); + var models = await ApiClient.QueryUsersAsync(query, limit).ConfigureAwait(false); return models.Select(x => new User(this, x)).ToImmutableArray(); } /// - public virtual async Task> GetVoiceRegions() + public virtual async Task> GetVoiceRegionsAsync() { - var models = await ApiClient.GetVoiceRegions().ConfigureAwait(false); + var models = await ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); return models.Select(x => new VoiceRegion(x)).ToImmutableArray(); } /// - public virtual async Task GetVoiceRegion(string id) + public virtual async Task GetVoiceRegionAsync(string id) { - var models = await ApiClient.GetVoiceRegions().ConfigureAwait(false); + var models = await ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); return models.Select(x => new VoiceRegion(x)).Where(x => x.Id == id).FirstOrDefault(); } @@ -251,7 +251,7 @@ namespace Discord public void Dispose() => Dispose(true); ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; - Task IDiscordClient.Connect() { throw new NotSupportedException(); } - Task IDiscordClient.Disconnect() { throw new NotSupportedException(); } + Task IDiscordClient.ConnectAsync() { throw new NotSupportedException(); } + Task IDiscordClient.DisconnectAsync() { throw new NotSupportedException(); } } } diff --git a/src/Discord.Net/DiscordSocketClient.cs b/src/Discord.Net/DiscordSocketClient.cs index 449817b1c..eeb51f52a 100644 --- a/src/Discord.Net/DiscordSocketClient.cs +++ b/src/Discord.Net/DiscordSocketClient.cs @@ -115,38 +115,38 @@ namespace Discord _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() }; - ApiClient.SentGatewayMessage += async opCode => await _gatewayLogger.Debug($"Sent {(GatewayOpCode)opCode}"); - ApiClient.ReceivedGatewayEvent += ProcessMessage; + ApiClient.SentGatewayMessage += async opCode => await _gatewayLogger.DebugAsync($"Sent {(GatewayOpCode)opCode}"); + ApiClient.ReceivedGatewayEvent += ProcessMessageAsync; GatewaySocket = config.WebSocketProvider(); _voiceRegions = ImmutableDictionary.Create(); _largeGuilds = new ConcurrentQueue(); } - protected override async Task OnLogin() + protected override async Task OnLoginAsync() { - var voiceRegions = await ApiClient.GetVoiceRegions().ConfigureAwait(false); + var voiceRegions = await ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); _voiceRegions = voiceRegions.Select(x => new VoiceRegion(x)).ToImmutableDictionary(x => x.Id); } - protected override async Task OnLogout() + protected override async Task OnLogoutAsync() { if (ConnectionState != ConnectionState.Disconnected) - await DisconnectInternal().ConfigureAwait(false); + await DisconnectInternalAsync().ConfigureAwait(false); _voiceRegions = ImmutableDictionary.Create(); } /// - public async Task Connect() + public async Task ConnectAsync() { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await ConnectInternal().ConfigureAwait(false); + await ConnectInternalAsync().ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task ConnectInternal() + private async Task ConnectInternalAsync() { if (LoginState != LoginState.LoggedIn) throw new InvalidOperationException("You must log in before connecting."); @@ -156,47 +156,47 @@ namespace Discord { _connectTask = new TaskCompletionSource(); _heartbeatCancelToken = new CancellationTokenSource(); - await ApiClient.Connect().ConfigureAwait(false); + await ApiClient.ConnectAsync().ConfigureAwait(false); await _connectTask.Task.ConfigureAwait(false); ConnectionState = ConnectionState.Connected; } catch (Exception) { - await DisconnectInternal().ConfigureAwait(false); + await DisconnectInternalAsync().ConfigureAwait(false); throw; } - await Connected.Raise().ConfigureAwait(false); + await Connected.RaiseAsync().ConfigureAwait(false); } /// - public async Task Disconnect() + public async Task DisconnectAsync() { await _connectionLock.WaitAsync().ConfigureAwait(false); try { - await DisconnectInternal().ConfigureAwait(false); + await DisconnectInternalAsync().ConfigureAwait(false); } finally { _connectionLock.Release(); } } - private async Task DisconnectInternal() + private async Task DisconnectInternalAsync() { ulong guildId; if (ConnectionState == ConnectionState.Disconnected) return; ConnectionState = ConnectionState.Disconnecting; - await ApiClient.Disconnect().ConfigureAwait(false); + await ApiClient.DisconnectAsync().ConfigureAwait(false); await _heartbeatTask.ConfigureAwait(false); while (_largeGuilds.TryDequeue(out guildId)) { } ConnectionState = ConnectionState.Disconnected; - await Disconnected.Raise().ConfigureAwait(false); + await Disconnected.RaiseAsync().ConfigureAwait(false); } /// - public override Task GetVoiceRegion(string id) + public override Task GetVoiceRegionAsync(string id) { VoiceRegion region; if (_voiceRegions.TryGetValue(id, out region)) @@ -205,7 +205,7 @@ namespace Discord } /// - public override Task GetGuild(ulong id) + public override Task GetGuildAsync(ulong id) { return Task.FromResult(DataStore.GetGuild(id)); } @@ -237,7 +237,7 @@ namespace Discord } /// - public override Task GetChannel(ulong id) + public override Task GetChannelAsync(ulong id) { return Task.FromResult(DataStore.GetChannel(id)); } @@ -284,12 +284,12 @@ namespace Discord } /// - public override Task GetUser(ulong id) + public override Task GetUserAsync(ulong id) { return Task.FromResult(DataStore.GetUser(id)); } /// - public override Task GetUser(string username, string discriminator) + public override Task GetUserAsync(string username, string discriminator) { return Task.FromResult(DataStore.Users.Where(x => x.Discriminator == discriminator && x.Username == username).FirstOrDefault()); } @@ -310,10 +310,10 @@ namespace Discord } /// Downloads the members list for all large guilds. - public Task DownloadAllMembers() - => DownloadMembers(DataStore.Guilds.Where(x => !x.HasAllMembers)); + public Task DownloadAllMembersAsync() + => DownloadMembersAsync(DataStore.Guilds.Where(x => !x.HasAllMembers)); /// Downloads the members list for the provided guilds, if they don't have a complete list. - public async Task DownloadMembers(IEnumerable guilds) + public async Task DownloadMembersAsync(IEnumerable guilds) { const short batchSize = 50; var cachedGuilds = guilds.Select(x => x as CachedGuild).ToArray(); @@ -321,7 +321,7 @@ namespace Discord return; else if (cachedGuilds.Length == 1) { - await cachedGuilds[0].DownloadMembers().ConfigureAwait(false); + await cachedGuilds[0].DownloadMembersAsync().ConfigureAwait(false); return; } @@ -341,7 +341,7 @@ namespace Discord batchTasks[j] = guild.DownloaderPromise; } - await ApiClient.SendRequestMembers(batchIds).ConfigureAwait(false); + await ApiClient.SendRequestMembersAsync(batchIds).ConfigureAwait(false); if (isLast && batchCount > 1) await Task.WhenAll(batchTasks.Take(count)).ConfigureAwait(false); @@ -350,7 +350,7 @@ namespace Discord } } - private async Task ProcessMessage(GatewayOpCode opCode, int? seq, string type, object payload) + private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string type, object payload) { #if BENCHMARK Stopwatch stopwatch = Stopwatch.StartNew(); @@ -365,22 +365,22 @@ namespace Discord { case GatewayOpCode.Hello: { - await _gatewayLogger.Debug($"Received Hello").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Hello").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); - await ApiClient.SendIdentify().ConfigureAwait(false); - _heartbeatTask = RunHeartbeat(data.HeartbeatInterval, _heartbeatCancelToken.Token); + await ApiClient.SendIdentifyAsync().ConfigureAwait(false); + _heartbeatTask = RunHeartbeatAsync(data.HeartbeatInterval, _heartbeatCancelToken.Token); } break; case GatewayOpCode.HeartbeatAck: { - await _gatewayLogger.Debug($"Received HeartbeatAck").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received HeartbeatAck").ConfigureAwait(false); var latency = (int)(Environment.TickCount - _heartbeatTime); - await _gatewayLogger.Debug($"Latency = {latency} ms").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Latency = {latency} ms").ConfigureAwait(false); Latency = latency; - await LatencyUpdated.Raise(latency).ConfigureAwait(false); + await LatencyUpdated.RaiseAsync(latency).ConfigureAwait(false); } break; case GatewayOpCode.Dispatch: @@ -389,7 +389,7 @@ namespace Discord //Global case "READY": { - await _gatewayLogger.Debug($"Received Dispatch (READY)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (READY)").ConfigureAwait(false); //TODO: Make downloading large guilds optional var data = (payload as JToken).ToObject(_serializer); @@ -405,7 +405,7 @@ namespace Discord _sessionId = data.SessionId; DataStore = dataStore; - await Ready.Raise().ConfigureAwait(false); + await Ready.RaiseAsync().ConfigureAwait(false); _connectTask.TrySetResult(true); //Signal the .Connect() call to complete } @@ -420,17 +420,17 @@ namespace Discord if (data.Unavailable == false) type = "GUILD_AVAILABLE"; - await _gatewayLogger.Debug($"Received Dispatch ({type})").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); if (data.Unavailable != false) - await JoinedGuild.Raise(guild).ConfigureAwait(false); + await JoinedGuild.RaiseAsync(guild).ConfigureAwait(false); - await GuildAvailable.Raise(guild).ConfigureAwait(false); + await GuildAvailable.RaiseAsync(guild).ConfigureAwait(false); } break; case "GUILD_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.Id); @@ -438,10 +438,10 @@ namespace Discord { var before = _enablePreUpdateEvents ? guild.Clone() : null; guild.Update(data, UpdateSource.WebSocket); - await GuildUpdated.Raise(before, guild).ConfigureAwait(false); + await GuildUpdated.RaiseAsync(before, guild).ConfigureAwait(false); } else - await _gatewayLogger.Warning("GUILD_UPDATE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_UPDATE referenced an unknown guild."); } break; case "GUILD_DELETE": @@ -449,26 +449,26 @@ namespace Discord var data = (payload as JToken).ToObject(_serializer); if (data.Unavailable == true) type = "GUILD_UNAVAILABLE"; - await _gatewayLogger.Debug($"Received Dispatch ({type})").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch ({type})").ConfigureAwait(false); var guild = DataStore.RemoveGuild(data.Id); if (guild != null) { - await GuildUnavailable.Raise(guild).ConfigureAwait(false); + await GuildUnavailable.RaiseAsync(guild).ConfigureAwait(false); if (data.Unavailable != true) - await LeftGuild.Raise(guild).ConfigureAwait(false); + await LeftGuild.RaiseAsync(guild).ConfigureAwait(false); foreach (var member in guild.Members) member.User.RemoveRef(); } else - await _gatewayLogger.Warning($"{type} referenced an unknown guild.").ConfigureAwait(false); + await _gatewayLogger.WarningAsync($"{type} referenced an unknown guild.").ConfigureAwait(false); } break; //Channels case "CHANNEL_CREATE": { - await _gatewayLogger.Debug($"Received Dispatch (CHANNEL_CREATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (CHANNEL_CREATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); ICachedChannel channel = null; @@ -481,17 +481,17 @@ namespace Discord DataStore.AddChannel(channel); } else - await _gatewayLogger.Warning("CHANNEL_CREATE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("CHANNEL_CREATE referenced an unknown guild."); } else channel = AddCachedDMChannel(data); if (channel != null) - await ChannelCreated.Raise(channel); + await ChannelCreated.RaiseAsync(channel); } break; case "CHANNEL_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (CHANNEL_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (CHANNEL_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var channel = DataStore.GetChannel(data.Id); @@ -499,44 +499,44 @@ namespace Discord { var before = _enablePreUpdateEvents ? channel.Clone() : null; channel.Update(data, UpdateSource.WebSocket); - await ChannelUpdated.Raise(before, channel); + await ChannelUpdated.RaiseAsync(before, channel); } else - await _gatewayLogger.Warning("CHANNEL_UPDATE referenced an unknown channel."); + await _gatewayLogger.WarningAsync("CHANNEL_UPDATE referenced an unknown channel."); } break; case "CHANNEL_DELETE": { - await _gatewayLogger.Debug($"Received Dispatch (CHANNEL_DELETE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (CHANNEL_DELETE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var channel = RemoveCachedChannel(data.Id); if (channel != null) - await ChannelDestroyed.Raise(channel); + await ChannelDestroyed.RaiseAsync(channel); else - await _gatewayLogger.Warning("CHANNEL_DELETE referenced an unknown channel."); + await _gatewayLogger.WarningAsync("CHANNEL_DELETE referenced an unknown channel."); } break; //Members case "GUILD_MEMBER_ADD": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBER_ADD)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBER_ADD)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); if (guild != null) { var user = guild.AddCachedUser(data); - await UserJoined.Raise(user).ConfigureAwait(false); + await UserJoined.RaiseAsync(user).ConfigureAwait(false); } else - await _gatewayLogger.Warning("GUILD_MEMBER_ADD referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_MEMBER_ADD referenced an unknown guild."); } break; case "GUILD_MEMBER_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBER_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBER_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); @@ -547,18 +547,18 @@ namespace Discord { var before = _enablePreUpdateEvents ? user.Clone() : null; user.Update(data, UpdateSource.WebSocket); - await UserUpdated.Raise(before, user); + await UserUpdated.RaiseAsync(before, user); } else - await _gatewayLogger.Warning("GUILD_MEMBER_UPDATE referenced an unknown user."); + await _gatewayLogger.WarningAsync("GUILD_MEMBER_UPDATE referenced an unknown user."); } else - await _gatewayLogger.Warning("GUILD_MEMBER_UPDATE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_MEMBER_UPDATE referenced an unknown guild."); } break; case "GUILD_MEMBER_REMOVE": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBER_REMOVE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBER_REMOVE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); @@ -568,18 +568,18 @@ namespace Discord if (user != null) { user.User.RemoveRef(); - await UserLeft.Raise(user); + await UserLeft.RaiseAsync(user); } else - await _gatewayLogger.Warning("GUILD_MEMBER_REMOVE referenced an unknown user."); + await _gatewayLogger.WarningAsync("GUILD_MEMBER_REMOVE referenced an unknown user."); } else - await _gatewayLogger.Warning("GUILD_MEMBER_REMOVE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_MEMBER_REMOVE referenced an unknown guild."); } break; case "GUILD_MEMBERS_CHUNK": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_MEMBERS_CHUNK)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_MEMBERS_CHUNK)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); @@ -591,33 +591,33 @@ namespace Discord if (guild.DownloadedMemberCount >= guild.MemberCount) //Finished downloading for there { guild.CompleteDownloadMembers(); - await GuildDownloadedMembers.Raise(guild).ConfigureAwait(false); + await GuildDownloadedMembers.RaiseAsync(guild).ConfigureAwait(false); } } else - await _gatewayLogger.Warning("GUILD_MEMBERS_CHUNK referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_MEMBERS_CHUNK referenced an unknown guild."); } break; //Roles case "GUILD_ROLE_CREATE": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_ROLE_CREATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_ROLE_CREATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); if (guild != null) { var role = guild.AddCachedRole(data.Role); - await RoleCreated.Raise(role).ConfigureAwait(false); + await RoleCreated.RaiseAsync(role).ConfigureAwait(false); } else - await _gatewayLogger.Warning("GUILD_ROLE_CREATE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_ROLE_CREATE referenced an unknown guild."); } break; case "GUILD_ROLE_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_ROLE_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_ROLE_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); @@ -628,18 +628,18 @@ namespace Discord { var before = _enablePreUpdateEvents ? role.Clone() : null; role.Update(data.Role, UpdateSource.WebSocket); - await RoleUpdated.Raise(before, role).ConfigureAwait(false); + await RoleUpdated.RaiseAsync(before, role).ConfigureAwait(false); } else - await _gatewayLogger.Warning("GUILD_ROLE_UPDATE referenced an unknown role."); + await _gatewayLogger.WarningAsync("GUILD_ROLE_UPDATE referenced an unknown role."); } else - await _gatewayLogger.Warning("GUILD_ROLE_UPDATE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_ROLE_UPDATE referenced an unknown guild."); } break; case "GUILD_ROLE_DELETE": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_ROLE_DELETE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_ROLE_DELETE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); @@ -647,45 +647,45 @@ namespace Discord { var role = guild.RemoveCachedRole(data.RoleId); if (role != null) - await RoleDeleted.Raise(role).ConfigureAwait(false); + await RoleDeleted.RaiseAsync(role).ConfigureAwait(false); else - await _gatewayLogger.Warning("GUILD_ROLE_DELETE referenced an unknown role."); + await _gatewayLogger.WarningAsync("GUILD_ROLE_DELETE referenced an unknown role."); } else - await _gatewayLogger.Warning("GUILD_ROLE_DELETE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_ROLE_DELETE referenced an unknown guild."); } break; //Bans case "GUILD_BAN_ADD": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_BAN_ADD)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_BAN_ADD)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); if (guild != null) - await UserBanned.Raise(new User(this, data)); + await UserBanned.RaiseAsync(new User(this, data)); else - await _gatewayLogger.Warning("GUILD_BAN_ADD referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_BAN_ADD referenced an unknown guild."); } break; case "GUILD_BAN_REMOVE": { - await _gatewayLogger.Debug($"Received Dispatch (GUILD_BAN_REMOVE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_BAN_REMOVE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var guild = DataStore.GetGuild(data.GuildId); if (guild != null) - await UserUnbanned.Raise(new User(this, data)); + await UserUnbanned.RaiseAsync(new User(this, data)); else - await _gatewayLogger.Warning("GUILD_BAN_REMOVE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("GUILD_BAN_REMOVE referenced an unknown guild."); } break; //Messages case "MESSAGE_CREATE": { - await _gatewayLogger.Debug($"Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; @@ -696,18 +696,18 @@ namespace Discord if (author != null) { var msg = channel.AddCachedMessage(author, data); - await MessageReceived.Raise(msg).ConfigureAwait(false); + await MessageReceived.RaiseAsync(msg).ConfigureAwait(false); } else - await _gatewayLogger.Warning("MESSAGE_CREATE referenced an unknown user."); + await _gatewayLogger.WarningAsync("MESSAGE_CREATE referenced an unknown user."); } else - await _gatewayLogger.Warning("MESSAGE_CREATE referenced an unknown channel."); + await _gatewayLogger.WarningAsync("MESSAGE_CREATE referenced an unknown channel."); } break; case "MESSAGE_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (MESSAGE_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (MESSAGE_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; @@ -716,32 +716,32 @@ namespace Discord var msg = channel.GetCachedMessage(data.Id); var before = _enablePreUpdateEvents ? msg.Clone() : null; msg.Update(data, UpdateSource.WebSocket); - await MessageUpdated.Raise(before, msg).ConfigureAwait(false); + await MessageUpdated.RaiseAsync(before, msg).ConfigureAwait(false); } else - await _gatewayLogger.Warning("MESSAGE_UPDATE referenced an unknown channel."); + await _gatewayLogger.WarningAsync("MESSAGE_UPDATE referenced an unknown channel."); } break; case "MESSAGE_DELETE": { - await _gatewayLogger.Debug($"Received Dispatch (MESSAGE_DELETE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (MESSAGE_DELETE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; if (channel != null) { var msg = channel.RemoveCachedMessage(data.Id); - await MessageDeleted.Raise(msg).ConfigureAwait(false); + await MessageDeleted.RaiseAsync(msg).ConfigureAwait(false); } else - await _gatewayLogger.Warning("MESSAGE_DELETE referenced an unknown channel."); + await _gatewayLogger.WarningAsync("MESSAGE_DELETE referenced an unknown channel."); } break; //Statuses case "PRESENCE_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (PRESENCE_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (PRESENCE_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); if (data.GuildId == null) @@ -755,7 +755,7 @@ namespace Discord var guild = DataStore.GetGuild(data.GuildId.Value); if (guild == null) { - await _gatewayLogger.Warning("PRESENCE_UPDATE referenced an unknown guild."); + await _gatewayLogger.WarningAsync("PRESENCE_UPDATE referenced an unknown guild."); break; } if (data.Status == UserStatus.Offline) @@ -767,7 +767,7 @@ namespace Discord break; case "TYPING_START": { - await _gatewayLogger.Debug($"Received Dispatch (TYPING_START)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (TYPING_START)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); var channel = DataStore.GetChannel(data.ChannelId) as ICachedMessageChannel; @@ -775,17 +775,17 @@ namespace Discord { var user = channel.GetCachedUser(data.UserId); if (user != null) - await UserIsTyping.Raise(channel, user).ConfigureAwait(false); + await UserIsTyping.RaiseAsync(channel, user).ConfigureAwait(false); } else - await _gatewayLogger.Warning("TYPING_START referenced an unknown channel.").ConfigureAwait(false); + await _gatewayLogger.WarningAsync("TYPING_START referenced an unknown channel.").ConfigureAwait(false); } break; //Voice case "VOICE_STATE_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (VOICE_STATE_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (VOICE_STATE_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); if (data.GuildId.HasValue) @@ -802,7 +802,7 @@ namespace Discord user.Update(data, UpdateSource.WebSocket); } else - await _gatewayLogger.Warning("VOICE_STATE_UPDATE referenced an unknown guild.").ConfigureAwait(false); + await _gatewayLogger.WarningAsync("VOICE_STATE_UPDATE referenced an unknown guild.").ConfigureAwait(false); } } break; @@ -810,14 +810,14 @@ namespace Discord //Settings case "USER_UPDATE": { - await _gatewayLogger.Debug($"Received Dispatch (USER_UPDATE)").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Received Dispatch (USER_UPDATE)").ConfigureAwait(false); var data = (payload as JToken).ToObject(_serializer); if (data.Id == CurrentUser.Id) { var before = _enablePreUpdateEvents ? CurrentUser.Clone() : null; CurrentUser.Update(data, UpdateSource.WebSocket); - await CurrentUserUpdated.Raise(before, CurrentUser).ConfigureAwait(false); + await CurrentUserUpdated.RaiseAsync(before, CurrentUser).ConfigureAwait(false); } } break; @@ -829,23 +829,23 @@ namespace Discord case "GUILD_INTEGRATIONS_UPDATE": //TODO: Add case "VOICE_SERVER_UPDATE": //TODO: Add case "RESUMED": //TODO: Add - await _gatewayLogger.Debug($"Ignored Dispatch ({type})").ConfigureAwait(false); + await _gatewayLogger.DebugAsync($"Ignored Dispatch ({type})").ConfigureAwait(false); return; //Others default: - await _gatewayLogger.Warning($"Unknown Dispatch ({type})").ConfigureAwait(false); + await _gatewayLogger.WarningAsync($"Unknown Dispatch ({type})").ConfigureAwait(false); return; } break; default: - await _gatewayLogger.Warning($"Unknown OpCode ({opCode})").ConfigureAwait(false); + await _gatewayLogger.WarningAsync($"Unknown OpCode ({opCode})").ConfigureAwait(false); return; } } catch (Exception ex) { - await _gatewayLogger.Error($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false); + await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false); return; } #if BENCHMARK @@ -854,11 +854,11 @@ namespace Discord { stopwatch.Stop(); double millis = Math.Round(stopwatch.ElapsedTicks / (double)Stopwatch.Frequency * 1000.0, 2); - await _benchmarkLogger.Debug($"{millis} ms").ConfigureAwait(false); + await _benchmarkLogger.DebugAsync($"{millis} ms").ConfigureAwait(false); } #endif } - private async Task RunHeartbeat(int intervalMillis, CancellationToken cancelToken) + private async Task RunHeartbeatAsync(int intervalMillis, CancellationToken cancelToken) { try { @@ -868,7 +868,7 @@ namespace Discord //if (_heartbeatTime != 0) //TODO: Connection lost, reconnect _heartbeatTime = Environment.TickCount; - await ApiClient.SendHeartbeat(_lastSeq).ConfigureAwait(false); + await ApiClient.SendHeartbeatAsync(_lastSeq).ConfigureAwait(false); await Task.Delay(intervalMillis, cancelToken).ConfigureAwait(false); } } diff --git a/src/Discord.Net/Entities/Channels/DMChannel.cs b/src/Discord.Net/Entities/Channels/DMChannel.cs index ef8c08c19..b1df139f0 100644 --- a/src/Discord.Net/Entities/Channels/DMChannel.cs +++ b/src/Discord.Net/Entities/Channels/DMChannel.cs @@ -33,21 +33,21 @@ namespace Discord Recipient.Update(model.Recipient, UpdateSource.Rest); } - public async Task Update() + public async Task UpdateAsync() { if (IsAttached) throw new NotSupportedException(); - var model = await Discord.ApiClient.GetChannel(Id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetChannelAsync(Id).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Close() + public async Task CloseAsync() { - await Discord.ApiClient.DeleteChannel(Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteChannelAsync(Id).ConfigureAwait(false); } - public virtual async Task GetUser(ulong id) + public virtual async Task GetUserAsync(ulong id) { - var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); + var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); if (id == Recipient.Id) return Recipient; else if (id == currentUser.Id) @@ -55,66 +55,66 @@ namespace Discord else return null; } - public virtual async Task> GetUsers() + public virtual async Task> GetUsersAsync() { - var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); + var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); return ImmutableArray.Create(currentUser, Recipient); } - public virtual async Task> GetUsers(int limit, int offset) + public virtual async Task> GetUsersAsync(int limit, int offset) { - var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); + var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); return new IUser[] { currentUser, Recipient }.Skip(offset).Take(limit).ToImmutableArray(); } - public async Task SendMessage(string text, bool isTTS) + public async Task SendMessageAsync(string text, bool isTTS) { var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; - var model = await Discord.ApiClient.CreateDMMessage(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateDMMessageAsync(Id, args).ConfigureAwait(false); return new Message(this, new User(Discord, model.Author), model); } - public async Task SendFile(string filePath, string text, bool isTTS) + public async Task SendFileAsync(string filePath, string text, bool isTTS) { string filename = Path.GetFileName(filePath); using (var file = File.OpenRead(filePath)) { var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; - var model = await Discord.ApiClient.UploadDMFile(Id, file, args).ConfigureAwait(false); + var model = await Discord.ApiClient.UploadDMFileAsync(Id, file, args).ConfigureAwait(false); return new Message(this, new User(Discord, model.Author), model); } } - public async Task SendFile(Stream stream, string filename, string text, bool isTTS) + public async Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) { var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; - var model = await Discord.ApiClient.UploadDMFile(Id, stream, args).ConfigureAwait(false); + var model = await Discord.ApiClient.UploadDMFileAsync(Id, stream, args).ConfigureAwait(false); return new Message(this, new User(Discord, model.Author), model); } - public virtual async Task GetMessage(ulong id) + public virtual async Task GetMessageAsync(ulong id) { - var model = await Discord.ApiClient.GetChannelMessage(Id, id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); if (model != null) return new Message(this, new User(Discord, model.Author), model); return null; } - public virtual async Task> GetMessages(int limit) + public virtual async Task> GetMessagesAsync(int limit) { var args = new GetChannelMessagesParams { Limit = limit }; - var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); + var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); } - public virtual async Task> GetMessages(ulong fromMessageId, Direction dir, int limit) + public virtual async Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) { var args = new GetChannelMessagesParams { Limit = limit }; - var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); + var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); } - public async Task DeleteMessages(IEnumerable messages) + public async Task DeleteMessagesAsync(IEnumerable messages) { - await Discord.ApiClient.DeleteDMMessages(Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); + await Discord.ApiClient.DeleteDMMessagesAsync(Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); } - public async Task TriggerTyping() + public async Task TriggerTypingAsync() { - await Discord.ApiClient.TriggerTypingIndicator(Id).ConfigureAwait(false); + await Discord.ApiClient.TriggerTypingIndicatorAsync(Id).ConfigureAwait(false); } public override string ToString() => '@' + Recipient.ToString(); diff --git a/src/Discord.Net/Entities/Channels/GuildChannel.cs b/src/Discord.Net/Entities/Channels/GuildChannel.cs index 461f84076..2459b3103 100644 --- a/src/Discord.Net/Entities/Channels/GuildChannel.cs +++ b/src/Discord.Net/Entities/Channels/GuildChannel.cs @@ -46,37 +46,37 @@ namespace Discord _overwrites = newOverwrites; } - public async Task Update() + public async Task UpdateAsync() { if (IsAttached) throw new NotSupportedException(); - var model = await Discord.ApiClient.GetChannel(Id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetChannelAsync(Id).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func != null) throw new NullReferenceException(nameof(func)); var args = new ModifyGuildChannelParams(); func(args); - var model = await Discord.ApiClient.ModifyGuildChannel(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Delete() + public async Task DeleteAsync() { - await Discord.ApiClient.DeleteChannel(Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteChannelAsync(Id).ConfigureAwait(false); } - public abstract Task GetUser(ulong id); - public abstract Task> GetUsers(); - public abstract Task> GetUsers(int limit, int offset); + public abstract Task GetUserAsync(ulong id); + public abstract Task> GetUsersAsync(); + public abstract Task> GetUsersAsync(int limit, int offset); - public async Task> GetInvites() + public async Task> GetInvitesAsync() { - var models = await Discord.ApiClient.GetChannelInvites(Id).ConfigureAwait(false); + var models = await Discord.ApiClient.GetChannelInvitesAsync(Id).ConfigureAwait(false); return models.Select(x => new InviteMetadata(Discord, x)).ToImmutableArray(); } - public async Task CreateInvite(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) + public async Task CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool withXkcd) { var args = new CreateChannelInviteParams { @@ -85,7 +85,7 @@ namespace Discord Temporary = isTemporary, XkcdPass = withXkcd }; - var model = await Discord.ApiClient.CreateChannelInvite(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateChannelInviteAsync(Id, args).ConfigureAwait(false); return new InviteMetadata(Discord, model); } @@ -104,28 +104,28 @@ namespace Discord return null; } - public async Task AddPermissionOverwrite(IUser user, OverwritePermissions perms) + public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms) { var args = new ModifyChannelPermissionsParams { Allow = perms.AllowValue, Deny = perms.DenyValue }; - await Discord.ApiClient.ModifyChannelPermissions(Id, user.Id, args).ConfigureAwait(false); + await Discord.ApiClient.ModifyChannelPermissionsAsync(Id, user.Id, args).ConfigureAwait(false); _overwrites[user.Id] = new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User }); } - public async Task AddPermissionOverwrite(IRole role, OverwritePermissions perms) + public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms) { var args = new ModifyChannelPermissionsParams { Allow = perms.AllowValue, Deny = perms.DenyValue }; - await Discord.ApiClient.ModifyChannelPermissions(Id, role.Id, args).ConfigureAwait(false); + await Discord.ApiClient.ModifyChannelPermissionsAsync(Id, role.Id, args).ConfigureAwait(false); _overwrites[role.Id] = new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role }); } - public async Task RemovePermissionOverwrite(IUser user) + public async Task RemovePermissionOverwriteAsync(IUser user) { - await Discord.ApiClient.DeleteChannelPermission(Id, user.Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteChannelPermissionAsync(Id, user.Id).ConfigureAwait(false); Overwrite value; _overwrites.TryRemove(user.Id, out value); } - public async Task RemovePermissionOverwrite(IRole role) + public async Task RemovePermissionOverwriteAsync(IRole role) { - await Discord.ApiClient.DeleteChannelPermission(Id, role.Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteChannelPermissionAsync(Id, role.Id).ConfigureAwait(false); Overwrite value; _overwrites.TryRemove(role.Id, out value); @@ -137,8 +137,8 @@ namespace Discord IGuild IGuildChannel.Guild => Guild; IReadOnlyCollection IGuildChannel.PermissionOverwrites => _overwrites.ToReadOnlyCollection(); - async Task IChannel.GetUser(ulong id) => await GetUser(id).ConfigureAwait(false); - async Task> IChannel.GetUsers() => await GetUsers().ConfigureAwait(false); - async Task> IChannel.GetUsers(int limit, int offset) => await GetUsers(limit, offset).ConfigureAwait(false); + async Task IChannel.GetUserAsync(ulong id) => await GetUserAsync(id).ConfigureAwait(false); + async Task> IChannel.GetUsersAsync() => await GetUsersAsync().ConfigureAwait(false); + async Task> IChannel.GetUsersAsync(int limit, int offset) => await GetUsersAsync(limit, offset).ConfigureAwait(false); } } diff --git a/src/Discord.Net/Entities/Channels/IChannel.cs b/src/Discord.Net/Entities/Channels/IChannel.cs index 13040dc78..b64e0f2c7 100644 --- a/src/Discord.Net/Entities/Channels/IChannel.cs +++ b/src/Discord.Net/Entities/Channels/IChannel.cs @@ -6,10 +6,10 @@ namespace Discord public interface IChannel : ISnowflakeEntity { /// Gets a collection of all users in this channel. - Task> GetUsers(); + Task> GetUsersAsync(); /// Gets a paginated collection of all users in this channel. - Task> GetUsers(int limit, int offset = 0); + Task> GetUsersAsync(int limit, int offset = 0); /// Gets a user in this channel with the provided id. - Task GetUser(ulong id); + Task GetUserAsync(ulong id); } } diff --git a/src/Discord.Net/Entities/Channels/IDMChannel.cs b/src/Discord.Net/Entities/Channels/IDMChannel.cs index 5038bf36c..2714c59f5 100644 --- a/src/Discord.Net/Entities/Channels/IDMChannel.cs +++ b/src/Discord.Net/Entities/Channels/IDMChannel.cs @@ -8,6 +8,6 @@ namespace Discord IUser Recipient { get; } /// Closes this private channel, removing it from your channel list. - Task Close(); + Task CloseAsync(); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Channels/IGuildChannel.cs b/src/Discord.Net/Entities/Channels/IGuildChannel.cs index 81d4a0f2e..60f52d2b5 100644 --- a/src/Discord.Net/Entities/Channels/IGuildChannel.cs +++ b/src/Discord.Net/Entities/Channels/IGuildChannel.cs @@ -20,32 +20,32 @@ namespace Discord /// The max amount of times this invite may be used. Set to null to have unlimited uses. /// If true, a user accepting this invite will be kicked from the guild after closing their client. /// If true, creates a human-readable link. Not supported if maxAge is set to null. - Task CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); + Task CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); /// Returns a collection of all invites to this channel. - Task> GetInvites(); + Task> GetInvitesAsync(); /// Gets a collection of permission overwrites for this channel. IReadOnlyCollection PermissionOverwrites { get; } /// Modifies this guild channel. - Task Modify(Action func); + Task ModifyAsync(Action func); /// Gets the permission overwrite for a specific role, or null if one does not exist. OverwritePermissions? GetPermissionOverwrite(IRole role); /// Gets the permission overwrite for a specific user, or null if one does not exist. OverwritePermissions? GetPermissionOverwrite(IUser user); /// Removes the permission overwrite for the given role, if one exists. - Task RemovePermissionOverwrite(IRole role); + Task RemovePermissionOverwriteAsync(IRole role); /// Removes the permission overwrite for the given user, if one exists. - Task RemovePermissionOverwrite(IUser user); + Task RemovePermissionOverwriteAsync(IUser user); /// Adds or updates the permission overwrite for the given role. - Task AddPermissionOverwrite(IRole role, OverwritePermissions permissions); + Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions); /// Adds or updates the permission overwrite for the given user. - Task AddPermissionOverwrite(IUser user, OverwritePermissions permissions); + Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions); /// Gets a collection of all users in this channel. - new Task> GetUsers(); + new Task> GetUsersAsync(); /// Gets a user in this channel with the provided id. - new Task GetUser(ulong id); + new Task GetUserAsync(ulong id); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Channels/IMessageChannel.cs b/src/Discord.Net/Entities/Channels/IMessageChannel.cs index bb9015c1f..a5a73b177 100644 --- a/src/Discord.Net/Entities/Channels/IMessageChannel.cs +++ b/src/Discord.Net/Entities/Channels/IMessageChannel.cs @@ -10,24 +10,24 @@ namespace Discord IReadOnlyCollection CachedMessages { get; } /// Sends a message to this message channel. - Task SendMessage(string text, bool isTTS = false); + Task SendMessageAsync(string text, bool isTTS = false); /// Sends a file to this text channel, with an optional caption. - Task SendFile(string filePath, string text = null, bool isTTS = false); + Task SendFileAsync(string filePath, string text = null, bool isTTS = false); /// Sends a file to this text channel, with an optional caption. - Task SendFile(Stream stream, string filename, string text = null, bool isTTS = false); + Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false); /// Gets a message from this message channel with the given id, or null if not found. - Task GetMessage(ulong id); + Task GetMessageAsync(ulong id); /// Gets the message from this channel's cache with the given id, or null if not found. IMessage GetCachedMessage(ulong id); /// Gets the last N messages from this message channel. - Task> GetMessages(int limit = DiscordConfig.MaxMessagesPerBatch); + Task> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); /// Gets a collection of messages in this channel. - Task> GetMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); + Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); /// Bulk deletes multiple messages. - Task DeleteMessages(IEnumerable messages); + Task DeleteMessagesAsync(IEnumerable messages); /// Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. - Task TriggerTyping(); + Task TriggerTypingAsync(); } } diff --git a/src/Discord.Net/Entities/Channels/ITextChannel.cs b/src/Discord.Net/Entities/Channels/ITextChannel.cs index fe0578e57..3b4248b6e 100644 --- a/src/Discord.Net/Entities/Channels/ITextChannel.cs +++ b/src/Discord.Net/Entities/Channels/ITextChannel.cs @@ -10,6 +10,6 @@ namespace Discord string Topic { get; } /// Modifies this text channel. - Task Modify(Action func); + Task ModifyAsync(Action func); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Channels/IVoiceChannel.cs b/src/Discord.Net/Entities/Channels/IVoiceChannel.cs index d94a97a63..fc90b2935 100644 --- a/src/Discord.Net/Entities/Channels/IVoiceChannel.cs +++ b/src/Discord.Net/Entities/Channels/IVoiceChannel.cs @@ -12,6 +12,6 @@ namespace Discord int UserLimit { get; } /// Modifies this voice channel. - Task Modify(Action func); + Task ModifyAsync(Action func); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Channels/TextChannel.cs b/src/Discord.Net/Entities/Channels/TextChannel.cs index 2c824ffa8..778eea0ac 100644 --- a/src/Discord.Net/Entities/Channels/TextChannel.cs +++ b/src/Discord.Net/Entities/Channels/TextChannel.cs @@ -30,83 +30,83 @@ namespace Discord base.Update(model, UpdateSource.Rest); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func != null) throw new NullReferenceException(nameof(func)); var args = new ModifyTextChannelParams(); func(args); - var model = await Discord.ApiClient.ModifyGuildChannel(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public override async Task GetUser(ulong id) + public override async Task GetUserAsync(ulong id) { - var user = await Guild.GetUser(id).ConfigureAwait(false); + var user = await Guild.GetUserAsync(id).ConfigureAwait(false); if (user != null && Permissions.GetValue(Permissions.ResolveChannel(user, this, user.GuildPermissions.RawValue), ChannelPermission.ReadMessages)) return user; return null; } - public override async Task> GetUsers() + public override async Task> GetUsersAsync() { - var users = await Guild.GetUsers().ConfigureAwait(false); + var users = await Guild.GetUsersAsync().ConfigureAwait(false); return users.Where(x => Permissions.GetValue(Permissions.ResolveChannel(x, this, x.GuildPermissions.RawValue), ChannelPermission.ReadMessages)).ToImmutableArray(); } - public override async Task> GetUsers(int limit, int offset) + public override async Task> GetUsersAsync(int limit, int offset) { - var users = await Guild.GetUsers(limit, offset).ConfigureAwait(false); + var users = await Guild.GetUsersAsync(limit, offset).ConfigureAwait(false); return users.Where(x => Permissions.GetValue(Permissions.ResolveChannel(x, this, x.GuildPermissions.RawValue), ChannelPermission.ReadMessages)).ToImmutableArray(); } - public async Task SendMessage(string text, bool isTTS) + public async Task SendMessageAsync(string text, bool isTTS) { var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; - var model = await Discord.ApiClient.CreateMessage(Guild.Id, Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateMessageAsync(Guild.Id, Id, args).ConfigureAwait(false); return new Message(this, new User(Discord, model.Author), model); } - public async Task SendFile(string filePath, string text, bool isTTS) + public async Task SendFileAsync(string filePath, string text, bool isTTS) { string filename = Path.GetFileName(filePath); using (var file = File.OpenRead(filePath)) { var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; - var model = await Discord.ApiClient.UploadFile(Guild.Id, Id, file, args).ConfigureAwait(false); + var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, file, args).ConfigureAwait(false); return new Message(this, new User(Discord, model.Author), model); } } - public async Task SendFile(Stream stream, string filename, string text, bool isTTS) + public async Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) { var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; - var model = await Discord.ApiClient.UploadFile(Guild.Id, Id, stream, args).ConfigureAwait(false); + var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, stream, args).ConfigureAwait(false); return new Message(this, new User(Discord, model.Author), model); } - public virtual async Task GetMessage(ulong id) + public virtual async Task GetMessageAsync(ulong id) { - var model = await Discord.ApiClient.GetChannelMessage(Id, id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); if (model != null) return new Message(this, new User(Discord, model.Author), model); return null; } - public virtual async Task> GetMessages(int limit) + public virtual async Task> GetMessagesAsync(int limit) { var args = new GetChannelMessagesParams { Limit = limit }; - var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); + var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); } - public virtual async Task> GetMessages(ulong fromMessageId, Direction dir, int limit) + public virtual async Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) { var args = new GetChannelMessagesParams { Limit = limit }; - var models = await Discord.ApiClient.GetChannelMessages(Id, args).ConfigureAwait(false); + var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); return models.Select(x => new Message(this, new User(Discord, x.Author), x)).ToImmutableArray(); } - public async Task DeleteMessages(IEnumerable messages) + public async Task DeleteMessagesAsync(IEnumerable messages) { - await Discord.ApiClient.DeleteMessages(Guild.Id, Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); + await Discord.ApiClient.DeleteMessagesAsync(Guild.Id, Id, new DeleteMessagesParams { MessageIds = messages.Select(x => x.Id) }).ConfigureAwait(false); } - public async Task TriggerTyping() + public async Task TriggerTypingAsync() { - await Discord.ApiClient.TriggerTypingIndicator(Id).ConfigureAwait(false); + await Discord.ApiClient.TriggerTypingIndicatorAsync(Id).ConfigureAwait(false); } private string DebuggerDisplay => $"{Name} ({Id}, Text)"; diff --git a/src/Discord.Net/Entities/Channels/VoiceChannel.cs b/src/Discord.Net/Entities/Channels/VoiceChannel.cs index 8947c9672..2d2d5ed63 100644 --- a/src/Discord.Net/Entities/Channels/VoiceChannel.cs +++ b/src/Discord.Net/Entities/Channels/VoiceChannel.cs @@ -26,25 +26,25 @@ namespace Discord UserLimit = model.UserLimit; } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func != null) throw new NullReferenceException(nameof(func)); var args = new ModifyVoiceChannelParams(); func(args); - var model = await Discord.ApiClient.ModifyGuildChannel(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public override Task GetUser(ulong id) + public override Task GetUserAsync(ulong id) { throw new NotSupportedException(); } - public override Task> GetUsers() + public override Task> GetUsersAsync() { throw new NotSupportedException(); } - public override Task> GetUsers(int limit, int offset) + public override Task> GetUsersAsync(int limit, int offset) { throw new NotSupportedException(); } diff --git a/src/Discord.Net/Entities/Guilds/Guild.cs b/src/Discord.Net/Entities/Guilds/Guild.cs index 65ce5ec71..c8e79238b 100644 --- a/src/Discord.Net/Entities/Guilds/Guild.cs +++ b/src/Discord.Net/Entities/Guilds/Guild.cs @@ -103,114 +103,114 @@ namespace Discord } } - public async Task Update() + public async Task UpdateAsync() { if (IsAttached) throw new NotSupportedException(); - var response = await Discord.ApiClient.GetGuild(Id).ConfigureAwait(false); + var response = await Discord.ApiClient.GetGuildAsync(Id).ConfigureAwait(false); Update(response, UpdateSource.Rest); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func == null) throw new NullReferenceException(nameof(func)); var args = new ModifyGuildParams(); func(args); - var model = await Discord.ApiClient.ModifyGuild(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.ModifyGuildAsync(Id, args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task ModifyEmbed(Action func) + public async Task ModifyEmbedAsync(Action func) { if (func == null) throw new NullReferenceException(nameof(func)); var args = new ModifyGuildEmbedParams(); func(args); - var model = await Discord.ApiClient.ModifyGuildEmbed(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.ModifyGuildEmbedAsync(Id, args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task ModifyChannels(IEnumerable args) + public async Task ModifyChannelsAsync(IEnumerable args) { //TODO: Update channels - await Discord.ApiClient.ModifyGuildChannels(Id, args).ConfigureAwait(false); + await Discord.ApiClient.ModifyGuildChannelsAsync(Id, args).ConfigureAwait(false); } - public async Task ModifyRoles(IEnumerable args) + public async Task ModifyRolesAsync(IEnumerable args) { - var models = await Discord.ApiClient.ModifyGuildRoles(Id, args).ConfigureAwait(false); + var models = await Discord.ApiClient.ModifyGuildRolesAsync(Id, args).ConfigureAwait(false); Update(models, UpdateSource.Rest); } - public async Task Leave() + public async Task LeaveAsync() { - await Discord.ApiClient.LeaveGuild(Id).ConfigureAwait(false); + await Discord.ApiClient.LeaveGuildAsync(Id).ConfigureAwait(false); } - public async Task Delete() + public async Task DeleteAsync() { - await Discord.ApiClient.DeleteGuild(Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false); } - public async Task> GetBans() + public async Task> GetBansAsync() { - var models = await Discord.ApiClient.GetGuildBans(Id).ConfigureAwait(false); + var models = await Discord.ApiClient.GetGuildBansAsync(Id).ConfigureAwait(false); return models.Select(x => new User(Discord, x)).ToImmutableArray(); } - public Task AddBan(IUser user, int pruneDays = 0) => AddBan(user, pruneDays); - public async Task AddBan(ulong userId, int pruneDays = 0) + public Task AddBanAsync(IUser user, int pruneDays = 0) => AddBanAsync(user, pruneDays); + public async Task AddBanAsync(ulong userId, int pruneDays = 0) { var args = new CreateGuildBanParams() { PruneDays = pruneDays }; - await Discord.ApiClient.CreateGuildBan(Id, userId, args).ConfigureAwait(false); + await Discord.ApiClient.CreateGuildBanAsync(Id, userId, args).ConfigureAwait(false); } - public Task RemoveBan(IUser user) => RemoveBan(user.Id); - public async Task RemoveBan(ulong userId) + public Task RemoveBanAsync(IUser user) => RemoveBanAsync(user.Id); + public async Task RemoveBanAsync(ulong userId) { - await Discord.ApiClient.RemoveGuildBan(Id, userId).ConfigureAwait(false); + await Discord.ApiClient.RemoveGuildBanAsync(Id, userId).ConfigureAwait(false); } - public virtual async Task GetChannel(ulong id) + public virtual async Task GetChannelAsync(ulong id) { - var model = await Discord.ApiClient.GetChannel(Id, id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetChannelAsync(Id, id).ConfigureAwait(false); if (model != null) return ToChannel(model); return null; } - public virtual async Task> GetChannels() + public virtual async Task> GetChannelsAsync() { - var models = await Discord.ApiClient.GetGuildChannels(Id).ConfigureAwait(false); + var models = await Discord.ApiClient.GetGuildChannelsAsync(Id).ConfigureAwait(false); return models.Select(x => ToChannel(x)).ToImmutableArray(); } - public async Task CreateTextChannel(string name) + public async Task CreateTextChannelAsync(string name) { if (name == null) throw new ArgumentNullException(nameof(name)); var args = new CreateGuildChannelParams() { Name = name, Type = ChannelType.Text }; - var model = await Discord.ApiClient.CreateGuildChannel(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateGuildChannelAsync(Id, args).ConfigureAwait(false); return new TextChannel(this, model); } - public async Task CreateVoiceChannel(string name) + public async Task CreateVoiceChannelAsync(string name) { if (name == null) throw new ArgumentNullException(nameof(name)); var args = new CreateGuildChannelParams { Name = name, Type = ChannelType.Voice }; - var model = await Discord.ApiClient.CreateGuildChannel(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateGuildChannelAsync(Id, args).ConfigureAwait(false); return new VoiceChannel(this, model); } - public async Task> GetIntegrations() + public async Task> GetIntegrationsAsync() { - var models = await Discord.ApiClient.GetGuildIntegrations(Id).ConfigureAwait(false); + var models = await Discord.ApiClient.GetGuildIntegrationsAsync(Id).ConfigureAwait(false); return models.Select(x => new GuildIntegration(this, x)).ToImmutableArray(); } - public async Task CreateIntegration(ulong id, string type) + public async Task CreateIntegrationAsync(ulong id, string type) { var args = new CreateGuildIntegrationParams { Id = id, Type = type }; - var model = await Discord.ApiClient.CreateGuildIntegration(Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateGuildIntegrationAsync(Id, args).ConfigureAwait(false); return new GuildIntegration(this, model); } - public async Task> GetInvites() + public async Task> GetInvitesAsync() { - var models = await Discord.ApiClient.GetGuildInvites(Id).ConfigureAwait(false); + var models = await Discord.ApiClient.GetGuildInvitesAsync(Id).ConfigureAwait(false); return models.Select(x => new InviteMetadata(Discord, x)).ToImmutableArray(); } - public async Task CreateInvite(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) + public async Task CreateInviteAsync(int? maxAge = 1800, int? maxUses = null, bool isTemporary = false, bool withXkcd = false) { if (maxAge <= 0) throw new ArgumentOutOfRangeException(nameof(maxAge)); if (maxUses <= 0) throw new ArgumentOutOfRangeException(nameof(maxUses)); @@ -222,7 +222,7 @@ namespace Discord Temporary = isTemporary, XkcdPass = withXkcd }; - var model = await Discord.ApiClient.CreateChannelInvite(DefaultChannelId, args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateChannelInviteAsync(DefaultChannelId, args).ConfigureAwait(false); return new InviteMetadata(Discord, model); } @@ -233,14 +233,14 @@ namespace Discord return result; return null; } - public async Task CreateRole(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false) + public async Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false) { if (name == null) throw new ArgumentNullException(nameof(name)); - var model = await Discord.ApiClient.CreateGuildRole(Id).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateGuildRoleAsync(Id).ConfigureAwait(false); var role = new Role(this, model); - await role.Modify(x => + await role.ModifyAsync(x => { x.Name = name; x.Permissions = (permissions ?? role.Permissions).RawValue; @@ -251,38 +251,38 @@ namespace Discord return role; } - public virtual async Task GetUser(ulong id) + public virtual async Task GetUserAsync(ulong id) { - var model = await Discord.ApiClient.GetGuildMember(Id, id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetGuildMemberAsync(Id, id).ConfigureAwait(false); if (model != null) return new GuildUser(this, new User(Discord, model.User), model); return null; } - public virtual async Task GetCurrentUser() + public virtual async Task GetCurrentUserAsync() { - var currentUser = await Discord.GetCurrentUser().ConfigureAwait(false); - return await GetUser(currentUser.Id).ConfigureAwait(false); + var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false); + return await GetUserAsync(currentUser.Id).ConfigureAwait(false); } - public virtual async Task> GetUsers() + public virtual async Task> GetUsersAsync() { var args = new GetGuildMembersParams(); - var models = await Discord.ApiClient.GetGuildMembers(Id, args).ConfigureAwait(false); + var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); return models.Select(x => new GuildUser(this, new User(Discord, x.User), x)).ToImmutableArray(); } - public virtual async Task> GetUsers(int limit, int offset) + public virtual async Task> GetUsersAsync(int limit, int offset) { var args = new GetGuildMembersParams { Limit = limit, Offset = offset }; - var models = await Discord.ApiClient.GetGuildMembers(Id, args).ConfigureAwait(false); + var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); return models.Select(x => new GuildUser(this, new User(Discord, x.User), x)).ToImmutableArray(); } - public async Task PruneUsers(int days = 30, bool simulate = false) + public async Task PruneUsersAsync(int days = 30, bool simulate = false) { var args = new GuildPruneParams() { Days = days }; GetGuildPruneCountResponse model; if (simulate) - model = await Discord.ApiClient.GetGuildPruneCount(Id, args).ConfigureAwait(false); + model = await Discord.ApiClient.GetGuildPruneCountAsync(Id, args).ConfigureAwait(false); else - model = await Discord.ApiClient.BeginGuildPrune(Id, args).ConfigureAwait(false); + model = await Discord.ApiClient.BeginGuildPruneAsync(Id, args).ConfigureAwait(false); return model.Pruned; } @@ -306,7 +306,7 @@ namespace Discord IRole IGuild.EveryoneRole => EveryoneRole; IReadOnlyCollection IGuild.Emojis => Emojis; IReadOnlyCollection IGuild.Features => Features; - Task IGuild.DownloadUsers() { throw new NotSupportedException(); } + Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); } IRole IGuild.GetRole(ulong id) => GetRole(id); } diff --git a/src/Discord.Net/Entities/Guilds/GuildIntegration.cs b/src/Discord.Net/Entities/Guilds/GuildIntegration.cs index 5dbdd6d47..913536fa6 100644 --- a/src/Discord.Net/Entities/Guilds/GuildIntegration.cs +++ b/src/Discord.Net/Entities/Guilds/GuildIntegration.cs @@ -47,23 +47,23 @@ namespace Discord User = new User(Discord, model.User); } - public async Task Delete() + public async Task DeleteAsync() { - await Discord.ApiClient.DeleteGuildIntegration(Guild.Id, Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteGuildIntegrationAsync(Guild.Id, Id).ConfigureAwait(false); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func == null) throw new NullReferenceException(nameof(func)); var args = new ModifyGuildIntegrationParams(); func(args); - var model = await Discord.ApiClient.ModifyGuildIntegration(Guild.Id, Id, args).ConfigureAwait(false); + var model = await Discord.ApiClient.ModifyGuildIntegrationAsync(Guild.Id, Id, args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Sync() + public async Task SyncAsync() { - await Discord.ApiClient.SyncGuildIntegration(Guild.Id, Id).ConfigureAwait(false); + await Discord.ApiClient.SyncGuildIntegrationAsync(Guild.Id, Id).ConfigureAwait(false); } public override string ToString() => Name; diff --git a/src/Discord.Net/Entities/Guilds/IGuild.cs b/src/Discord.Net/Entities/Guilds/IGuild.cs index 8d86dcd8b..9949b788d 100644 --- a/src/Discord.Net/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net/Entities/Guilds/IGuild.cs @@ -40,59 +40,59 @@ namespace Discord IReadOnlyCollection Roles { get; } /// Modifies this guild. - Task Modify(Action func); + Task ModifyAsync(Action func); /// Modifies this guild's embed. - Task ModifyEmbed(Action func); + Task ModifyEmbedAsync(Action func); /// Bulk modifies the channels of this guild. - Task ModifyChannels(IEnumerable args); + Task ModifyChannelsAsync(IEnumerable args); /// Bulk modifies the roles of this guild. - Task ModifyRoles(IEnumerable args); + Task ModifyRolesAsync(IEnumerable args); /// Leaves this guild. If you are the owner, use Delete instead. - Task Leave(); + Task LeaveAsync(); /// Gets a collection of all users banned on this guild. - Task> GetBans(); + Task> GetBansAsync(); /// Bans the provided user from this guild and optionally prunes their recent messages. - Task AddBan(IUser user, int pruneDays = 0); + Task AddBanAsync(IUser user, int pruneDays = 0); /// Bans the provided user id from this guild and optionally prunes their recent messages. - Task AddBan(ulong userId, int pruneDays = 0); + Task AddBanAsync(ulong userId, int pruneDays = 0); /// Unbans the provided user if it is currently banned. - Task RemoveBan(IUser user); + Task RemoveBanAsync(IUser user); /// Unbans the provided user id if it is currently banned. - Task RemoveBan(ulong userId); + Task RemoveBanAsync(ulong userId); /// Gets a collection of all channels in this guild. - Task> GetChannels(); + Task> GetChannelsAsync(); /// Gets the channel in this guild with the provided id, or null if not found. - Task GetChannel(ulong id); + Task GetChannelAsync(ulong id); /// Creates a new text channel. - Task CreateTextChannel(string name); + Task CreateTextChannelAsync(string name); /// Creates a new voice channel. - Task CreateVoiceChannel(string name); + Task CreateVoiceChannelAsync(string name); /// Gets a collection of all invites to this guild. - Task> GetInvites(); + Task> GetInvitesAsync(); /// Creates a new invite to this guild. /// The time (in seconds) until the invite expires. Set to null to never expire. /// The max amount of times this invite may be used. Set to null to have unlimited uses. /// If true, a user accepting this invite will be kicked from the guild after closing their client. /// If true, creates a human-readable link. Not supported if maxAge is set to null. - Task CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); + Task CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool withXkcd = false); /// Gets the role in this guild with the provided id, or null if not found. IRole GetRole(ulong id); /// Creates a new role. - Task CreateRole(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false); + Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false); /// Gets a collection of all users in this guild. - Task> GetUsers(); + Task> GetUsersAsync(); /// Gets the user in this guild with the provided id, or null if not found. - Task GetUser(ulong id); + Task GetUserAsync(ulong id); /// Gets the current user for this guild. - Task GetCurrentUser(); + Task GetCurrentUserAsync(); /// Downloads all users for this guild if the current list is incomplete. - Task DownloadUsers(); + Task DownloadUsersAsync(); /// Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. - Task PruneUsers(int days = 30, bool simulate = false); + Task PruneUsersAsync(int days = 30, bool simulate = false); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Guilds/UserGuild.cs b/src/Discord.Net/Entities/Guilds/UserGuild.cs index a34b40d85..9d76817e5 100644 --- a/src/Discord.Net/Entities/Guilds/UserGuild.cs +++ b/src/Discord.Net/Entities/Guilds/UserGuild.cs @@ -33,13 +33,13 @@ namespace Discord Permissions = new GuildPermissions(model.Permissions); } - public async Task Leave() + public async Task LeaveAsync() { - await Discord.ApiClient.LeaveGuild(Id).ConfigureAwait(false); + await Discord.ApiClient.LeaveGuildAsync(Id).ConfigureAwait(false); } - public async Task Delete() + public async Task DeleteAsync() { - await Discord.ApiClient.DeleteGuild(Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false); } public override string ToString() => Name; diff --git a/src/Discord.Net/Entities/IDeletable.cs b/src/Discord.Net/Entities/IDeletable.cs index 98887b571..f35f8ad88 100644 --- a/src/Discord.Net/Entities/IDeletable.cs +++ b/src/Discord.Net/Entities/IDeletable.cs @@ -5,6 +5,6 @@ namespace Discord public interface IDeletable { /// Deletes this object and all its children. - Task Delete(); + Task DeleteAsync(); } } diff --git a/src/Discord.Net/Entities/IUpdateable.cs b/src/Discord.Net/Entities/IUpdateable.cs index 4f7d5ed34..50b23bb95 100644 --- a/src/Discord.Net/Entities/IUpdateable.cs +++ b/src/Discord.Net/Entities/IUpdateable.cs @@ -5,6 +5,6 @@ namespace Discord public interface IUpdateable { /// Updates this object's properties with its current state. - Task Update(); + Task UpdateAsync(); } } diff --git a/src/Discord.Net/Entities/Invites/IInvite.cs b/src/Discord.Net/Entities/Invites/IInvite.cs index eddc3df5a..d9da5b3ec 100644 --- a/src/Discord.Net/Entities/Invites/IInvite.cs +++ b/src/Discord.Net/Entities/Invites/IInvite.cs @@ -19,6 +19,6 @@ namespace Discord ulong GuildId { get; } /// Accepts this invite and joins the target guild. This will fail on bot accounts. - Task Accept(); + Task AcceptAsync(); } } diff --git a/src/Discord.Net/Entities/Invites/Invite.cs b/src/Discord.Net/Entities/Invites/Invite.cs index d21b93331..90e380582 100644 --- a/src/Discord.Net/Entities/Invites/Invite.cs +++ b/src/Discord.Net/Entities/Invites/Invite.cs @@ -37,13 +37,13 @@ namespace Discord ChannelName = model.Channel.Name; } - public async Task Accept() + public async Task AcceptAsync() { - await Discord.ApiClient.AcceptInvite(Code).ConfigureAwait(false); + await Discord.ApiClient.AcceptInviteAsync(Code).ConfigureAwait(false); } - public async Task Delete() + public async Task DeleteAsync() { - await Discord.ApiClient.DeleteInvite(Code).ConfigureAwait(false); + await Discord.ApiClient.DeleteInviteAsync(Code).ConfigureAwait(false); } public override string ToString() => XkcdUrl ?? Url; diff --git a/src/Discord.Net/Entities/Messages/IMessage.cs b/src/Discord.Net/Entities/Messages/IMessage.cs index d9cd9ab04..311eb17d5 100644 --- a/src/Discord.Net/Entities/Messages/IMessage.cs +++ b/src/Discord.Net/Entities/Messages/IMessage.cs @@ -34,6 +34,6 @@ namespace Discord IReadOnlyCollection MentionedUsers { get; } /// Modifies this message. - Task Modify(Action func); + Task ModifyAsync(Action func); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Messages/Message.cs b/src/Discord.Net/Entities/Messages/Message.cs index 4d05e409f..e72f89a57 100644 --- a/src/Discord.Net/Entities/Messages/Message.cs +++ b/src/Discord.Net/Entities/Messages/Message.cs @@ -97,14 +97,14 @@ namespace Discord Text = MentionUtils.CleanUserMentions(model.Content, model.Mentions); } - public async Task Update() + public async Task UpdateAsync() { if (IsAttached) throw new NotSupportedException(); - var model = await Discord.ApiClient.GetChannelMessage(Channel.Id, Id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetChannelMessageAsync(Channel.Id, Id).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func == null) throw new NullReferenceException(nameof(func)); @@ -114,18 +114,18 @@ namespace Discord Model model; if (guildChannel != null) - model = await Discord.ApiClient.ModifyMessage(guildChannel.Guild.Id, Channel.Id, Id, args).ConfigureAwait(false); + model = await Discord.ApiClient.ModifyMessageAsync(guildChannel.Guild.Id, Channel.Id, Id, args).ConfigureAwait(false); else - model = await Discord.ApiClient.ModifyDMMessage(Channel.Id, Id, args).ConfigureAwait(false); + model = await Discord.ApiClient.ModifyDMMessageAsync(Channel.Id, Id, args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Delete() + public async Task DeleteAsync() { var guildChannel = Channel as GuildChannel; if (guildChannel != null) - await Discord.ApiClient.DeleteMessage(guildChannel.Id, Channel.Id, Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteMessageAsync(guildChannel.Id, Channel.Id, Id).ConfigureAwait(false); else - await Discord.ApiClient.DeleteDMMessage(Channel.Id, Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteDMMessageAsync(Channel.Id, Id).ConfigureAwait(false); } public override string ToString() => Text; diff --git a/src/Discord.Net/Entities/Roles/IRole.cs b/src/Discord.Net/Entities/Roles/IRole.cs index 36d0ce641..29975be46 100644 --- a/src/Discord.Net/Entities/Roles/IRole.cs +++ b/src/Discord.Net/Entities/Roles/IRole.cs @@ -24,6 +24,6 @@ namespace Discord ulong GuildId { get; } /// Modifies this role. - Task Modify(Action func); + Task ModifyAsync(Action func); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Roles/Role.cs b/src/Discord.Net/Entities/Roles/Role.cs index 577a4c252..9511ce67e 100644 --- a/src/Discord.Net/Entities/Roles/Role.cs +++ b/src/Discord.Net/Entities/Roles/Role.cs @@ -44,18 +44,18 @@ namespace Discord Permissions = new GuildPermissions(model.Permissions.Value); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func == null) throw new NullReferenceException(nameof(func)); var args = new ModifyGuildRoleParams(); func(args); - var response = await Discord.ApiClient.ModifyGuildRole(Guild.Id, Id, args).ConfigureAwait(false); + var response = await Discord.ApiClient.ModifyGuildRoleAsync(Guild.Id, Id, args).ConfigureAwait(false); Update(response, UpdateSource.Rest); } - public async Task Delete() + public async Task DeleteAsync() { - await Discord.ApiClient.DeleteGuildRole(Guild.Id, Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteGuildRoleAsync(Guild.Id, Id).ConfigureAwait(false); } public Role Clone() => MemberwiseClone() as Role; diff --git a/src/Discord.Net/Entities/Users/GuildUser.cs b/src/Discord.Net/Entities/Users/GuildUser.cs index dd879dd20..b520d301f 100644 --- a/src/Discord.Net/Entities/Users/GuildUser.cs +++ b/src/Discord.Net/Entities/Users/GuildUser.cs @@ -67,31 +67,31 @@ namespace Discord IsMute = model.Mute; } - public async Task Update() + public async Task UpdateAsync() { if (IsAttached) throw new NotSupportedException(); - var model = await Discord.ApiClient.GetGuildMember(Guild.Id, Id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetGuildMemberAsync(Guild.Id, Id).ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func == null) throw new NullReferenceException(nameof(func)); var args = new ModifyGuildMemberParams(); func(args); - bool isCurrentUser = (await Discord.GetCurrentUser().ConfigureAwait(false)).Id == Id; + bool isCurrentUser = (await Discord.GetCurrentUserAsync().ConfigureAwait(false)).Id == Id; if (isCurrentUser && args.Nickname.IsSpecified) { var nickArgs = new ModifyCurrentUserNickParams { Nickname = args.Nickname.Value ?? "" }; - await Discord.ApiClient.ModifyCurrentUserNick(Guild.Id, nickArgs).ConfigureAwait(false); + await Discord.ApiClient.ModifyMyNickAsync(Guild.Id, nickArgs).ConfigureAwait(false); args.Nickname = new Optional(); //Remove } if (!isCurrentUser || args.Deaf.IsSpecified || args.Mute.IsSpecified || args.Roles.IsSpecified) { - await Discord.ApiClient.ModifyGuildMember(Guild.Id, Id, args).ConfigureAwait(false); + await Discord.ApiClient.ModifyGuildMemberAsync(Guild.Id, Id, args).ConfigureAwait(false); if (args.Deaf.IsSpecified) IsDeaf = args.Deaf.Value; if (args.Mute.IsSpecified) @@ -102,9 +102,9 @@ namespace Discord Roles = args.Roles.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray(); } } - public async Task Kick() + public async Task KickAsync() { - await Discord.ApiClient.RemoveGuildMember(Guild.Id, Id).ConfigureAwait(false); + await Discord.ApiClient.RemoveGuildMemberAsync(Guild.Id, Id).ConfigureAwait(false); } public ChannelPermissions GetPermissions(IGuildChannel channel) @@ -113,7 +113,7 @@ namespace Discord return new ChannelPermissions(Permissions.ResolveChannel(this, channel, GuildPermissions.RawValue)); } - public Task CreateDMChannel() => User.CreateDMChannel(); + public Task CreateDMChannelAsync() => User.CreateDMChannelAsync(); IGuild IGuildUser.Guild => Guild; IReadOnlyCollection IGuildUser.Roles => Roles; diff --git a/src/Discord.Net/Entities/Users/IGuildUser.cs b/src/Discord.Net/Entities/Users/IGuildUser.cs index 5b68af6ca..ad90b6901 100644 --- a/src/Discord.Net/Entities/Users/IGuildUser.cs +++ b/src/Discord.Net/Entities/Users/IGuildUser.cs @@ -28,8 +28,8 @@ namespace Discord ChannelPermissions GetPermissions(IGuildChannel channel); /// Kicks this user from this guild. - Task Kick(); + Task KickAsync(); /// Modifies this user's properties in this guild. - Task Modify(Action func); + Task ModifyAsync(Action func); } } diff --git a/src/Discord.Net/Entities/Users/ISelfUser.cs b/src/Discord.Net/Entities/Users/ISelfUser.cs index d6e7c7718..8efd0cef4 100644 --- a/src/Discord.Net/Entities/Users/ISelfUser.cs +++ b/src/Discord.Net/Entities/Users/ISelfUser.cs @@ -11,6 +11,6 @@ namespace Discord /// Returns true if this user's email has been verified. bool IsVerified { get; } - Task Modify(Action func); + Task ModifyAsync(Action func); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Users/IUser.cs b/src/Discord.Net/Entities/Users/IUser.cs index 0b1b04332..9f2709a3d 100644 --- a/src/Discord.Net/Entities/Users/IUser.cs +++ b/src/Discord.Net/Entities/Users/IUser.cs @@ -15,6 +15,6 @@ namespace Discord //TODO: CreateDMChannel is a candidate to move to IGuildUser, and User made a common class, depending on next friends list update /// Returns a private message channel to this user, creating one if it does not already exist. - Task CreateDMChannel(); + Task CreateDMChannelAsync(); } } diff --git a/src/Discord.Net/Entities/Users/SelfUser.cs b/src/Discord.Net/Entities/Users/SelfUser.cs index 1e0a621a1..bdd90d2ff 100644 --- a/src/Discord.Net/Entities/Users/SelfUser.cs +++ b/src/Discord.Net/Entities/Users/SelfUser.cs @@ -24,20 +24,20 @@ namespace Discord IsVerified = model.IsVerified; } - public async Task Update() + public async Task UpdateAsync() { if (IsAttached) throw new NotSupportedException(); - var model = await Discord.ApiClient.GetCurrentUser().ConfigureAwait(false); + var model = await Discord.ApiClient.GetSelfAsync().ConfigureAwait(false); Update(model, UpdateSource.Rest); } - public async Task Modify(Action func) + public async Task ModifyAsync(Action func) { if (func != null) throw new NullReferenceException(nameof(func)); var args = new ModifyCurrentUserParams(); func(args); - var model = await Discord.ApiClient.ModifyCurrentUser(args).ConfigureAwait(false); + var model = await Discord.ApiClient.ModifySelfAsync(args).ConfigureAwait(false); Update(model, UpdateSource.Rest); } } diff --git a/src/Discord.Net/Entities/Users/User.cs b/src/Discord.Net/Entities/Users/User.cs index 6e1282933..70dd158c5 100644 --- a/src/Discord.Net/Entities/Users/User.cs +++ b/src/Discord.Net/Entities/Users/User.cs @@ -38,10 +38,10 @@ namespace Discord Username = model.Username; } - public async Task CreateDMChannel() + public async Task CreateDMChannelAsync() { var args = new CreateDMChannelParams { RecipientId = Id }; - var model = await Discord.ApiClient.CreateDMChannel(args).ConfigureAwait(false); + var model = await Discord.ApiClient.CreateDMChannelAsync(args).ConfigureAwait(false); return new DMChannel(Discord, this, model); } diff --git a/src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs b/src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs index 1c0520a5a..2bba02a46 100644 --- a/src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs +++ b/src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs @@ -21,9 +21,9 @@ namespace Discord _messages = new MessageCache(Discord, this); } - public override Task GetUser(ulong id) => Task.FromResult(GetCachedUser(id)); - public override Task> GetUsers() => Task.FromResult>(Members); - public override Task> GetUsers(int limit, int offset) + public override Task GetUserAsync(ulong id) => Task.FromResult(GetCachedUser(id)); + public override Task> GetUsersAsync() => Task.FromResult>(Members); + public override Task> GetUsersAsync(int limit, int offset) => Task.FromResult>(Members.Skip(offset).Take(limit).ToImmutableArray()); public ICachedUser GetCachedUser(ulong id) { @@ -36,17 +36,17 @@ namespace Discord return null; } - public override async Task GetMessage(ulong id) + public override async Task GetMessageAsync(ulong id) { - return await _messages.Download(id).ConfigureAwait(false); + return await _messages.DownloadAsync(id).ConfigureAwait(false); } - public override async Task> GetMessages(int limit) + public override async Task> GetMessagesAsync(int limit) { - return await _messages.Download(null, Direction.Before, limit).ConfigureAwait(false); + return await _messages.DownloadAsync(null, Direction.Before, limit).ConfigureAwait(false); } - public override async Task> GetMessages(ulong fromMessageId, Direction dir, int limit) + public override async Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) { - return await _messages.Download(fromMessageId, dir, limit).ConfigureAwait(false); + return await _messages.DownloadAsync(fromMessageId, dir, limit).ConfigureAwait(false); } public CachedMessage AddCachedMessage(ICachedUser author, MessageModel model) { diff --git a/src/Discord.Net/Entities/WebSocket/CachedGuild.cs b/src/Discord.Net/Entities/WebSocket/CachedGuild.cs index f8a4aa380..058cd5b52 100644 --- a/src/Discord.Net/Entities/WebSocket/CachedGuild.cs +++ b/src/Discord.Net/Entities/WebSocket/CachedGuild.cs @@ -107,8 +107,8 @@ namespace Discord _voiceStates = voiceStates; } - public override Task GetChannel(ulong id) => Task.FromResult(GetCachedChannel(id)); - public override Task> GetChannels() => Task.FromResult>(Channels); + public override Task GetChannelAsync(ulong id) => Task.FromResult(GetCachedChannel(id)); + public override Task> GetChannelsAsync() => Task.FromResult>(Channels); public ICachedGuildChannel AddCachedChannel(ChannelModel model, ConcurrentHashSet channels = null) { var channel = ToChannel(model); @@ -182,13 +182,13 @@ namespace Discord return null; } - public override Task GetUser(ulong id) => Task.FromResult(GetCachedUser(id)); - public override Task GetCurrentUser() + public override Task GetUserAsync(ulong id) => Task.FromResult(GetCachedUser(id)); + public override Task GetCurrentUserAsync() => Task.FromResult(CurrentUser); - public override Task> GetUsers() + public override Task> GetUsersAsync() => Task.FromResult>(Members); //TODO: Is there a better way of exposing pagination? - public override Task> GetUsers(int limit, int offset) + public override Task> GetUsersAsync(int limit, int offset) => Task.FromResult>(Members.OrderBy(x => x.Id).Skip(offset).Take(limit).ToImmutableArray()); public CachedGuildUser AddCachedUser(MemberModel model, ConcurrentDictionary members = null, DataStore dataStore = null) { @@ -213,10 +213,10 @@ namespace Discord return member; return null; } - public async Task DownloadMembers() + public async Task DownloadMembersAsync() { if (!HasAllMembers) - await Discord.ApiClient.SendRequestMembers(new ulong[] { Id }).ConfigureAwait(false); + await Discord.ApiClient.SendRequestMembersAsync(new ulong[] { Id }).ConfigureAwait(false); await _downloaderPromise.Task.ConfigureAwait(false); } public void CompleteDownloadMembers() diff --git a/src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs b/src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs index 95c0ac375..cedd5208b 100644 --- a/src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs +++ b/src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs @@ -23,9 +23,9 @@ namespace Discord _messages = new MessageCache(Discord, this); } - public override Task GetUser(ulong id) => Task.FromResult(GetCachedUser(id)); - public override Task> GetUsers() => Task.FromResult>(Members); - public override Task> GetUsers(int limit, int offset) + public override Task GetUserAsync(ulong id) => Task.FromResult(GetCachedUser(id)); + public override Task> GetUsersAsync() => Task.FromResult>(Members); + public override Task> GetUsersAsync(int limit, int offset) => Task.FromResult>(Members.Skip(offset).Take(limit).ToImmutableArray()); public CachedGuildUser GetCachedUser(ulong id) { @@ -35,17 +35,17 @@ namespace Discord return null; } - public override async Task GetMessage(ulong id) + public override async Task GetMessageAsync(ulong id) { - return await _messages.Download(id).ConfigureAwait(false); + return await _messages.DownloadAsync(id).ConfigureAwait(false); } - public override async Task> GetMessages(int limit = DiscordConfig.MaxMessagesPerBatch) + public override async Task> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) { - return await _messages.Download(null, Direction.Before, limit).ConfigureAwait(false); + return await _messages.DownloadAsync(null, Direction.Before, limit).ConfigureAwait(false); } - public override async Task> GetMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) + public override async Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) { - return await _messages.Download(fromMessageId, dir, limit).ConfigureAwait(false); + return await _messages.DownloadAsync(fromMessageId, dir, limit).ConfigureAwait(false); } public CachedMessage AddCachedMessage(ICachedUser author, MessageModel model) diff --git a/src/Discord.Net/Entities/WebSocket/CachedVoiceChannel.cs b/src/Discord.Net/Entities/WebSocket/CachedVoiceChannel.cs index 3b9f42bec..22639eb16 100644 --- a/src/Discord.Net/Entities/WebSocket/CachedVoiceChannel.cs +++ b/src/Discord.Net/Entities/WebSocket/CachedVoiceChannel.cs @@ -19,11 +19,11 @@ namespace Discord { } - public override Task GetUser(ulong id) + public override Task GetUserAsync(ulong id) => Task.FromResult(GetCachedUser(id)); - public override Task> GetUsers() + public override Task> GetUsersAsync() => Task.FromResult(Members); - public override Task> GetUsers(int limit, int offset) + public override Task> GetUsersAsync(int limit, int offset) => Task.FromResult>(Members.OrderBy(x => x.Id).Skip(offset).Take(limit).ToImmutableArray()); public IGuildUser GetCachedUser(ulong id) { diff --git a/src/Discord.Net/Extensions/DiscordClientExtensions.cs b/src/Discord.Net/Extensions/DiscordClientExtensions.cs index 4d262715e..53e09c0e0 100644 --- a/src/Discord.Net/Extensions/DiscordClientExtensions.cs +++ b/src/Discord.Net/Extensions/DiscordClientExtensions.cs @@ -5,9 +5,9 @@ namespace Discord.Extensions { public static class DiscordClientExtensions { - public static async Task GetOptimalVoiceRegion(this DiscordClient discord) + public static async Task GetOptimalVoiceRegionAsync(this DiscordClient discord) { - var regions = await discord.GetVoiceRegions().ConfigureAwait(false); + var regions = await discord.GetVoiceRegionsAsync().ConfigureAwait(false); return regions.FirstOrDefault(x => x.IsOptimal); } } diff --git a/src/Discord.Net/Extensions/EventExtensions.cs b/src/Discord.Net/Extensions/EventExtensions.cs index 867d4d41d..4467af55c 100644 --- a/src/Discord.Net/Extensions/EventExtensions.cs +++ b/src/Discord.Net/Extensions/EventExtensions.cs @@ -7,7 +7,7 @@ namespace Discord.Extensions { //TODO: Optimize these for if there is only 1 subscriber (can we do this?) //TODO: Could we maintain our own list instead of generating one on every invocation? - public static async Task Raise(this Func eventHandler) + public static async Task RaiseAsync(this Func eventHandler) { var subscriptions = eventHandler?.GetInvocationList(); if (subscriptions != null) @@ -16,7 +16,7 @@ namespace Discord.Extensions await (subscriptions[i] as Func).Invoke().ConfigureAwait(false); } } - public static async Task Raise(this Func eventHandler, T arg) + public static async Task RaiseAsync(this Func eventHandler, T arg) { var subscriptions = eventHandler?.GetInvocationList(); if (subscriptions != null) @@ -25,7 +25,7 @@ namespace Discord.Extensions await (subscriptions[i] as Func).Invoke(arg).ConfigureAwait(false); } } - public static async Task Raise(this Func eventHandler, T1 arg1, T2 arg2) + public static async Task RaiseAsync(this Func eventHandler, T1 arg1, T2 arg2) { var subscriptions = eventHandler?.GetInvocationList(); if (subscriptions != null) @@ -34,7 +34,7 @@ namespace Discord.Extensions await (subscriptions[i] as Func).Invoke(arg1, arg2).ConfigureAwait(false); } } - public static async Task Raise(this Func eventHandler, T1 arg1, T2 arg2, T3 arg3) + public static async Task RaiseAsync(this Func eventHandler, T1 arg1, T2 arg2, T3 arg3) { var subscriptions = eventHandler?.GetInvocationList(); if (subscriptions != null) @@ -43,7 +43,7 @@ namespace Discord.Extensions await (subscriptions[i] as Func).Invoke(arg1, arg2, arg3).ConfigureAwait(false); } } - public static async Task Raise(this Func eventHandler, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + public static async Task RaiseAsync(this Func eventHandler, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { var subscriptions = eventHandler?.GetInvocationList(); if (subscriptions != null) diff --git a/src/Discord.Net/Extensions/GuildExtensions.cs b/src/Discord.Net/Extensions/GuildExtensions.cs index a438994c9..8100ca4b5 100644 --- a/src/Discord.Net/Extensions/GuildExtensions.cs +++ b/src/Discord.Net/Extensions/GuildExtensions.cs @@ -4,9 +4,9 @@ namespace Discord.Extensions { public static class GuildExtensions { - public static async Task GetTextChannel(this IGuild guild, ulong id) - => await guild.GetChannel(id).ConfigureAwait(false) as ITextChannel; - public static async Task GetVoiceChannel(this IGuild guild, ulong id) - => await guild.GetChannel(id).ConfigureAwait(false) as IVoiceChannel; + public static async Task GetTextChannelAsync(this IGuild guild, ulong id) + => await guild.GetChannelAsync(id).ConfigureAwait(false) as ITextChannel; + public static async Task GetVoiceChannelAsync(this IGuild guild, ulong id) + => await guild.GetChannelAsync(id).ConfigureAwait(false) as IVoiceChannel; } } diff --git a/src/Discord.Net/IDiscordClient.cs b/src/Discord.Net/IDiscordClient.cs index e3049c9c3..821de976f 100644 --- a/src/Discord.Net/IDiscordClient.cs +++ b/src/Discord.Net/IDiscordClient.cs @@ -13,29 +13,29 @@ namespace Discord DiscordApiClient ApiClient { get; } - Task Login(TokenType tokenType, string token, bool validateToken = true); - Task Logout(); + Task LoginAsync(TokenType tokenType, string token, bool validateToken = true); + Task LogoutAsync(); - Task Connect(); - Task Disconnect(); + Task ConnectAsync(); + Task DisconnectAsync(); - Task GetChannel(ulong id); - Task> GetDMChannels(); + Task GetChannelAsync(ulong id); + Task> GetDMChannelsAsync(); - Task> GetConnections(); + Task> GetConnectionsAsync(); - Task GetGuild(ulong id); - Task> GetGuilds(); - Task CreateGuild(string name, IVoiceRegion region, Stream jpegIcon = null); + Task GetGuildAsync(ulong id); + Task> GetGuildsAsync(); + Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null); - Task GetInvite(string inviteIdOrXkcd); + Task GetInviteAsync(string inviteIdOrXkcd); - Task GetUser(ulong id); - Task GetUser(string username, string discriminator); - Task GetCurrentUser(); - Task> QueryUsers(string query, int limit); + Task GetUserAsync(ulong id); + Task GetUserAsync(string username, string discriminator); + Task GetCurrentUserAsync(); + Task> QueryUsersAsync(string query, int limit); - Task> GetVoiceRegions(); - Task GetVoiceRegion(string id); + Task> GetVoiceRegionsAsync(); + Task GetVoiceRegionAsync(string id); } } diff --git a/src/Discord.Net/Logging/ILogger.cs b/src/Discord.Net/Logging/ILogger.cs index ccc7f06f7..207c03dc7 100644 --- a/src/Discord.Net/Logging/ILogger.cs +++ b/src/Discord.Net/Logging/ILogger.cs @@ -7,28 +7,28 @@ namespace Discord.Logging { LogSeverity Level { get; } - Task Log(LogSeverity severity, string message, Exception exception = null); - Task Log(LogSeverity severity, FormattableString message, Exception exception = null); - Task Log(LogSeverity severity, Exception exception); + Task LogAsync(LogSeverity severity, string message, Exception exception = null); + Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null); + Task LogAsync(LogSeverity severity, Exception exception); - Task Error(string message, Exception exception = null); - Task Error(FormattableString message, Exception exception = null); - Task Error(Exception exception); + Task ErrorAsync(string message, Exception exception = null); + Task ErrorAsync(FormattableString message, Exception exception = null); + Task ErrorAsync(Exception exception); - Task Warning(string message, Exception exception = null); - Task Warning(FormattableString message, Exception exception = null); - Task Warning(Exception exception); + Task WarningAsync(string message, Exception exception = null); + Task WarningAsync(FormattableString message, Exception exception = null); + Task WarningAsync(Exception exception); - Task Info(string message, Exception exception = null); - Task Info(FormattableString message, Exception exception = null); - Task Info(Exception exception); + Task InfoAsync(string message, Exception exception = null); + Task InfoAsync(FormattableString message, Exception exception = null); + Task InfoAsync(Exception exception); - Task Verbose(string message, Exception exception = null); - Task Verbose(FormattableString message, Exception exception = null); - Task Verbose(Exception exception); + Task VerboseAsync(string message, Exception exception = null); + Task VerboseAsync(FormattableString message, Exception exception = null); + Task VerboseAsync(Exception exception); - Task Debug(string message, Exception exception = null); - Task Debug(FormattableString message, Exception exception = null); - Task Debug(Exception exception); + Task DebugAsync(string message, Exception exception = null); + Task DebugAsync(FormattableString message, Exception exception = null); + Task DebugAsync(Exception exception); } } diff --git a/src/Discord.Net/Logging/LogManager.cs b/src/Discord.Net/Logging/LogManager.cs index 83e82824c..2d1ef53c7 100644 --- a/src/Discord.Net/Logging/LogManager.cs +++ b/src/Discord.Net/Logging/LogManager.cs @@ -15,101 +15,101 @@ namespace Discord.Logging Level = minSeverity; } - public async Task Log(LogSeverity severity, string source, string message, Exception ex = null) + public async Task LogAsync(LogSeverity severity, string source, string message, Exception ex = null) { if (severity <= Level) - await Message.Raise(new LogMessage(severity, source, message, ex)).ConfigureAwait(false); + await Message.RaiseAsync(new LogMessage(severity, source, message, ex)).ConfigureAwait(false); } - public async Task Log(LogSeverity severity, string source, FormattableString message, Exception ex = null) + public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null) { if (severity <= Level) - await Message.Raise(new LogMessage(severity, source, message.ToString(), ex)).ConfigureAwait(false); + await Message.RaiseAsync(new LogMessage(severity, source, message.ToString(), ex)).ConfigureAwait(false); } - public async Task Log(LogSeverity severity, string source, Exception ex) + public async Task LogAsync(LogSeverity severity, string source, Exception ex) { if (severity <= Level) - await Message.Raise(new LogMessage(severity, source, null, ex)).ConfigureAwait(false); + await Message.RaiseAsync(new LogMessage(severity, source, null, ex)).ConfigureAwait(false); } - async Task ILogger.Log(LogSeverity severity, string message, Exception ex) + async Task ILogger.LogAsync(LogSeverity severity, string message, Exception ex) { if (severity <= Level) - await Message.Raise(new LogMessage(severity, "Discord", message, ex)).ConfigureAwait(false); + await Message.RaiseAsync(new LogMessage(severity, "Discord", message, ex)).ConfigureAwait(false); } - async Task ILogger.Log(LogSeverity severity, FormattableString message, Exception ex) + async Task ILogger.LogAsync(LogSeverity severity, FormattableString message, Exception ex) { if (severity <= Level) - await Message.Raise(new LogMessage(severity, "Discord", message.ToString(), ex)).ConfigureAwait(false); + await Message.RaiseAsync(new LogMessage(severity, "Discord", message.ToString(), ex)).ConfigureAwait(false); } - async Task ILogger.Log(LogSeverity severity, Exception ex) + async Task ILogger.LogAsync(LogSeverity severity, Exception ex) { if (severity <= Level) - await Message.Raise(new LogMessage(severity, "Discord", null, ex)).ConfigureAwait(false); + await Message.RaiseAsync(new LogMessage(severity, "Discord", null, ex)).ConfigureAwait(false); } - public Task Error(string source, string message, Exception ex = null) - => Log(LogSeverity.Error, source, message, ex); - public Task Error(string source, FormattableString message, Exception ex = null) - => Log(LogSeverity.Error, source, message, ex); - public Task Error(string source, Exception ex) - => Log(LogSeverity.Error, source, ex); - Task ILogger.Error(string message, Exception ex) - => Log(LogSeverity.Error, "Discord", message, ex); - Task ILogger.Error(FormattableString message, Exception ex) - => Log(LogSeverity.Error, "Discord", message, ex); - Task ILogger.Error(Exception ex) - => Log(LogSeverity.Error, "Discord", ex); + public Task ErrorAsync(string source, string message, Exception ex = null) + => LogAsync(LogSeverity.Error, source, message, ex); + public Task ErrorAsync(string source, FormattableString message, Exception ex = null) + => LogAsync(LogSeverity.Error, source, message, ex); + public Task ErrorAsync(string source, Exception ex) + => LogAsync(LogSeverity.Error, source, ex); + Task ILogger.ErrorAsync(string message, Exception ex) + => LogAsync(LogSeverity.Error, "Discord", message, ex); + Task ILogger.ErrorAsync(FormattableString message, Exception ex) + => LogAsync(LogSeverity.Error, "Discord", message, ex); + Task ILogger.ErrorAsync(Exception ex) + => LogAsync(LogSeverity.Error, "Discord", ex); - public Task Warning(string source, string message, Exception ex = null) - => Log(LogSeverity.Warning, source, message, ex); - public Task Warning(string source, FormattableString message, Exception ex = null) - => Log(LogSeverity.Warning, source, message, ex); - public Task Warning(string source, Exception ex) - => Log(LogSeverity.Warning, source, ex); - Task ILogger.Warning(string message, Exception ex) - => Log(LogSeverity.Warning, "Discord", message, ex); - Task ILogger.Warning(FormattableString message, Exception ex) - => Log(LogSeverity.Warning, "Discord", message, ex); - Task ILogger.Warning(Exception ex) - => Log(LogSeverity.Warning, "Discord", ex); + public Task WarningAsync(string source, string message, Exception ex = null) + => LogAsync(LogSeverity.Warning, source, message, ex); + public Task WarningAsync(string source, FormattableString message, Exception ex = null) + => LogAsync(LogSeverity.Warning, source, message, ex); + public Task WarningAsync(string source, Exception ex) + => LogAsync(LogSeverity.Warning, source, ex); + Task ILogger.WarningAsync(string message, Exception ex) + => LogAsync(LogSeverity.Warning, "Discord", message, ex); + Task ILogger.WarningAsync(FormattableString message, Exception ex) + => LogAsync(LogSeverity.Warning, "Discord", message, ex); + Task ILogger.WarningAsync(Exception ex) + => LogAsync(LogSeverity.Warning, "Discord", ex); - public Task Info(string source, string message, Exception ex = null) - => Log(LogSeverity.Info, source, message, ex); - public Task Info(string source, FormattableString message, Exception ex = null) - => Log(LogSeverity.Info, source, message, ex); - public Task Info(string source, Exception ex) - => Log(LogSeverity.Info, source, ex); - Task ILogger.Info(string message, Exception ex) - => Log(LogSeverity.Info, "Discord", message, ex); - Task ILogger.Info(FormattableString message, Exception ex) - => Log(LogSeverity.Info, "Discord", message, ex); - Task ILogger.Info(Exception ex) - => Log(LogSeverity.Info, "Discord", ex); + public Task InfoAsync(string source, string message, Exception ex = null) + => LogAsync(LogSeverity.Info, source, message, ex); + public Task InfoAsync(string source, FormattableString message, Exception ex = null) + => LogAsync(LogSeverity.Info, source, message, ex); + public Task InfoAsync(string source, Exception ex) + => LogAsync(LogSeverity.Info, source, ex); + Task ILogger.InfoAsync(string message, Exception ex) + => LogAsync(LogSeverity.Info, "Discord", message, ex); + Task ILogger.InfoAsync(FormattableString message, Exception ex) + => LogAsync(LogSeverity.Info, "Discord", message, ex); + Task ILogger.InfoAsync(Exception ex) + => LogAsync(LogSeverity.Info, "Discord", ex); - public Task Verbose(string source, string message, Exception ex = null) - => Log(LogSeverity.Verbose, source, message, ex); - public Task Verbose(string source, FormattableString message, Exception ex = null) - => Log(LogSeverity.Verbose, source, message, ex); - public Task Verbose(string source, Exception ex) - => Log(LogSeverity.Verbose, source, ex); - Task ILogger.Verbose(string message, Exception ex) - => Log(LogSeverity.Verbose, "Discord", message, ex); - Task ILogger.Verbose(FormattableString message, Exception ex) - => Log(LogSeverity.Verbose, "Discord", message, ex); - Task ILogger.Verbose(Exception ex) - => Log(LogSeverity.Verbose, "Discord", ex); + public Task VerboseAsync(string source, string message, Exception ex = null) + => LogAsync(LogSeverity.Verbose, source, message, ex); + public Task VerboseAsync(string source, FormattableString message, Exception ex = null) + => LogAsync(LogSeverity.Verbose, source, message, ex); + public Task VerboseAsync(string source, Exception ex) + => LogAsync(LogSeverity.Verbose, source, ex); + Task ILogger.VerboseAsync(string message, Exception ex) + => LogAsync(LogSeverity.Verbose, "Discord", message, ex); + Task ILogger.VerboseAsync(FormattableString message, Exception ex) + => LogAsync(LogSeverity.Verbose, "Discord", message, ex); + Task ILogger.VerboseAsync(Exception ex) + => LogAsync(LogSeverity.Verbose, "Discord", ex); - public Task Debug(string source, string message, Exception ex = null) - => Log(LogSeverity.Debug, source, message, ex); - public Task Debug(string source, FormattableString message, Exception ex = null) - => Log(LogSeverity.Debug, source, message, ex); - public Task Debug(string source, Exception ex) - => Log(LogSeverity.Debug, source, ex); - Task ILogger.Debug(string message, Exception ex) - => Log(LogSeverity.Debug, "Discord", message, ex); - Task ILogger.Debug(FormattableString message, Exception ex) - => Log(LogSeverity.Debug, "Discord", message, ex); - Task ILogger.Debug(Exception ex) - => Log(LogSeverity.Debug, "Discord", ex); + public Task DebugAsync(string source, string message, Exception ex = null) + => LogAsync(LogSeverity.Debug, source, message, ex); + public Task DebugAsync(string source, FormattableString message, Exception ex = null) + => LogAsync(LogSeverity.Debug, source, message, ex); + public Task DebugAsync(string source, Exception ex) + => LogAsync(LogSeverity.Debug, source, ex); + Task ILogger.DebugAsync(string message, Exception ex) + => LogAsync(LogSeverity.Debug, "Discord", message, ex); + Task ILogger.DebugAsync(FormattableString message, Exception ex) + => LogAsync(LogSeverity.Debug, "Discord", message, ex); + Task ILogger.DebugAsync(Exception ex) + => LogAsync(LogSeverity.Debug, "Discord", ex); public Logger CreateLogger(string name) => new Logger(this, name); } diff --git a/src/Discord.Net/Logging/Logger.cs b/src/Discord.Net/Logging/Logger.cs index 759917488..36897ea44 100644 --- a/src/Discord.Net/Logging/Logger.cs +++ b/src/Discord.Net/Logging/Logger.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; namespace Discord.Logging { - internal class Logger + internal class Logger : ILogger { private readonly LogManager _manager; @@ -16,44 +16,44 @@ namespace Discord.Logging Name = name; } - public Task Log(LogSeverity severity, string message, Exception exception = null) - => _manager.Log(severity, Name, message, exception); - public Task Log(LogSeverity severity, FormattableString message, Exception exception = null) - => _manager.Log(severity, Name, message, exception); - - public Task Error(string message, Exception exception = null) - => _manager.Error(Name, message, exception); - public Task Error(FormattableString message, Exception exception = null) - => _manager.Error(Name, message, exception); - public Task Error(Exception exception) - => _manager.Error(Name, exception); - - public Task Warning(string message, Exception exception = null) - => _manager.Warning(Name, message, exception); - public Task Warning(FormattableString message, Exception exception = null) - => _manager.Warning(Name, message, exception); - public Task Warning(Exception exception) - => _manager.Warning(Name, exception); - - public Task Info(string message, Exception exception = null) - => _manager.Info(Name, message, exception); - public Task Info(FormattableString message, Exception exception = null) - => _manager.Info(Name, message, exception); - public Task Info(Exception exception) - => _manager.Info(Name, exception); - - public Task Verbose(string message, Exception exception = null) - => _manager.Verbose(Name, message, exception); - public Task Verbose(FormattableString message, Exception exception = null) - => _manager.Verbose(Name, message, exception); - public Task Verbose(Exception exception) - => _manager.Verbose(Name, exception); - - public Task Debug(string message, Exception exception = null) - => _manager.Debug(Name, message, exception); - public Task Debug(FormattableString message, Exception exception = null) - => _manager.Debug(Name, message, exception); - public Task Debug(Exception exception) - => _manager.Debug(Name, exception); + public Task LogAsync(LogSeverity severity, string message, Exception exception = null) + => _manager.LogAsync(severity, Name, message, exception); + public Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null) + => _manager.LogAsync(severity, Name, message, exception); + + public Task ErrorAsync(string message, Exception exception = null) + => _manager.ErrorAsync(Name, message, exception); + public Task ErrorAsync(FormattableString message, Exception exception = null) + => _manager.ErrorAsync(Name, message, exception); + public Task ErrorAsync(Exception exception) + => _manager.ErrorAsync(Name, exception); + + public Task WarningAsync(string message, Exception exception = null) + => _manager.WarningAsync(Name, message, exception); + public Task WarningAsync(FormattableString message, Exception exception = null) + => _manager.WarningAsync(Name, message, exception); + public Task WarningAsync(Exception exception) + => _manager.WarningAsync(Name, exception); + + public Task InfoAsync(string message, Exception exception = null) + => _manager.InfoAsync(Name, message, exception); + public Task InfoAsync(FormattableString message, Exception exception = null) + => _manager.InfoAsync(Name, message, exception); + public Task InfoAsync(Exception exception) + => _manager.InfoAsync(Name, exception); + + public Task VerboseAsync(string message, Exception exception = null) + => _manager.VerboseAsync(Name, message, exception); + public Task VerboseAsync(FormattableString message, Exception exception = null) + => _manager.VerboseAsync(Name, message, exception); + public Task VerboseAsync(Exception exception) + => _manager.VerboseAsync(Name, exception); + + public Task DebugAsync(string message, Exception exception = null) + => _manager.DebugAsync(Name, message, exception); + public Task DebugAsync(FormattableString message, Exception exception = null) + => _manager.DebugAsync(Name, message, exception); + public Task DebugAsync(Exception exception) + => _manager.DebugAsync(Name, exception); } } diff --git a/src/Discord.Net/Net/Queue/IQueuedRequest.cs b/src/Discord.Net/Net/Queue/IQueuedRequest.cs index 099e0e7ed..ad0c8fcb6 100644 --- a/src/Discord.Net/Net/Queue/IQueuedRequest.cs +++ b/src/Discord.Net/Net/Queue/IQueuedRequest.cs @@ -11,6 +11,6 @@ namespace Discord.Net.Queue CancellationToken CancelToken { get; } int? TimeoutTick { get; } - Task Send(); + Task SendAsync(); } } diff --git a/src/Discord.Net/Net/Queue/RequestQueue.cs b/src/Discord.Net/Net/Queue/RequestQueue.cs index adf54af9c..631f5b457 100644 --- a/src/Discord.Net/Net/Queue/RequestQueue.cs +++ b/src/Discord.Net/Net/Queue/RequestQueue.cs @@ -61,7 +61,7 @@ namespace Discord.Net.Queue _cancelToken = CancellationToken.None; _parentToken = CancellationToken.None; } - public async Task SetCancelToken(CancellationToken cancelToken) + public async Task SetCancelTokenAsync(CancellationToken cancelToken) { await _lock.WaitAsync().ConfigureAwait(false); try @@ -72,17 +72,17 @@ namespace Discord.Net.Queue finally { _lock.Release(); } } - internal async Task Send(RestRequest request, BucketGroup group, int bucketId, ulong guildId) + internal async Task SendAsync(RestRequest request, BucketGroup group, int bucketId, ulong guildId) { request.CancelToken = _cancelToken; var bucket = GetBucket(group, bucketId, guildId); - return await bucket.Send(request).ConfigureAwait(false); + return await bucket.SendAsync(request).ConfigureAwait(false); } - internal async Task Send(WebSocketRequest request, BucketGroup group, int bucketId, ulong guildId) + internal async Task SendAsync(WebSocketRequest request, BucketGroup group, int bucketId, ulong guildId) { request.CancelToken = _cancelToken; var bucket = GetBucket(group, bucketId, guildId); - return await bucket.Send(request).ConfigureAwait(false); + return await bucket.SendAsync(request).ConfigureAwait(false); } private RequestQueueBucket CreateBucket(BucketDefinition def) @@ -119,7 +119,7 @@ namespace Discord.Net.Queue return _guildBuckets[(int)type].GetOrAdd(guildId, _ => CreateBucket(_guildLimits[type])); } - public async Task Clear() + public async Task ClearAsync() { await _lock.WaitAsync().ConfigureAwait(false); try diff --git a/src/Discord.Net/Net/Queue/RequestQueueBucket.cs b/src/Discord.Net/Net/Queue/RequestQueueBucket.cs index 6fc60d9ea..bfc7e2bb2 100644 --- a/src/Discord.Net/Net/Queue/RequestQueueBucket.cs +++ b/src/Discord.Net/Net/Queue/RequestQueueBucket.cs @@ -28,13 +28,13 @@ namespace Discord.Net.Queue Parent = parent; } - public async Task Send(IQueuedRequest request) + public async Task SendAsync(IQueuedRequest request) { var endTick = request.TimeoutTick; //Wait until a spot is open in our bucket if (_semaphore != null) - await Enter(endTick).ConfigureAwait(false); + await EnterAsync(endTick).ConfigureAwait(false); try { while (true) @@ -63,10 +63,10 @@ namespace Discord.Net.Queue { //If there's a parent bucket, pass this request to them if (Parent != null) - return await Parent.Send(request).ConfigureAwait(false); + return await Parent.SendAsync(request).ConfigureAwait(false); //We have all our semaphores, send the request - return await request.Send().ConfigureAwait(false); + return await request.SendAsync().ConfigureAwait(false); } catch (HttpRateLimitException ex) { @@ -79,7 +79,7 @@ namespace Discord.Net.Queue { //Make sure we put this entry back after WindowMilliseconds if (_semaphore != null) - QueueExit(); + QueueExitAsync(); } } @@ -92,17 +92,17 @@ namespace Discord.Net.Queue { _resumeNotifier = new TaskCompletionSource(); _pauseEndTick = unchecked(Environment.TickCount + milliseconds); - QueueResume(milliseconds); + QueueResumeAsync(milliseconds); } } } - private async Task QueueResume(int millis) + private async Task QueueResumeAsync(int millis) { await Task.Delay(millis).ConfigureAwait(false); _resumeNotifier.SetResult(0); } - private async Task Enter(int? endTick) + private async Task EnterAsync(int? endTick) { if (endTick.HasValue) { @@ -113,7 +113,7 @@ namespace Discord.Net.Queue else await _semaphore.WaitAsync().ConfigureAwait(false); } - private async Task QueueExit() + private async Task QueueExitAsync() { await Task.Delay(_windowMilliseconds).ConfigureAwait(false); _semaphore.Release(); diff --git a/src/Discord.Net/Net/Queue/RestRequest.cs b/src/Discord.Net/Net/Queue/RestRequest.cs index 778a03be3..aa63eacb5 100644 --- a/src/Discord.Net/Net/Queue/RestRequest.cs +++ b/src/Discord.Net/Net/Queue/RestRequest.cs @@ -47,14 +47,14 @@ namespace Discord.Net.Queue Promise = new TaskCompletionSource(); } - public async Task Send() + public async Task SendAsync() { if (IsMultipart) - return await Client.Send(Method, Endpoint, MultipartParams, HeaderOnly).ConfigureAwait(false); + return await Client.SendAsync(Method, Endpoint, MultipartParams, HeaderOnly).ConfigureAwait(false); else if (Json != null) - return await Client.Send(Method, Endpoint, Json, HeaderOnly).ConfigureAwait(false); + return await Client.SendAsync(Method, Endpoint, Json, HeaderOnly).ConfigureAwait(false); else - return await Client.Send(Method, Endpoint, HeaderOnly).ConfigureAwait(false); + return await Client.SendAsync(Method, Endpoint, HeaderOnly).ConfigureAwait(false); } } } diff --git a/src/Discord.Net/Net/Queue/WebSocketRequest.cs b/src/Discord.Net/Net/Queue/WebSocketRequest.cs index 003bf731f..1a841b603 100644 --- a/src/Discord.Net/Net/Queue/WebSocketRequest.cs +++ b/src/Discord.Net/Net/Queue/WebSocketRequest.cs @@ -32,9 +32,9 @@ namespace Discord.Net.Queue Promise = new TaskCompletionSource(); } - public async Task Send() + public async Task SendAsync() { - await Client.Send(Data, DataIndex, DataCount, IsText).ConfigureAwait(false); + await Client.SendAsync(Data, DataIndex, DataCount, IsText).ConfigureAwait(false); return null; } } diff --git a/src/Discord.Net/Net/Rest/DefaultRestClient.cs b/src/Discord.Net/Net/Rest/DefaultRestClient.cs index f870cf61e..c51c5fa0a 100644 --- a/src/Discord.Net/Net/Rest/DefaultRestClient.cs +++ b/src/Discord.Net/Net/Rest/DefaultRestClient.cs @@ -67,22 +67,22 @@ namespace Discord.Net.Rest _cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token; } - public async Task Send(string method, string endpoint, bool headerOnly = false) + public async Task SendAsync(string method, string endpoint, bool headerOnly = false) { string uri = Path.Combine(_baseUrl, endpoint); using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) - return await SendInternal(restRequest, headerOnly).ConfigureAwait(false); + return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); } - public async Task Send(string method, string endpoint, string json, bool headerOnly = false) + public async Task SendAsync(string method, string endpoint, string json, bool headerOnly = false) { string uri = Path.Combine(_baseUrl, endpoint); using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) { restRequest.Content = new StringContent(json, Encoding.UTF8, "application/json"); - return await SendInternal(restRequest, headerOnly).ConfigureAwait(false); + return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); } } - public async Task Send(string method, string endpoint, IReadOnlyDictionary multipartParams, bool headerOnly = false) + public async Task SendAsync(string method, string endpoint, IReadOnlyDictionary multipartParams, bool headerOnly = false) { string uri = Path.Combine(_baseUrl, endpoint); using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) @@ -110,11 +110,11 @@ namespace Discord.Net.Rest } } restRequest.Content = content; - return await SendInternal(restRequest, headerOnly).ConfigureAwait(false); + return await SendInternalAsync(restRequest, headerOnly).ConfigureAwait(false); } } - private async Task SendInternal(HttpRequestMessage request, bool headerOnly) + private async Task SendInternalAsync(HttpRequestMessage request, bool headerOnly) { while (true) { diff --git a/src/Discord.Net/Net/Rest/IRestClient.cs b/src/Discord.Net/Net/Rest/IRestClient.cs index 25b577688..57b5f91ca 100644 --- a/src/Discord.Net/Net/Rest/IRestClient.cs +++ b/src/Discord.Net/Net/Rest/IRestClient.cs @@ -11,8 +11,8 @@ namespace Discord.Net.Rest void SetHeader(string key, string value); void SetCancelToken(CancellationToken cancelToken); - Task Send(string method, string endpoint, bool headerOnly = false); - Task Send(string method, string endpoint, string json, bool headerOnly = false); - Task Send(string method, string endpoint, IReadOnlyDictionary multipartParams, bool headerOnly = false); + Task SendAsync(string method, string endpoint, bool headerOnly = false); + Task SendAsync(string method, string endpoint, string json, bool headerOnly = false); + Task SendAsync(string method, string endpoint, IReadOnlyDictionary multipartParams, bool headerOnly = false); } } diff --git a/src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs b/src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs index 545a92d37..eea88605d 100644 --- a/src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs +++ b/src/Discord.Net/Net/WebSockets/DefaultWebsocketClient.cs @@ -50,18 +50,18 @@ namespace Discord.Net.WebSockets Dispose(true); } - public async Task Connect(string host) + public async Task ConnectAsync(string host) { //Assume locked - await Disconnect().ConfigureAwait(false); + await DisconnectAsync().ConfigureAwait(false); _cancelTokenSource = new CancellationTokenSource(); _cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token; await _client.ConnectAsync(new Uri(host), _cancelToken).ConfigureAwait(false); - _task = Run(_cancelToken); + _task = RunAsync(_cancelToken); } - public async Task Disconnect() + public async Task DisconnectAsync() { //Assume locked _cancelTokenSource.Cancel(); @@ -82,7 +82,7 @@ namespace Discord.Net.WebSockets _cancelToken = CancellationTokenSource.CreateLinkedTokenSource(_parentToken, _cancelTokenSource.Token).Token; } - public async Task Send(byte[] data, int index, int count, bool isText) + public async Task SendAsync(byte[] data, int index, int count, bool isText) { await _sendLock.WaitAsync(_cancelToken); try @@ -118,7 +118,7 @@ namespace Discord.Net.WebSockets } //TODO: Check this code - private async Task Run(CancellationToken cancelToken) + private async Task RunAsync(CancellationToken cancelToken) { var buffer = new ArraySegment(new byte[ReceiveChunkSize]); var stream = new MemoryStream(); @@ -151,11 +151,11 @@ namespace Discord.Net.WebSockets var array = stream.ToArray(); if (result.MessageType == WebSocketMessageType.Binary) - await BinaryMessage.Raise(array, 0, array.Length).ConfigureAwait(false); + await BinaryMessage.RaiseAsync(array, 0, array.Length).ConfigureAwait(false); else if (result.MessageType == WebSocketMessageType.Text) { string text = Encoding.UTF8.GetString(array, 0, array.Length); - await TextMessage.Raise(text).ConfigureAwait(false); + await TextMessage.RaiseAsync(text).ConfigureAwait(false); } stream.Position = 0; diff --git a/src/Discord.Net/Net/WebSockets/IWebSocketClient.cs b/src/Discord.Net/Net/WebSockets/IWebSocketClient.cs index 2925c1350..583aaa06d 100644 --- a/src/Discord.Net/Net/WebSockets/IWebSocketClient.cs +++ b/src/Discord.Net/Net/WebSockets/IWebSocketClient.cs @@ -12,9 +12,9 @@ namespace Discord.Net.WebSockets void SetHeader(string key, string value); void SetCancelToken(CancellationToken cancelToken); - Task Connect(string host); - Task Disconnect(); + Task ConnectAsync(string host); + Task DisconnectAsync(); - Task Send(byte[] data, int index, int count, bool isText); + Task SendAsync(byte[] data, int index, int count, bool isText); } } diff --git a/src/Discord.Net/Utilities/MessageCache.cs b/src/Discord.Net/Utilities/MessageCache.cs index 991dde11f..6fd12aa4e 100644 --- a/src/Discord.Net/Utilities/MessageCache.cs +++ b/src/Discord.Net/Utilities/MessageCache.cs @@ -81,17 +81,17 @@ namespace Discord .ToImmutableArray(); } - public async Task Download(ulong id) + public async Task DownloadAsync(ulong id) { var msg = Get(id); if (msg != null) return msg; - var model = await _discord.ApiClient.GetChannelMessage(_channel.Id, id).ConfigureAwait(false); + var model = await _discord.ApiClient.GetChannelMessageAsync(_channel.Id, id).ConfigureAwait(false); if (model != null) return new CachedMessage(_channel, new User(_discord, model.Author), model); return null; } - public async Task> Download(ulong? fromId, Direction dir, int limit) + public async Task> DownloadAsync(ulong? fromId, Direction dir, int limit) { //TODO: Test heavily, especially the ordering of messages if (limit < 0) throw new ArgumentOutOfRangeException(nameof(limit)); @@ -110,7 +110,7 @@ namespace Discord RelativeDirection = dir, RelativeMessageId = dir == Direction.Before ? cachedMessages[0].Id : cachedMessages[cachedMessages.Count - 1].Id }; - var downloadedMessages = await _discord.ApiClient.GetChannelMessages(_channel.Id, args).ConfigureAwait(false); + var downloadedMessages = await _discord.ApiClient.GetChannelMessagesAsync(_channel.Id, args).ConfigureAwait(false); return cachedMessages.Concat(downloadedMessages.Select(x => new CachedMessage(_channel, _channel.GetCachedUser(x.Id), x))).ToImmutableArray(); } }