[Refactor] Remove some unnecessary async/await (#2739)
* Remove some unnecessary async/await * More not-so-async stuff * More not-so-async stuff * Fix merge issue
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Discord.Rest
|
||||
RequestOptions options)
|
||||
=> ModifyAsync(msg.Channel.Id, msg.Id, client, func, options);
|
||||
|
||||
public static async Task<Model> ModifyAsync(ulong channelId, ulong msgId, BaseDiscordClient client, Action<MessageProperties> func,
|
||||
public static Task<Model> ModifyAsync(ulong channelId, ulong msgId, BaseDiscordClient client, Action<MessageProperties> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new MessageProperties();
|
||||
@@ -95,7 +95,7 @@ namespace Discord.Rest
|
||||
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create<API.AllowedMentions>(),
|
||||
Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>() : Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
};
|
||||
return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false);
|
||||
return client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,58 +110,39 @@ namespace Discord.Rest
|
||||
MessageComponent = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty<API.ActionRowComponent>() : Optional<API.ActionRowComponent[]>.Unspecified
|
||||
};
|
||||
|
||||
return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false);
|
||||
return client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
|
||||
=> DeleteAsync(msg.Channel.Id, msg.Id, client, options);
|
||||
|
||||
public static async Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.DeleteMessageAsync(channelId, msgId, options);
|
||||
|
||||
public static async Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.AddReactionAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.AddReactionAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options);
|
||||
|
||||
public static async Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.AddReactionAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.AddReactionAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options);
|
||||
|
||||
public static async Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveReactionAsync(channelId, messageId, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.RemoveReactionAsync(channelId, messageId, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options);
|
||||
|
||||
public static async Task RemoveReactionAsync(IMessage msg, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task RemoveReactionAsync(IMessage msg, ulong userId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, userId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options);
|
||||
|
||||
public static async Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveAllReactionsAsync(channelId, messageId, options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.RemoveAllReactionsAsync(channelId, messageId, options);
|
||||
|
||||
public static async Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task RemoveAllReactionsAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options);
|
||||
|
||||
public static async Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options);
|
||||
|
||||
public static async Task RemoveAllReactionsForEmoteAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveAllReactionsForEmoteAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task RemoveAllReactionsForEmoteAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.RemoveAllReactionsForEmoteAsync(msg.Channel.Id, msg.Id, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options);
|
||||
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
|
||||
int? limit, BaseDiscordClient client, ReactionType reactionType, RequestOptions options)
|
||||
@@ -211,19 +192,15 @@ namespace Discord.Rest
|
||||
return newContent;
|
||||
}
|
||||
|
||||
public static async Task PinAsync(IMessage msg, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
public static Task PinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
if (msg.Channel is IVoiceChannel)
|
||||
throw new NotSupportedException("Pinned messages are not supported in text-in-voice channels.");
|
||||
await client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false);
|
||||
return client.ApiClient.AddPinAsync(msg.Channel.Id, msg.Id, options);
|
||||
}
|
||||
|
||||
public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task UnpinAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.RemovePinAsync(msg.Channel.Id, msg.Id, options);
|
||||
|
||||
public static ImmutableArray<ITag> ParseTags(string text, IMessageChannel channel, IGuild guild, IReadOnlyCollection<IUser> userMentions)
|
||||
{
|
||||
@@ -397,11 +374,8 @@ namespace Discord.Rest
|
||||
public static Task CrosspostAsync(IMessage msg, BaseDiscordClient client, RequestOptions options)
|
||||
=> CrosspostAsync(msg.Channel.Id, msg.Id, client, options);
|
||||
|
||||
public static async Task CrosspostAsync(ulong channelId, ulong msgId, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.CrosspostAsync(channelId, msgId, options).ConfigureAwait(false);
|
||||
}
|
||||
public static Task CrosspostAsync(ulong channelId, ulong msgId, BaseDiscordClient client, RequestOptions options)
|
||||
=> client.ApiClient.CrosspostAsync(channelId, msgId, options);
|
||||
|
||||
public static IUser GetAuthor(BaseDiscordClient client, IGuild guild, UserModel model, ulong? webhookId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user