Browse Source

Add ConfigureAwait(false) for most missing tasks

pull/988/head
Hsu Still 7 years ago
parent
commit
cc723df6ad
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
20 changed files with 59 additions and 58 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
  2. +1
    -1
      src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
  3. +2
    -2
      src/Discord.Net.Commands/Info/CommandInfo.cs
  4. +1
    -1
      src/Discord.Net.Commands/Readers/NullableTypeReader.cs
  5. +5
    -3
      src/Discord.Net.Commands/Readers/UserTypeReader.cs
  6. +2
    -2
      src/Discord.Net.Core/Utils/Cacheable.cs
  7. +1
    -1
      src/Discord.Net.Rest/ClientHelper.cs
  8. +7
    -7
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  9. +2
    -2
      src/Discord.Net.Rest/DiscordRestClient.cs
  10. +3
    -3
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  11. +11
    -12
      src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs
  12. +4
    -4
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  13. +3
    -3
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  14. +1
    -1
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  15. +1
    -1
      src/Discord.Net.Rest/Entities/Users/RestUser.cs
  16. +2
    -2
      src/Discord.Net.Rest/Entities/Users/UserHelper.cs
  17. +7
    -7
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  18. +3
    -3
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  19. +1
    -1
      src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs
  20. +1
    -1
      src/Discord.Net.Webhook/WebhookClientHelper.cs

+ 1
- 1
src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs View File

@@ -15,7 +15,7 @@ namespace Discord.Commands
switch (context.Client.TokenType) switch (context.Client.TokenType)
{ {
case TokenType.Bot: case TokenType.Bot:
var application = await context.Client.GetApplicationInfoAsync();
var application = await context.Client.GetApplicationInfoAsync().ConfigureAwait(false);
if (context.User.Id != application.Owner.Id) if (context.User.Id != application.Owner.Id)
return PreconditionResult.FromError("Command can only be run by the owner of the bot."); return PreconditionResult.FromError("Command can only be run by the owner of the bot.");
return PreconditionResult.FromSuccess(); return PreconditionResult.FromSuccess();


+ 1
- 1
src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs View File

@@ -34,7 +34,7 @@ namespace Discord.Commands
} }
else if (IsLoadableModule(typeInfo)) else if (IsLoadableModule(typeInfo))
{ {
await service._cmdLogger.WarningAsync($"Class {typeInfo.FullName} is not public and cannot be loaded. To suppress this message, mark the class with {nameof(DontAutoLoadAttribute)}.");
await service._cmdLogger.WarningAsync($"Class {typeInfo.FullName} is not public and cannot be loaded. To suppress this message, mark the class with {nameof(DontAutoLoadAttribute)}.").ConfigureAwait(false);
} }
} }




+ 2
- 2
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -122,11 +122,11 @@ namespace Discord.Commands
return PreconditionGroupResult.FromSuccess(); return PreconditionGroupResult.FromSuccess();
} }


var moduleResult = await CheckGroups(Module.Preconditions, "Module");
var moduleResult = await CheckGroups(Module.Preconditions, "Module").ConfigureAwait(false);
if (!moduleResult.IsSuccess) if (!moduleResult.IsSuccess)
return moduleResult; return moduleResult;


var commandResult = await CheckGroups(Preconditions, "Command");
var commandResult = await CheckGroups(Preconditions, "Command").ConfigureAwait(false);
if (!commandResult.IsSuccess) if (!commandResult.IsSuccess)
return commandResult; return commandResult;




+ 1
- 1
src/Discord.Net.Commands/Readers/NullableTypeReader.cs View File

@@ -28,7 +28,7 @@ namespace Discord.Commands
{ {
if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase)) if (string.Equals(input, "null", StringComparison.OrdinalIgnoreCase) || string.Equals(input, "nothing", StringComparison.OrdinalIgnoreCase))
return TypeReaderResult.FromSuccess(new T?()); return TypeReaderResult.FromSuccess(new T?());
return await _baseTypeReader.ReadAsync(context, input, services);
return await _baseTypeReader.ReadAsync(context, input, services).ConfigureAwait(false);
} }
} }
} }

+ 5
- 3
src/Discord.Net.Commands/Readers/UserTypeReader.cs View File

@@ -45,7 +45,7 @@ namespace Discord.Commands
if (ushort.TryParse(input.Substring(index + 1), out ushort discriminator)) if (ushort.TryParse(input.Substring(index + 1), out ushort discriminator))
{ {
var channelUser = await channelUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator && var channelUser = await channelUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator &&
string.Equals(username, x.Username, StringComparison.OrdinalIgnoreCase));
string.Equals(username, x.Username, StringComparison.OrdinalIgnoreCase)).ConfigureAwait(false);
AddResult(results, channelUser as T, channelUser?.Username == username ? 0.85f : 0.75f); AddResult(results, channelUser as T, channelUser?.Username == username ? 0.85f : 0.75f);


var guildUser = guildUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator && var guildUser = guildUsers.FirstOrDefault(x => x.DiscriminatorValue == discriminator &&
@@ -58,7 +58,8 @@ namespace Discord.Commands
{ {
await channelUsers await channelUsers
.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase)) .Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase))
.ForEachAsync(channelUser => AddResult(results, channelUser as T, channelUser.Username == input ? 0.65f : 0.55f));
.ForEachAsync(channelUser => AddResult(results, channelUser as T, channelUser.Username == input ? 0.65f : 0.55f))
.ConfigureAwait(false);
foreach (var guildUser in guildUsers.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase))) foreach (var guildUser in guildUsers.Where(x => string.Equals(input, x.Username, StringComparison.OrdinalIgnoreCase)))
AddResult(results, guildUser as T, guildUser.Username == input ? 0.60f : 0.50f); AddResult(results, guildUser as T, guildUser.Username == input ? 0.60f : 0.50f);
@@ -68,7 +69,8 @@ namespace Discord.Commands
{ {
await channelUsers await channelUsers
.Where(x => string.Equals(input, (x as IGuildUser)?.Nickname, StringComparison.OrdinalIgnoreCase)) .Where(x => string.Equals(input, (x as IGuildUser)?.Nickname, StringComparison.OrdinalIgnoreCase))
.ForEachAsync(channelUser => AddResult(results, channelUser as T, (channelUser as IGuildUser).Nickname == input ? 0.65f : 0.55f));
.ForEachAsync(channelUser => AddResult(results, channelUser as T, (channelUser as IGuildUser).Nickname == input ? 0.65f : 0.55f))
.ConfigureAwait(false);


foreach (var guildUser in guildUsers.Where(x => string.Equals(input, (x as IGuildUser).Nickname, StringComparison.OrdinalIgnoreCase))) foreach (var guildUser in guildUsers.Where(x => string.Equals(input, (x as IGuildUser).Nickname, StringComparison.OrdinalIgnoreCase)))
AddResult(results, guildUser as T, (guildUser as IGuildUser).Nickname == input ? 0.60f : 0.50f); AddResult(results, guildUser as T, (guildUser as IGuildUser).Nickname == input ? 0.60f : 0.50f);


+ 2
- 2
src/Discord.Net.Core/Utils/Cacheable.cs View File

@@ -35,13 +35,13 @@ namespace Discord
/// <exception cref="NullReferenceException">Thrown when the message is deleted.</exception> /// <exception cref="NullReferenceException">Thrown when the message is deleted.</exception>
public async Task<TEntity> DownloadAsync() public async Task<TEntity> DownloadAsync()
{ {
return await DownloadFunc();
return await DownloadFunc().ConfigureAwait(false);
} }


/// <summary> Returns the cached entity if it exists; otherwise downloads it. </summary> /// <summary> Returns the cached entity if it exists; otherwise downloads it. </summary>
/// <returns>An awaitable Task containing a cached or downloaded entity.</returns> /// <returns>An awaitable Task containing a cached or downloaded entity.</returns>
/// <exception cref="Discord.Net.HttpException">Thrown when used from a user account.</exception> /// <exception cref="Discord.Net.HttpException">Thrown when used from a user account.</exception>
/// <exception cref="NullReferenceException">Thrown when the message is deleted and is not in cache.</exception> /// <exception cref="NullReferenceException">Thrown when the message is deleted and is not in cache.</exception>
public async Task<TEntity> GetOrDownloadAsync() => HasValue ? Value : await DownloadAsync();
public async Task<TEntity> GetOrDownloadAsync() => HasValue ? Value : await DownloadAsync().ConfigureAwait(false);
} }
} }

+ 1
- 1
src/Discord.Net.Rest/ClientHelper.cs View File

@@ -146,7 +146,7 @@ namespace Discord.Rest


public static async Task<RestWebhook> GetWebhookAsync(BaseDiscordClient client, ulong id, RequestOptions options) public static async Task<RestWebhook> GetWebhookAsync(BaseDiscordClient client, ulong id, RequestOptions options)
{ {
var model = await client.ApiClient.GetWebhookAsync(id);
var model = await client.ApiClient.GetWebhookAsync(id).ConfigureAwait(false);
if (model != null) if (model != null)
return RestWebhook.Create(client, (IGuild)null, model); return RestWebhook.Create(client, (IGuild)null, model);
return null; return null;


+ 7
- 7
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -401,7 +401,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
await SendAsync("PUT", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options);
await SendAsync("PUT", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false);
} }
public async Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) public async Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null)
{ {
@@ -412,7 +412,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options);
await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false);
} }
//Channel Messages //Channel Messages
@@ -1078,7 +1078,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
return await SendAsync<Emoji>("GET", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options);
return await SendAsync<Emoji>("GET", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false);
} }


public async Task<Emoji> CreateGuildEmoteAsync(ulong guildId, Rest.CreateGuildEmoteParams args, RequestOptions options = null) public async Task<Emoji> CreateGuildEmoteAsync(ulong guildId, Rest.CreateGuildEmoteParams args, RequestOptions options = null)
@@ -1090,7 +1090,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
return await SendJsonAsync<Emoji>("POST", () => $"guilds/{guildId}/emojis", args, ids, options: options);
return await SendJsonAsync<Emoji>("POST", () => $"guilds/{guildId}/emojis", args, ids, options: options).ConfigureAwait(false);
} }


public async Task<Emoji> ModifyGuildEmoteAsync(ulong guildId, ulong emoteId, ModifyGuildEmoteParams args, RequestOptions options = null) public async Task<Emoji> ModifyGuildEmoteAsync(ulong guildId, ulong emoteId, ModifyGuildEmoteParams args, RequestOptions options = null)
@@ -1101,7 +1101,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
return await SendJsonAsync<Emoji>("PATCH", () => $"guilds/{guildId}/emojis/{emoteId}", args, ids, options: options);
return await SendJsonAsync<Emoji>("PATCH", () => $"guilds/{guildId}/emojis/{emoteId}", args, ids, options: options).ConfigureAwait(false);
} }


public async Task DeleteGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null) public async Task DeleteGuildEmoteAsync(ulong guildId, ulong emoteId, RequestOptions options = null)
@@ -1111,7 +1111,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
await SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options);
await SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false);
} }


//Users //Users
@@ -1211,7 +1211,7 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);
var ids = new BucketIds(channelId: channelId); var ids = new BucketIds(channelId: channelId);


return await SendJsonAsync<Webhook>("POST", () => $"channels/{channelId}/webhooks", args, ids, options: options);
return await SendJsonAsync<Webhook>("POST", () => $"channels/{channelId}/webhooks", args, ids, options: options).ConfigureAwait(false);
} }
public async Task<Webhook> GetWebhookAsync(ulong webhookId, RequestOptions options = null) public async Task<Webhook> GetWebhookAsync(ulong webhookId, RequestOptions options = null)
{ {


+ 2
- 2
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -37,7 +37,7 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null) public async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
{ {
return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options));
return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false));
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -165,6 +165,6 @@ namespace Discord.Rest
=> await GetVoiceRegionAsync(id, options).ConfigureAwait(false); => await GetVoiceRegionAsync(id, options).ConfigureAwait(false);


async Task<IWebhook> IDiscordClient.GetWebhookAsync(ulong id, RequestOptions options) async Task<IWebhook> IDiscordClient.GetWebhookAsync(ulong id, RequestOptions options)
=> await GetWebhookAsync(id, options);
=> await GetWebhookAsync(id, options).ConfigureAwait(false);
} }
} }

+ 3
- 3
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -88,11 +88,11 @@ namespace Discord.Rest


//ITextChannel //ITextChannel
async Task<IWebhook> ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options) async Task<IWebhook> ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options)
=> await CreateWebhookAsync(name, avatar, options);
=> await CreateWebhookAsync(name, avatar, options).ConfigureAwait(false);
async Task<IWebhook> ITextChannel.GetWebhookAsync(ulong id, RequestOptions options) async Task<IWebhook> ITextChannel.GetWebhookAsync(ulong id, RequestOptions options)
=> await GetWebhookAsync(id, options);
=> await GetWebhookAsync(id, options).ConfigureAwait(false);
async Task<IReadOnlyCollection<IWebhook>> ITextChannel.GetWebhooksAsync(RequestOptions options) async Task<IReadOnlyCollection<IWebhook>> ITextChannel.GetWebhooksAsync(RequestOptions options)
=> await GetWebhooksAsync(options);
=> await GetWebhooksAsync(options).ConfigureAwait(false);


//IMessageChannel //IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)


+ 11
- 12
src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs View File

@@ -53,7 +53,7 @@ namespace Discord.Rest
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{ {
if (mode == CacheMode.AllowDownload) if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id, options);
return await GetMessageAsync(id, options).ConfigureAwait(false);
else else
return null; return null;
} }
@@ -79,28 +79,27 @@ namespace Discord.Rest
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
} }
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options);
=> await GetPinnedMessagesAsync(options).ConfigureAwait(false);


#if FILESYSTEM #if FILESYSTEM
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options) async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, embed, options);
=> await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
#endif #endif
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, embed, options);
=> await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options) async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
=> await SendMessageAsync(text, isTTS, embed, options);
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options) IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options); => EnterTypingState(options);


//IChannel //IChannel
string IChannel.Name { get { throw new NotSupportedException(); } }
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
{
string IChannel.Name =>
throw new NotSupportedException(); throw new NotSupportedException();
}
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
{

IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) =>
throw new NotSupportedException();

Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) =>
throw new NotSupportedException(); throw new NotSupportedException();
}
} }
} }

+ 4
- 4
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -237,7 +237,7 @@ namespace Discord.Rest
}; };
if (info.Position != null) if (info.Position != null)
args.AfterUserId = info.Position.Value; args.AfterUserId = info.Position.Value;
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options);
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options).ConfigureAwait(false);
return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray(); return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
}, },
nextPage: (info, lastPage) => nextPage: (info, lastPage) =>
@@ -280,7 +280,7 @@ namespace Discord.Rest
//Emotes //Emotes
public static async Task<GuildEmote> GetEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) public static async Task<GuildEmote> GetEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
{ {
var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options);
var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false);
return emote.ToEntity(); return emote.ToEntity();
} }
public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional<IEnumerable<IRole>> roles, public static async Task<GuildEmote> CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional<IEnumerable<IRole>> roles,
@@ -294,7 +294,7 @@ namespace Discord.Rest
if (roles.IsSpecified) if (roles.IsSpecified)
apiargs.RoleIds = roles.Value?.Select(xr => xr.Id)?.ToArray(); apiargs.RoleIds = roles.Value?.Select(xr => xr.Id)?.ToArray();


var emote = await client.ApiClient.CreateGuildEmoteAsync(guild.Id, apiargs, options);
var emote = await client.ApiClient.CreateGuildEmoteAsync(guild.Id, apiargs, options).ConfigureAwait(false);
return emote.ToEntity(); return emote.ToEntity();
} }
public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func, public static async Task<GuildEmote> ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action<EmoteProperties> func,
@@ -312,7 +312,7 @@ namespace Discord.Rest
if (props.Roles.IsSpecified) if (props.Roles.IsSpecified)
apiargs.RoleIds = props.Roles.Value?.Select(xr => xr.Id)?.ToArray(); apiargs.RoleIds = props.Roles.Value?.Select(xr => xr.Id)?.ToArray();


var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options);
var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false);
return emote.ToEntity(); return emote.ToEntity();
} }
public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)


+ 3
- 3
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -121,7 +121,7 @@ namespace Discord.Rest
public async Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null) public async Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null)
{ {
var arr = args.ToArray(); var arr = args.ToArray();
await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options);
await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options).ConfigureAwait(false);
} }
public async Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, RequestOptions options = null) public async Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, RequestOptions options = null)
{ {
@@ -420,8 +420,8 @@ namespace Discord.Rest
Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); } Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); }


async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options) async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options)
=> await GetWebhookAsync(id, options);
=> await GetWebhookAsync(id, options).ConfigureAwait(false);
async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options) async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options)
=> await GetWebhooksAsync(options);
=> await GetWebhooksAsync(options).ConfigureAwait(false);
} }
} }

+ 1
- 1
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -43,7 +43,7 @@ namespace Discord.Rest


public static async Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) public static async Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
{ {
await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options);
await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false);
} }


public static async Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote, public static async Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,


+ 1
- 1
src/Discord.Net.Rest/Entities/Users/RestUser.cs View File

@@ -68,6 +68,6 @@ namespace Discord.Rest


//IUser //IUser
async Task<IDMChannel> IUser.GetOrCreateDMChannelAsync(RequestOptions options) async Task<IDMChannel> IUser.GetOrCreateDMChannelAsync(RequestOptions options)
=> await GetOrCreateDMChannelAsync(options);
=> await GetOrCreateDMChannelAsync(options).ConfigureAwait(false);
} }
} }

+ 2
- 2
src/Discord.Net.Rest/Entities/Users/UserHelper.cs View File

@@ -76,13 +76,13 @@ namespace Discord.Rest
public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options) public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options)
{ {
foreach (var role in roles) foreach (var role in roles)
await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options);
await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false);
} }


public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options) public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<IRole> roles, RequestOptions options)
{ {
foreach (var role in roles) foreach (var role in roles)
await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options);
await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, role.Id, options).ConfigureAwait(false);
} }
} }
} }

+ 7
- 7
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -1146,7 +1146,7 @@ namespace Discord.WebSocket


after = SocketMessage.Create(this, State, author, channel, data); after = SocketMessage.Create(this, State, author, channel, data);
} }
var cacheableBefore = new Cacheable<IMessage, ulong>(before, data.Id, isCached, async () => await channel.GetMessageAsync(data.Id));
var cacheableBefore = new Cacheable<IMessage, ulong>(before, data.Id, isCached, async () => await channel.GetMessageAsync(data.Id).ConfigureAwait(false));


await TimedInvokeAsync(_messageUpdatedEvent, nameof(MessageUpdated), cacheableBefore, after, channel).ConfigureAwait(false); await TimedInvokeAsync(_messageUpdatedEvent, nameof(MessageUpdated), cacheableBefore, after, channel).ConfigureAwait(false);
} }
@@ -1193,9 +1193,9 @@ namespace Discord.WebSocket
{ {
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage; var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null; bool isCached = cachedMsg != null;
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly);
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user)); var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage);


cachedMsg?.AddReaction(reaction); cachedMsg?.AddReaction(reaction);


@@ -1217,9 +1217,9 @@ namespace Discord.WebSocket
{ {
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage; var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null; bool isCached = cachedMsg != null;
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly);
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user)); var reaction = SocketReaction.Create(data, channel, cachedMsg, Optional.Create(user));
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage);


cachedMsg?.RemoveReaction(reaction); cachedMsg?.RemoveReaction(reaction);


@@ -1241,7 +1241,7 @@ namespace Discord.WebSocket
{ {
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage; var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null; bool isCached = cachedMsg != null;
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId) as IUserMessage);
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => (await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false)) as IUserMessage);


cachedMsg?.ClearReactions(); cachedMsg?.ClearReactions();


@@ -1272,7 +1272,7 @@ namespace Discord.WebSocket
{ {
var msg = SocketChannelHelper.RemoveMessage(channel, this, id); var msg = SocketChannelHelper.RemoveMessage(channel, this, id);
bool isCached = msg != null; bool isCached = msg != null;
var cacheable = new Cacheable<IMessage, ulong>(msg, id, isCached, async () => await channel.GetMessageAsync(id));
var cacheable = new Cacheable<IMessage, ulong>(msg, id, isCached, async () => await channel.GetMessageAsync(id).ConfigureAwait(false));
await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false); await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false);
} }
} }


+ 3
- 3
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -141,13 +141,13 @@ namespace Discord.WebSocket
//ITextChannel //ITextChannel
/// <inheritdoc /> /// <inheritdoc />
async Task<IWebhook> ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options) async Task<IWebhook> ITextChannel.CreateWebhookAsync(string name, Stream avatar, RequestOptions options)
=> await CreateWebhookAsync(name, avatar, options);
=> await CreateWebhookAsync(name, avatar, options).ConfigureAwait(false);
/// <inheritdoc /> /// <inheritdoc />
async Task<IWebhook> ITextChannel.GetWebhookAsync(ulong id, RequestOptions options) async Task<IWebhook> ITextChannel.GetWebhookAsync(ulong id, RequestOptions options)
=> await GetWebhookAsync(id, options);
=> await GetWebhookAsync(id, options).ConfigureAwait(false);
/// <inheritdoc /> /// <inheritdoc />
async Task<IReadOnlyCollection<IWebhook>> ITextChannel.GetWebhooksAsync(RequestOptions options) async Task<IReadOnlyCollection<IWebhook>> ITextChannel.GetWebhooksAsync(RequestOptions options)
=> await GetWebhooksAsync(options);
=> await GetWebhooksAsync(options).ConfigureAwait(false);


//IGuildChannel //IGuildChannel
/// <inheritdoc /> /// <inheritdoc />


+ 1
- 1
src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs View File

@@ -49,7 +49,7 @@ namespace Discord.Webhook


public async Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null) public async Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null)
{ {
var model = await WebhookClientHelper.ModifyAsync(_client, func, options);
var model = await WebhookClientHelper.ModifyAsync(_client, func, options).ConfigureAwait(false);
Update(model); Update(model);
} }




+ 1
- 1
src/Discord.Net.Webhook/WebhookClientHelper.cs View File

@@ -14,7 +14,7 @@ namespace Discord.Webhook
{ {
public static async Task<RestInternalWebhook> GetWebhookAsync(DiscordWebhookClient client, ulong webhookId) public static async Task<RestInternalWebhook> GetWebhookAsync(DiscordWebhookClient client, ulong webhookId)
{ {
var model = await client.ApiClient.GetWebhookAsync(webhookId);
var model = await client.ApiClient.GetWebhookAsync(webhookId).ConfigureAwait(false);
if (model == null) if (model == null)
throw new InvalidOperationException("Could not find a webhook for the supplied credentials."); throw new InvalidOperationException("Could not find a webhook for the supplied credentials.");
return RestInternalWebhook.Create(client, model); return RestInternalWebhook.Create(client, model);


Loading…
Cancel
Save