From 5c33e2875714918349d9cec28d3210dab97abc15 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sat, 8 Oct 2016 16:59:17 -0300 Subject: [PATCH] Added missing ConfigureAwaits --- src/Discord.Net.Commands/CommandService.cs | 6 ++-- .../API/DiscordRestApiClient.cs | 2 +- .../Net/Queue/RequestQueueBucket.cs | 2 +- .../Net/WebSockets/DefaultWebSocketClient.cs | 4 +-- .../Utils/Paging/PagedEnumerator.cs | 2 +- src/Discord.Net.Rest/DiscordRestClient.cs | 4 +-- .../Entities/Channels/ChannelHelper.cs | 18 +++++----- .../Entities/Channels/RestDMChannel.cs | 12 +++---- .../Entities/Channels/RestGroupChannel.cs | 12 +++---- .../Entities/Channels/RestGuildChannel.cs | 20 +++++------ .../Entities/Channels/RestTextChannel.cs | 14 ++++---- .../Entities/Channels/RestVoiceChannel.cs | 2 +- .../Entities/Guilds/GuildHelper.cs | 6 ++-- .../Entities/Guilds/RestGuild.cs | 34 +++++++++---------- .../Entities/Invites/RestInvite.cs | 2 +- .../Entities/Messages/MessageHelper.cs | 8 ++--- .../Entities/Messages/RestUserMessage.cs | 2 +- .../Entities/Roles/RestRole.cs | 2 +- .../Entities/Roles/RoleHelper.cs | 2 +- .../Entities/Users/RestGuildUser.cs | 4 +-- .../Entities/Users/RestSelfUser.cs | 4 +-- .../Entities/Users/RestUser.cs | 4 +-- .../Entities/Users/UserHelper.cs | 8 ++--- src/Discord.Net.Rest/Utils/TypingNotifier.cs | 4 +-- src/Discord.Net.Rpc/DiscordRpcClient.cs | 14 ++++---- .../Entities/Channels/RpcDMChannel.cs | 12 +++---- .../Entities/Channels/RpcGroupChannel.cs | 12 +++---- .../Entities/Channels/RpcGuildChannel.cs | 8 ++--- .../Entities/Channels/RpcTextChannel.cs | 10 +++--- src/Discord.Net.Rpc/Entities/Users/RpcUser.cs | 2 +- .../API/DiscordVoiceApiClient.cs | 8 ++--- .../Audio/AudioClient.cs | 2 +- .../DiscordSocketClient.cs | 14 ++++---- .../Entities/Channels/SocketDMChannel.cs | 10 +++--- .../Entities/Channels/SocketGroupChannel.cs | 10 +++--- .../Entities/Channels/SocketGuildChannel.cs | 16 ++++----- .../Entities/Channels/SocketTextChannel.cs | 10 +++--- .../Entities/Guilds/SocketGuild.cs | 20 +++++------ .../Entities/Users/SocketSelfUser.cs | 4 +-- .../Entities/Users/SocketUser.cs | 2 +- 40 files changed, 166 insertions(+), 166 deletions(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 9b77b65e6..509237310 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -201,7 +201,7 @@ namespace Discord.Commands var commands = searchResult.Commands; for (int i = commands.Count - 1; i >= 0; i--) { - var preconditionResult = await commands[i].CheckPreconditions(context); + var preconditionResult = await commands[i].CheckPreconditions(context).ConfigureAwait(false); if (!preconditionResult.IsSuccess) { if (commands.Count == 1) @@ -210,7 +210,7 @@ namespace Discord.Commands continue; } - var parseResult = await commands[i].Parse(context, searchResult, preconditionResult); + var parseResult = await commands[i].Parse(context, searchResult, preconditionResult).ConfigureAwait(false); if (!parseResult.IsSuccess) { if (parseResult.Error == CommandError.MultipleMatches) @@ -235,7 +235,7 @@ namespace Discord.Commands } } - return await commands[i].Execute(context, parseResult); + return await commands[i].Execute(context, parseResult).ConfigureAwait(false); } return SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."); diff --git a/src/Discord.Net.Core/API/DiscordRestApiClient.cs b/src/Discord.Net.Core/API/DiscordRestApiClient.cs index da3d689d5..baa0698d8 100644 --- a/src/Discord.Net.Core/API/DiscordRestApiClient.cs +++ b/src/Discord.Net.Core/API/DiscordRestApiClient.cs @@ -116,7 +116,7 @@ namespace Discord.API _restClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, _authToken)); if (FetchCurrentUser) - CurrentUser = await GetMyUserAsync(new RequestOptions { IgnoreState = true }); + CurrentUser = await GetMyUserAsync(new RequestOptions { IgnoreState = true }).ConfigureAwait(false); LoginState = LoginState.LoggedIn; } diff --git a/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs b/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs index 00668c315..a94d0f05e 100644 --- a/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs +++ b/src/Discord.Net.Core/Net/Queue/RequestQueueBucket.cs @@ -130,7 +130,7 @@ namespace Discord.Net.Queue if (millis <= 0 || !await _semaphore.WaitAsync(millis).ConfigureAwait(false)) throw new TimeoutException(); - if (!await _semaphore.WaitAsync(0)) + if (!await _semaphore.WaitAsync(0).ConfigureAwait(false)) { await _queue.RaiseRateLimitTriggered(Id, this, null).ConfigureAwait(false); diff --git a/src/Discord.Net.Core/Net/WebSockets/DefaultWebSocketClient.cs b/src/Discord.Net.Core/Net/WebSockets/DefaultWebSocketClient.cs index 2e4a90ad8..540e6f3b9 100644 --- a/src/Discord.Net.Core/Net/WebSockets/DefaultWebSocketClient.cs +++ b/src/Discord.Net.Core/Net/WebSockets/DefaultWebSocketClient.cs @@ -54,7 +54,7 @@ namespace Discord.Net.WebSockets await _sendLock.WaitAsync().ConfigureAwait(false); try { - await ConnectInternalAsync(host); + await ConnectInternalAsync(host).ConfigureAwait(false); } finally { @@ -86,7 +86,7 @@ namespace Discord.Net.WebSockets await _sendLock.WaitAsync().ConfigureAwait(false); try { - await DisconnectInternalAsync(); + await DisconnectInternalAsync().ConfigureAwait(false); } finally { diff --git a/src/Discord.Net.Core/Utils/Paging/PagedEnumerator.cs b/src/Discord.Net.Core/Utils/Paging/PagedEnumerator.cs index e4572e653..730f9517a 100644 --- a/src/Discord.Net.Core/Utils/Paging/PagedEnumerator.cs +++ b/src/Discord.Net.Core/Utils/Paging/PagedEnumerator.cs @@ -45,7 +45,7 @@ namespace Discord if (_info.Remaining == 0) return false; - var data = await _source._getPage(_info, cancelToken); + var data = await _source._getPage(_info, cancelToken).ConfigureAwait(false); Current = new Page(_info, data); _info.Page++; diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 2e9ff861c..f36c0fb06 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -78,14 +78,14 @@ namespace Discord.Rest async Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) { if (mode == CacheMode.AllowDownload) - return await GetChannelAsync(id); + return await GetChannelAsync(id).ConfigureAwait(false); else return null; } async Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) { if (mode == CacheMode.AllowDownload) - return await GetPrivateChannelsAsync(); + return await GetPrivateChannelsAsync().ConfigureAwait(false); else return ImmutableArray.Create(); } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index ea91d3002..b8843802a 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -23,7 +23,7 @@ namespace Discord.Rest { var args = new ModifyGuildChannelParams(); func(args); - return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); + return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options).ConfigureAwait(false); } public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, Action func, @@ -31,7 +31,7 @@ namespace Discord.Rest { var args = new ModifyTextChannelParams(); func(args); - return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); + return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options).ConfigureAwait(false); } public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, Action func, @@ -39,14 +39,14 @@ namespace Discord.Rest { var args = new ModifyVoiceChannelParams(); func(args); - return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); + return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options).ConfigureAwait(false); } //Invites public static async Task> GetInvitesAsync(IChannel channel, BaseDiscordClient client, RequestOptions options) { - var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id, options); + var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id, options).ConfigureAwait(false); return models.Select(x => RestInviteMetadata.Create(client, x)).ToImmutableArray(); } public static async Task CreateInviteAsync(IChannel channel, BaseDiscordClient client, @@ -57,7 +57,7 @@ namespace Discord.Rest args.MaxAge = maxAge.Value; if (maxUses.HasValue) args.MaxUses = maxUses.Value; - var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options); + var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false); return RestInviteMetadata.Create(client, model); } @@ -83,7 +83,7 @@ namespace Discord.Rest }; if (info.Position != null) args.RelativeMessageId = info.Position.Value; - var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args, options); + var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args, options).ConfigureAwait(false); return models.Select(x => RestMessage.Create(client, guild, x)).ToImmutableArray(); ; }, nextPage: (info, lastPage) => @@ -164,7 +164,7 @@ namespace Discord.Rest public static async Task GetUserAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) { - var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id, options); + var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id, options).ConfigureAwait(false); if (model == null) return null; var user = RestGuildUser.Create(client, guild, model); @@ -186,7 +186,7 @@ namespace Discord.Rest }; if (info.Position != null) args.AfterUserId = info.Position.Value; - var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args, options); + var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args, options).ConfigureAwait(false); return models .Select(x => RestGuildUser.Create(client, guild, x)) .Where(x => x.GetPermissions(channel).ReadMessages) @@ -207,7 +207,7 @@ namespace Discord.Rest public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client, RequestOptions options = null) { - await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options); + await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options).ConfigureAwait(false); } public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client, RequestOptions options) diff --git a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs index 355bd656c..fa3dae82b 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs @@ -36,7 +36,7 @@ namespace Discord.Rest public override async Task UpdateAsync(RequestOptions options = null) { - var model = await Discord.ApiClient.GetChannelAsync(Id, options); + var model = await Discord.ApiClient.GetChannelAsync(Id, options).ConfigureAwait(false); Update(model); } public Task CloseAsync(RequestOptions options = null) @@ -94,7 +94,7 @@ namespace Discord.Rest async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return null; } @@ -120,14 +120,14 @@ namespace Discord.Rest return AsyncEnumerable.Empty>(); } async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) - => await GetPinnedMessagesAsync(options); + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs index 9aeb99447..0868568cd 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs @@ -51,7 +51,7 @@ namespace Discord.Rest public override async Task UpdateAsync(RequestOptions options = null) { - var model = await Discord.ApiClient.GetChannelAsync(Id, options); + var model = await Discord.ApiClient.GetChannelAsync(Id, options).ConfigureAwait(false); Update(model); } public Task LeaveAsync(RequestOptions options = null) @@ -104,7 +104,7 @@ namespace Discord.Rest async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return null; } @@ -130,14 +130,14 @@ namespace Discord.Rest return AsyncEnumerable.Empty>(); } async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) - => await GetPinnedMessagesAsync(options); + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index cacc6d238..63e2ec509 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -51,12 +51,12 @@ namespace Discord.Rest public override async Task UpdateAsync(RequestOptions options = null) { - var model = await Discord.ApiClient.GetChannelAsync(GuildId, Id, options); + var model = await Discord.ApiClient.GetChannelAsync(GuildId, Id, options).ConfigureAwait(false); Update(model); } public async Task ModifyAsync(Action func, RequestOptions options = null) { - var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); + var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } public Task DeleteAsync(RequestOptions options = null) @@ -118,30 +118,30 @@ namespace Discord.Rest } public async Task> GetInvitesAsync(RequestOptions options = null) - => await ChannelHelper.GetInvitesAsync(this, Discord, options); + => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); public async Task CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null) - => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options); + => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options).ConfigureAwait(false); public override string ToString() => Name; //IGuildChannel async Task> IGuildChannel.GetInvitesAsync(RequestOptions options) - => await GetInvitesAsync(options); + => await GetInvitesAsync(options).ConfigureAwait(false); async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options) - => await CreateInviteAsync(maxAge, maxUses, isTemporary, options); + => await CreateInviteAsync(maxAge, maxUses, isTemporary, options).ConfigureAwait(false); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) => GetPermissionOverwrite(role); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) => GetPermissionOverwrite(user); async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(role, permissions, options); + => await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false); async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(user, permissions, options); + => await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false); async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) - => await RemovePermissionOverwriteAsync(role, options); + => await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false); async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) - => await RemovePermissionOverwriteAsync(user, options); + => await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false); IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overriden //Overriden in Text/Voice //TODO: Does this actually override? diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index 4bff8f40f..d8fc6637a 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -35,7 +35,7 @@ namespace Discord.Rest public async Task ModifyAsync(Action func, RequestOptions options = null) { - var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); + var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } @@ -76,7 +76,7 @@ namespace Discord.Rest async Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetUserAsync(id, options); + return await GetUserAsync(id, options).ConfigureAwait(false); else return null; } @@ -92,7 +92,7 @@ namespace Discord.Rest async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return null; } @@ -118,14 +118,14 @@ namespace Discord.Rest return AsyncEnumerable.Empty>(); } async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) - => await GetPinnedMessagesAsync(options); + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs index 9b0e2e21b..a19a5cb38 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs @@ -35,7 +35,7 @@ namespace Discord.Rest public async Task ModifyAsync(Action func, RequestOptions options = null) { - var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); + var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 966914960..a27475e3c 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -62,7 +62,7 @@ namespace Discord.Rest public static async Task> GetBansAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { - var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options); + var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestBan.Create(client, x)).ToImmutableArray(); } @@ -70,12 +70,12 @@ namespace Discord.Rest ulong userId, int pruneDays, RequestOptions options) { var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays }; - await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options); + await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options).ConfigureAwait(false); } public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options) { - await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options); + await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); } //Channels diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 4a01a53d2..7b68260de 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -100,18 +100,18 @@ namespace Discord.Rest //General public async Task UpdateAsync(RequestOptions options = null) - => Update(await Discord.ApiClient.GetGuildAsync(Id, options)); + => Update(await Discord.ApiClient.GetGuildAsync(Id, options).ConfigureAwait(false)); public Task DeleteAsync(RequestOptions options = null) => GuildHelper.DeleteAsync(this, Discord, options); public async Task ModifyAsync(Action func, RequestOptions options = null) { - var model = await GuildHelper.ModifyAsync(this, Discord, func, options); + var model = await GuildHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } public async Task ModifyEmbedAsync(Action func, RequestOptions options = null) { - var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options); + var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } public async Task ModifyChannelsAsync(IEnumerable args, RequestOptions options = null) @@ -121,7 +121,7 @@ namespace Discord.Rest } public async Task ModifyRolesAsync(IEnumerable args, RequestOptions options = null) { - var models = await GuildHelper.ModifyRolesAsync(this, Discord, args, options); + var models = await GuildHelper.ModifyRolesAsync(this, Discord, args, options).ConfigureAwait(false); foreach (var model in models) { var role = GetRole(model.Id); @@ -179,7 +179,7 @@ namespace Discord.Rest public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false, RequestOptions options = null) { - var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options); + var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options).ConfigureAwait(false); _roles = _roles.Add(role.Id, role); return role; } @@ -205,58 +205,58 @@ namespace Discord.Rest IReadOnlyCollection IGuild.Roles => Roles; async Task> IGuild.GetBansAsync(RequestOptions options) - => await GetBansAsync(options); + => await GetBansAsync(options).ConfigureAwait(false); async Task> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetChannelsAsync(options); + return await GetChannelsAsync(options).ConfigureAwait(false); else return ImmutableArray.Create(); } async Task IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetChannelAsync(id, options); + return await GetChannelAsync(id, options).ConfigureAwait(false); else return null; } async Task IGuild.CreateTextChannelAsync(string name, RequestOptions options) - => await CreateTextChannelAsync(name, options); + => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) - => await CreateVoiceChannelAsync(name, options); + => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) - => await GetIntegrationsAsync(options); + => await GetIntegrationsAsync(options).ConfigureAwait(false); async Task IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options) - => await CreateIntegrationAsync(id, type, options); + => await CreateIntegrationAsync(id, type, options).ConfigureAwait(false); async Task> IGuild.GetInvitesAsync(RequestOptions options) - => await GetInvitesAsync(options); + => await GetInvitesAsync(options).ConfigureAwait(false); IRole IGuild.GetRole(ulong id) => GetRole(id); async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) - => await CreateRoleAsync(name, permissions, color, isHoisted, options); + => await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false); async Task IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetUserAsync(id, options); + return await GetUserAsync(id, options).ConfigureAwait(false); else return null; } async Task IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetCurrentUserAsync(options); + return await GetCurrentUserAsync(options).ConfigureAwait(false); else return null; } async Task> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return (await GetUsersAsync(options).Flatten()).ToImmutableArray(); + return (await GetUsersAsync(options).Flatten().ConfigureAwait(false)).ToImmutableArray(); else return ImmutableArray.Create(); } diff --git a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs index 4c07ea9ac..4c870f3f4 100644 --- a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs +++ b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs @@ -35,7 +35,7 @@ namespace Discord.Rest public async Task UpdateAsync(RequestOptions options = null) { - var model = await Discord.ApiClient.GetInviteAsync(Code, options); + var model = await Discord.ApiClient.GetInviteAsync(Code, options).ConfigureAwait(false); Update(model); } public Task DeleteAsync(RequestOptions options = null) diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 6f4df548d..358f6f5a9 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -15,23 +15,23 @@ namespace Discord.Rest { var args = new ModifyMessageParams(); func(args); - return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, args, options); + return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, args, options).ConfigureAwait(false); } public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) { - await client.ApiClient.DeleteMessageAsync(msg.Channel.Id, msg.Id, options); + await client.ApiClient.DeleteMessageAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); } public static async Task PinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) { - await client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options); + await client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); } public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) { - await client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options); + await client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); } public static ImmutableArray ParseTags(string text, IMessageChannel channel, IGuild guild, ImmutableArray userMentions) diff --git a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs index c7ef91738..21f87c18f 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs @@ -113,7 +113,7 @@ namespace Discord.Rest public async Task ModifyAsync(Action func, RequestOptions options) { - var model = await MessageHelper.ModifyAsync(this, Discord, func, options); + var model = await MessageHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } public Task DeleteAsync(RequestOptions options) diff --git a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs index 7369b9461..16b521b1d 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs @@ -44,7 +44,7 @@ namespace Discord.Rest public async Task ModifyAsync(Action func, RequestOptions options = null) { - var model = await RoleHelper.ModifyAsync(this, Discord, func, options); + var model = await RoleHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } public Task DeleteAsync(RequestOptions options = null) diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index fbd73894a..0b102098c 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -18,7 +18,7 @@ namespace Discord.Rest { var args = new ModifyGuildRoleParams(); func(args); - return await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options); + return await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options).ConfigureAwait(false); } } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs index c24d03703..6d1cac024 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs @@ -64,12 +64,12 @@ namespace Discord.Rest public override async Task UpdateAsync(RequestOptions options = null) { - var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options); + var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options).ConfigureAwait(false); Update(model); } public async Task ModifyAsync(Action func, RequestOptions options = null) { - var args = await UserHelper.ModifyAsync(this, Discord, func, options); + var args = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); if (args.Deaf.IsSpecified) IsDeafened = args.Deaf.Value; if (args.Mute.IsSpecified) diff --git a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs index a8150b5e9..368d8c798 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs @@ -37,7 +37,7 @@ namespace Discord.Rest public override async Task UpdateAsync(RequestOptions options = null) { - var model = await Discord.ApiClient.GetMyUserAsync(options); + var model = await Discord.ApiClient.GetMyUserAsync(options).ConfigureAwait(false); if (model.Id != Id) throw new InvalidOperationException("Unable to update this object using a different token."); Update(model); @@ -47,7 +47,7 @@ namespace Discord.Rest { if (Id != Discord.CurrentUser.Id) throw new InvalidOperationException("Unable to modify this object using a different token."); - var model = await UserHelper.ModifyAsync(this, Discord, func, options); + var model = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs index 5e085b821..681be24c4 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs @@ -42,7 +42,7 @@ namespace Discord.Rest public virtual async Task UpdateAsync(RequestOptions options = null) { - var model = await Discord.ApiClient.GetUserAsync(Id, options); + var model = await Discord.ApiClient.GetUserAsync(Id, options).ConfigureAwait(false); Update(model); } @@ -56,6 +56,6 @@ namespace Discord.Rest Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(null); async Task IUser.CreateDMChannelAsync(RequestOptions options) - => await CreateDMChannelAsync(options); + => await CreateDMChannelAsync(options).ConfigureAwait(false); } } diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs index d86477520..545703f0d 100644 --- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs +++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs @@ -12,28 +12,28 @@ namespace Discord.Rest { var args = new ModifyCurrentUserParams(); func(args); - return await client.ApiClient.ModifySelfAsync(args, options); + return await client.ApiClient.ModifySelfAsync(args, options).ConfigureAwait(false); } public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action func, RequestOptions options) { var args = new ModifyGuildMemberParams(); func(args); - await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args, options); + await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args, options).ConfigureAwait(false); return args; } public static async Task KickAsync(IGuildUser user, BaseDiscordClient client, RequestOptions options) { - await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, options); + await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, options).ConfigureAwait(false); } public static async Task CreateDMChannelAsync(IUser user, BaseDiscordClient client, RequestOptions options) { var args = new CreateDMChannelParams(user.Id); - return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options)); + return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options).ConfigureAwait(false)); } } } diff --git a/src/Discord.Net.Rest/Utils/TypingNotifier.cs b/src/Discord.Net.Rest/Utils/TypingNotifier.cs index 433553e00..45b715a76 100644 --- a/src/Discord.Net.Rest/Utils/TypingNotifier.cs +++ b/src/Discord.Net.Rest/Utils/TypingNotifier.cs @@ -29,10 +29,10 @@ namespace Discord.Rest { try { - await _channel.TriggerTypingAsync(_options); + await _channel.TriggerTypingAsync(_options).ConfigureAwait(false); } catch { } - await Task.Delay(9750, token); + await Task.Delay(9750, token).ConfigureAwait(false); } } catch (OperationCanceledException) { } diff --git a/src/Discord.Net.Rpc/DiscordRpcClient.cs b/src/Discord.Net.Rpc/DiscordRpcClient.cs index 56f32255a..d0443d15e 100644 --- a/src/Discord.Net.Rpc/DiscordRpcClient.cs +++ b/src/Discord.Net.Rpc/DiscordRpcClient.cs @@ -103,7 +103,7 @@ namespace Discord.Rpc //Abort connection on timeout var _ = Task.Run(async () => { - await Task.Delay(ConnectionTimeout); + await Task.Delay(ConnectionTimeout).ConfigureAwait(false); connectTask.TrySetException(new TimeoutException()); }); @@ -231,27 +231,27 @@ namespace Discord.Rpc public async Task SubscribeGlobal(RpcGlobalEvent evnt, RequestOptions options = null) { - await ApiClient.SendGlobalSubscribeAsync(GetEventName(evnt), options); + await ApiClient.SendGlobalSubscribeAsync(GetEventName(evnt), options).ConfigureAwait(false); } public async Task UnsubscribeGlobal(RpcGlobalEvent evnt, RequestOptions options = null) { - await ApiClient.SendGlobalUnsubscribeAsync(GetEventName(evnt), options); + await ApiClient.SendGlobalUnsubscribeAsync(GetEventName(evnt), options).ConfigureAwait(false); } public async Task SubscribeGuild(ulong guildId, RpcChannelEvent evnt, RequestOptions options = null) { - await ApiClient.SendGuildSubscribeAsync(GetEventName(evnt), guildId, options); + await ApiClient.SendGuildSubscribeAsync(GetEventName(evnt), guildId, options).ConfigureAwait(false); } public async Task UnsubscribeGuild(ulong guildId, RpcChannelEvent evnt, RequestOptions options = null) { - await ApiClient.SendGuildUnsubscribeAsync(GetEventName(evnt), guildId, options); + await ApiClient.SendGuildUnsubscribeAsync(GetEventName(evnt), guildId, options).ConfigureAwait(false); } public async Task SubscribeChannel(ulong channelId, RpcChannelEvent evnt, RequestOptions options = null) { - await ApiClient.SendChannelSubscribeAsync(GetEventName(evnt), channelId); + await ApiClient.SendChannelSubscribeAsync(GetEventName(evnt), channelId).ConfigureAwait(false); } public async Task UnsubscribeChannel(ulong channelId, RpcChannelEvent evnt, RequestOptions options = null) { - await ApiClient.SendChannelUnsubscribeAsync(GetEventName(evnt), channelId); + await ApiClient.SendChannelUnsubscribeAsync(GetEventName(evnt), channelId).ConfigureAwait(false); } public async Task GetRpcGuildAsync(ulong id, RequestOptions options = null) diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs index 78d38d595..c7c5a8438 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs @@ -72,14 +72,14 @@ namespace Discord.Rpc async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return null; } IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(limit, options); + return GetMessagesAsync(limit, options).ConfigureAwait(false); else return AsyncEnumerable.Empty>(); } @@ -98,14 +98,14 @@ namespace Discord.Rpc return AsyncEnumerable.Empty>(); } async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) - => await GetPinnedMessagesAsync(options); + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs index 79ff1afd3..5062350fa 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs @@ -71,14 +71,14 @@ namespace Discord.Rpc async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return null; } IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(limit, options); + return GetMessagesAsync(limit, options).ConfigureAwait(false); else return AsyncEnumerable.Empty>(); } @@ -97,14 +97,14 @@ namespace Discord.Rpc return AsyncEnumerable.Empty>(); } async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) - => await GetPinnedMessagesAsync(options); + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs index 897244b55..9b010b903 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs @@ -51,17 +51,17 @@ namespace Discord.Rpc => ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options); public async Task> GetInvitesAsync(RequestOptions options = null) - => await ChannelHelper.GetInvitesAsync(this, Discord, options); + => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); public async Task CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null) - => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options); + => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options).ConfigureAwait(false); public override string ToString() => Name; //IGuildChannel async Task> IGuildChannel.GetInvitesAsync(RequestOptions options) - => await GetInvitesAsync(options); + => await GetInvitesAsync(options).ConfigureAwait(false); async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options) - => await CreateInviteAsync(maxAge, maxUses, isTemporary, options); + => await CreateInviteAsync(maxAge, maxUses, isTemporary, options).ConfigureAwait(false); IReadOnlyCollection IGuildChannel.PermissionOverwrites { get { throw new NotSupportedException(); } } OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs index 45705aa6f..b29d392f5 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs @@ -73,7 +73,7 @@ namespace Discord.Rpc async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return null; } @@ -99,14 +99,14 @@ namespace Discord.Rpc return AsyncEnumerable.Empty>(); } async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) - => await GetPinnedMessagesAsync(options); + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); } diff --git a/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs b/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs index 0ccf16f16..be2562114 100644 --- a/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs +++ b/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs @@ -51,6 +51,6 @@ namespace Discord.Rpc Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(null); async Task IUser.CreateDMChannelAsync(RequestOptions options) - => await CreateDMChannelAsync(options); + => await CreateDMChannelAsync(options).ConfigureAwait(false); } } diff --git a/src/Discord.Net.WebSocket/API/DiscordVoiceApiClient.cs b/src/Discord.Net.WebSocket/API/DiscordVoiceApiClient.cs index d7957b57b..378acd22e 100644 --- a/src/Discord.Net.WebSocket/API/DiscordVoiceApiClient.cs +++ b/src/Discord.Net.WebSocket/API/DiscordVoiceApiClient.cs @@ -107,7 +107,7 @@ namespace Discord.Audio if (payload != null) bytes = Encoding.UTF8.GetBytes(SerializeJson(payload)); await _webSocketClient.SendAsync(bytes, 0, bytes.Length, true).ConfigureAwait(false); - await _sentGatewayMessageEvent.InvokeAsync(opCode); + await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false); } public async Task SendAsync(byte[] data, int bytes) { @@ -132,7 +132,7 @@ namespace Discord.Audio UserId = userId, SessionId = sessionId, Token = token - }); + }).ConfigureAwait(false); } public async Task SendSelectProtocol(string externalIp, int externalPort) { @@ -145,7 +145,7 @@ namespace Discord.Audio Port = externalPort, Mode = Mode } - }); + }).ConfigureAwait(false); } public async Task SendSetSpeaking(bool value) { @@ -153,7 +153,7 @@ namespace Discord.Audio { IsSpeaking = value, Delay = 0 - }); + }).ConfigureAwait(false); } public async Task ConnectAsync(string url) diff --git a/src/Discord.Net.WebSocket/Audio/AudioClient.cs b/src/Discord.Net.WebSocket/Audio/AudioClient.cs index de20fcdff..04eec4541 100644 --- a/src/Discord.Net.WebSocket/Audio/AudioClient.cs +++ b/src/Discord.Net.WebSocket/Audio/AudioClient.cs @@ -269,7 +269,7 @@ namespace Discord.Audio catch { return; } await _audioLogger.DebugAsync("Received Discovery").ConfigureAwait(false); - await ApiClient.SendSelectProtocol(ip, port); + await ApiClient.SendSelectProtocol(ip, port).ConfigureAwait(false); } } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 6c59c4b0b..73e183da7 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -163,7 +163,7 @@ namespace Discord.WebSocket //Abort connection on timeout var _ = Task.Run(async () => { - await Task.Delay(ConnectionTimeout); + await Task.Delay(ConnectionTimeout).ConfigureAwait(false); connectTask.TrySetException(new TimeoutException()); }); @@ -410,7 +410,7 @@ namespace Discord.WebSocket //Wait for unsynced guilds to sync first. var unsyncedGuilds = guilds.Select(x => x.SyncPromise).Where(x => !x.IsCompleted).ToImmutableArray(); if (unsyncedGuilds.Length > 0) - await Task.WhenAll(unsyncedGuilds); + await Task.WhenAll(unsyncedGuilds).ConfigureAwait(false); //Download offline members const short batchSize = 50; @@ -1468,10 +1468,10 @@ namespace Discord.WebSocket //Ignored (User only) case "CHANNEL_PINS_ACK": - await _gatewayLogger.DebugAsync("Ignored Dispatch (CHANNEL_PINS_ACK)"); + await _gatewayLogger.DebugAsync("Ignored Dispatch (CHANNEL_PINS_ACK)").ConfigureAwait(false); break; case "CHANNEL_PINS_UPDATE": - await _gatewayLogger.DebugAsync("Ignored Dispatch (CHANNEL_PINS_UPDATE)"); + await _gatewayLogger.DebugAsync("Ignored Dispatch (CHANNEL_PINS_UPDATE)").ConfigureAwait(false); break; case "GUILD_INTEGRATIONS_UPDATE": await _gatewayLogger.DebugAsync("Ignored Dispatch (GUILD_INTEGRATIONS_UPDATE)").ConfigureAwait(false); @@ -1621,17 +1621,17 @@ namespace Discord.WebSocket => Task.FromResult>(PrivateChannels); async Task> IDiscordClient.GetConnectionsAsync() - => await GetConnectionsAsync(); + => await GetConnectionsAsync().ConfigureAwait(false); async Task IDiscordClient.GetInviteAsync(string inviteId) - => await GetInviteAsync(inviteId); + => await GetInviteAsync(inviteId).ConfigureAwait(false); Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) => Task.FromResult(GetGuild(id)); Task> IDiscordClient.GetGuildsAsync(CacheMode mode) => Task.FromResult>(Guilds); async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) - => await CreateGuildAsync(name, region, jpegIcon); + => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode) => Task.FromResult(GetUser(id)); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs index 5e481d3f2..46c6aca85 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs @@ -48,7 +48,7 @@ namespace Discord.WebSocket { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id, null, options); + msg = await ChannelHelper.GetMessageAsync(this, Discord, id, null, options).ConfigureAwait(false); return msg; } public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) @@ -118,7 +118,7 @@ namespace Discord.WebSocket async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return GetCachedMessage(id); } @@ -131,11 +131,11 @@ namespace Discord.WebSocket async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs index 00cf00082..4fa366704 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs @@ -71,7 +71,7 @@ namespace Discord.WebSocket { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id, null, options); + msg = await ChannelHelper.GetMessageAsync(this, Discord, id, null, options).ConfigureAwait(false); return msg; } public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) @@ -181,7 +181,7 @@ namespace Discord.WebSocket async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return GetCachedMessage(id); } @@ -194,11 +194,11 @@ namespace Discord.WebSocket async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 637f7c8ff..64ebc5603 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -112,9 +112,9 @@ namespace Discord.WebSocket } public async Task> GetInvitesAsync(RequestOptions options = null) - => await ChannelHelper.GetInvitesAsync(this, Discord, options); + => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); public async Task CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null) - => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options); + => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options);.ConfigureAwait(false) public new abstract SocketGuildUser GetUser(ulong id); @@ -129,22 +129,22 @@ namespace Discord.WebSocket ulong IGuildChannel.GuildId => Guild.Id; async Task> IGuildChannel.GetInvitesAsync(RequestOptions options) - => await GetInvitesAsync(options); + => await GetInvitesAsync(options).ConfigureAwait(false); async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options) - => await CreateInviteAsync(maxAge, maxUses, isTemporary, options); + => await CreateInviteAsync(maxAge, maxUses, isTemporary, options).ConfigureAwait(false); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) => GetPermissionOverwrite(role); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) => GetPermissionOverwrite(user); async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(role, permissions, options); + => await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false); async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) - => await AddPermissionOverwriteAsync(user, permissions, options); + => await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false); async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) - => await RemovePermissionOverwriteAsync(role, options); + => await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false); async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) - => await RemovePermissionOverwriteAsync(user, options); + => await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false); IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index e28e37493..dddecbad5 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -54,7 +54,7 @@ namespace Discord.WebSocket { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id, Guild, options); + msg = await ChannelHelper.GetMessageAsync(this, Discord, id, Guild, options).ConfigureAwait(false); return msg; } public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) @@ -119,7 +119,7 @@ namespace Discord.WebSocket async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id, options); + return await GetMessageAsync(id, options).ConfigureAwait(false); else return GetCachedMessage(id); } @@ -132,11 +132,11 @@ namespace Discord.WebSocket async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(filePath, text, isTTS, options); + => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) - => await SendFileAsync(stream, filename, text, isTTS, options); + => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); } diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 8d81a961d..54a4d5153 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -387,7 +387,7 @@ namespace Discord.WebSocket public async Task DownloadUsersAsync() { - await Discord.DownloadUsersAsync(new[] { this }); + await Discord.DownloadUsersAsync(new[] { this }).ConfigureAwait(false); } internal void CompleteDownloadUsers() { @@ -495,12 +495,12 @@ namespace Discord.WebSocket } catch (OperationCanceledException) { - await DisconnectAudioAsync(); + await DisconnectAudioAsync().ConfigureAwait(false); } catch (Exception e) { await _audioConnectPromise.SetExceptionAsync(e).ConfigureAwait(false); - await DisconnectAudioAsync(); + await DisconnectAudioAsync().ConfigureAwait(false); } finally { @@ -532,29 +532,29 @@ namespace Discord.WebSocket IReadOnlyCollection IGuild.Roles => Roles; async Task> IGuild.GetBansAsync(RequestOptions options) - => await GetBansAsync(options); + => await GetBansAsync(options).ConfigureAwait(false); Task> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(Channels); Task IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetChannel(id)); async Task IGuild.CreateTextChannelAsync(string name, RequestOptions options) - => await CreateTextChannelAsync(name, options); + => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) - => await CreateVoiceChannelAsync(name, options); + => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) - => await GetIntegrationsAsync(options); + => await GetIntegrationsAsync(options).ConfigureAwait(false); async Task IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options) - => await CreateIntegrationAsync(id, type, options); + => await CreateIntegrationAsync(id, type, options).ConfigureAwait(false); async Task> IGuild.GetInvitesAsync(RequestOptions options) - => await GetInvitesAsync(options); + => await GetInvitesAsync(options).ConfigureAwait(false); IRole IGuild.GetRole(ulong id) => GetRole(id); async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) - => await CreateRoleAsync(name, permissions, color, isHoisted, options); + => await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false); Task> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(Users); diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs index 926dca5cc..6e230c317 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs @@ -80,7 +80,7 @@ namespace Discord.WebSocket Presence = new SocketPresence(status, game); - await SendStatus(status, game); + await SendStatus(status, game).ConfigureAwait(false); } internal async Task SendStatus(UserStatus status, GameEntity? game) { @@ -95,7 +95,7 @@ namespace Discord.WebSocket status, status == UserStatus.AFK, _statusSince != null ? _statusSince.Value.ToUnixTimeMilliseconds() : (long?)null, - gameModel); + gameModel).ConfigureAwait(false); } internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser; diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 76af76022..14018b9e2 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -51,6 +51,6 @@ namespace Discord.WebSocket Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(GlobalUser.DMChannel); async Task IUser.CreateDMChannelAsync(RequestOptions options) - => await CreateDMChannelAsync(options); + => await CreateDMChannelAsync(options).ConfigureAwait(false); } }