[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:
Dmitry
2023-11-19 00:29:14 +03:00
committed by GitHub
parent 699554ad11
commit 86655a8157
73 changed files with 1020 additions and 1020 deletions

View File

@@ -25,7 +25,7 @@ namespace Discord.Rest
return RestApplication.Create(client, model);
}
public static async Task<API.Application> ModifyCurrentBotApplicationAsync(BaseDiscordClient client, Action<ModifyApplicationProperties> func, RequestOptions options)
public static Task<API.Application> ModifyCurrentBotApplicationAsync(BaseDiscordClient client, Action<ModifyApplicationProperties> func, RequestOptions options)
{
var args = new ModifyApplicationProperties();
func(args);
@@ -40,7 +40,7 @@ namespace Discord.Rest
if (args.Description.IsSpecified)
Preconditions.AtMost(args.Description.Value.Length, DiscordConfig.MaxApplicationDescriptionLength, nameof(args.Description), $"An application description tag mus have length less or equal to {DiscordConfig.MaxApplicationDescriptionLength}");
return await client.ApiClient.ModifyCurrentBotApplicationAsync(new()
return client.ApiClient.ModifyCurrentBotApplicationAsync(new()
{
Description = args.Description,
Tags = args.Tags,

File diff suppressed because it is too large Load Diff

View File

@@ -13,12 +13,10 @@ namespace Discord.Rest
internal static class ChannelHelper
{
#region General
public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false);
}
public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordClient client,
public static Task DeleteAsync(IChannel channel, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.DeleteChannelAsync(channel.Id, options);
public static Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordClient client,
Action<GuildChannelProperties> func,
RequestOptions options)
{
@@ -40,9 +38,10 @@ namespace Discord.Rest
: Optional.Create<API.Overwrite[]>(),
Flags = args.Flags.GetValueOrDefault(),
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options);
}
public static async Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordClient client,
public static Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordClient client,
Action<TextChannelProperties> func,
RequestOptions options)
{
@@ -67,9 +66,10 @@ namespace Discord.Rest
: Optional.Create<API.Overwrite[]>(),
DefaultSlowModeInterval = args.DefaultSlowModeInterval
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options);
}
public static async Task<Model> ModifyAsync(IVoiceChannel channel, BaseDiscordClient client,
public static Task<Model> ModifyAsync(IVoiceChannel channel, BaseDiscordClient client,
Action<VoiceChannelProperties> func,
RequestOptions options)
{
@@ -95,10 +95,10 @@ namespace Discord.Rest
SlowModeInterval = args.SlowModeInterval,
IsNsfw = args.IsNsfw,
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options);
}
public static async Task<StageInstance> ModifyAsync(IStageChannel channel, BaseDiscordClient client,
public static Task<StageInstance> ModifyAsync(IStageChannel channel, BaseDiscordClient client,
Action<StageInstanceProperties> func, RequestOptions options = null)
{
var args = new StageInstanceProperties();
@@ -110,7 +110,7 @@ namespace Discord.Rest
Topic = args.Topic
};
return await client.ApiClient.ModifyStageInstanceAsync(channel.Id, apiArgs, options);
return client.ApiClient.ModifyStageInstanceAsync(channel.Id, apiArgs, options);
}
#endregion
@@ -492,28 +492,27 @@ namespace Discord.Rest
#endregion
#region Permission Overwrites
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
public static Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IUser user, OverwritePermissions perms, RequestOptions options)
{
var args = new ModifyChannelPermissionsParams((int)PermissionTarget.User, perms.AllowValue.ToString(), perms.DenyValue.ToString());
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false);
return client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options);
}
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
public static Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IRole role, OverwritePermissions perms, RequestOptions options)
{
var args = new ModifyChannelPermissionsParams((int)PermissionTarget.Role, perms.AllowValue.ToString(), perms.DenyValue.ToString());
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false);
return client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options);
}
public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
public static Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IUser user, RequestOptions options)
{
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id, options).ConfigureAwait(false);
}
public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
=> client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id, options);
public static Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IRole role, RequestOptions options)
{
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options).ConfigureAwait(false);
}
=> client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options);
#endregion
#region Users
@@ -564,11 +563,9 @@ namespace Discord.Rest
#endregion
#region Typing
public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client,
RequestOptions options = null)
{
await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options).ConfigureAwait(false);
}
public static Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client, RequestOptions options = null)
=> client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options);
public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client,
RequestOptions options)
=> new TypingNotifier(channel, options);

View File

@@ -8,7 +8,7 @@ namespace Discord.Rest;
internal static class ForumHelper
{
public static async Task<Model> ModifyAsync(IForumChannel channel, BaseDiscordClient client,
public static Task<Model> ModifyAsync(IForumChannel channel, BaseDiscordClient client,
Action<ForumChannelProperties> func,
RequestOptions options)
{
@@ -59,6 +59,6 @@ internal static class ForumHelper
: Optional<ModifyForumReactionEmojiParams>.Unspecified,
DefaultSortOrder = args.DefaultSortOrder
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options);
}
}

View File

@@ -220,17 +220,17 @@ namespace Discord.Rest
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
=> GetPermissionOverwrite(user);
/// <inheritdoc />
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false);
Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
=> AddPermissionOverwriteAsync(role, permissions, options);
/// <inheritdoc />
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false);
Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
=> AddPermissionOverwriteAsync(user, permissions, options);
/// <inheritdoc />
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
=> await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false);
Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
=> RemovePermissionOverwriteAsync(role, options);
/// <inheritdoc />
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
=> await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false);
Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
=> RemovePermissionOverwriteAsync(user, options);
/// <inheritdoc />
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)

View File

@@ -11,7 +11,7 @@ namespace Discord.Rest
{
internal static class ThreadHelper
{
public static async Task<Model> CreateThreadAsync(BaseDiscordClient client, ITextChannel channel, string name, ThreadType type = ThreadType.PublicThread,
public static Task<Model> CreateThreadAsync(BaseDiscordClient client, ITextChannel channel, string name, ThreadType type = ThreadType.PublicThread,
ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null)
{
if (channel is INewsChannel && type != ThreadType.NewsThread)
@@ -26,17 +26,13 @@ namespace Discord.Rest
Ratelimit = slowmode.HasValue ? slowmode.Value : Optional<int?>.Unspecified,
};
Model model;
if (message != null)
model = await client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options).ConfigureAwait(false);
return client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options);
else
model = await client.ApiClient.StartThreadAsync(channel.Id, args, options).ConfigureAwait(false);
return model;
return client.ApiClient.StartThreadAsync(channel.Id, args, options);
}
public static async Task<Model> ModifyAsync(IThreadChannel channel, BaseDiscordClient client,
public static Task<Model> ModifyAsync(IThreadChannel channel, BaseDiscordClient client,
Action<ThreadChannelProperties> func,
RequestOptions options)
{
@@ -55,7 +51,7 @@ namespace Discord.Rest
AppliedTags = args.AppliedTags,
Flags = args.Flags,
};
return await client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options);
}
public static async Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(IGuild guild, ulong channelId, BaseDiscordClient client, RequestOptions options)

View File

@@ -20,7 +20,7 @@ namespace Discord.Rest
{
#region General
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null" />.</exception>
public static async Task<Model> ModifyAsync(IGuild guild, BaseDiscordClient client,
public static Task<Model> ModifyAsync(IGuild guild, BaseDiscordClient client,
Action<GuildProperties> func, RequestOptions options)
{
if (func == null)
@@ -91,10 +91,11 @@ namespace Discord.Rest
else if (args.PreferredCulture.IsSpecified)
apiArgs.PreferredLocale = args.PreferredCulture.Value.Name;
return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options);
}
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null" />.</exception>
public static async Task<WidgetModel> ModifyWidgetAsync(IGuild guild, BaseDiscordClient client,
public static Task<WidgetModel> ModifyWidgetAsync(IGuild guild, BaseDiscordClient client,
Action<GuildWidgetProperties> func, RequestOptions options)
{
if (func == null)
@@ -112,30 +113,29 @@ namespace Discord.Rest
else if (args.ChannelId.IsSpecified)
apiArgs.ChannelId = args.ChannelId.Value;
return await client.ApiClient.ModifyGuildWidgetAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildWidgetAsync(guild.Id, apiArgs, options);
}
public static async Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client,
public static Task ReorderChannelsAsync(IGuild guild, BaseDiscordClient client,
IEnumerable<ReorderChannelProperties> args, RequestOptions options)
{
var apiArgs = args.Select(x => new API.Rest.ModifyGuildChannelsParams(x.Id, x.Position));
await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildChannelsAsync(guild.Id, apiArgs, options);
}
public static async Task<IReadOnlyCollection<RoleModel>> ReorderRolesAsync(IGuild guild, BaseDiscordClient client,
public static Task<IReadOnlyCollection<RoleModel>> ReorderRolesAsync(IGuild guild, BaseDiscordClient client,
IEnumerable<ReorderRoleProperties> args, RequestOptions options)
{
var apiArgs = args.Select(x => new API.Rest.ModifyGuildRolesParams(x.Id, x.Position));
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
}
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.LeaveGuildAsync(guild.Id, options).ConfigureAwait(false);
}
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options);
}
public static Task LeaveAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.LeaveGuildAsync(guild.Id, options);
public static Task DeleteAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.DeleteGuildAsync(guild.Id, options);
public static ulong GetUploadLimit(IGuild guild)
{
var tierFactor = guild.PremiumTier switch
@@ -223,17 +223,15 @@ namespace Discord.Rest
return model == null ? null : RestBan.Create(client, model);
}
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
public static Task AddBanAsync(IGuild guild, BaseDiscordClient client,
ulong userId, int pruneDays, string reason, RequestOptions options)
{
var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays, Reason = reason };
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).ConfigureAwait(false);
return client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options);
}
public static Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options)
=> client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options);
#endregion
#region Channels
@@ -506,9 +504,9 @@ namespace Discord.Rest
var models = await client.ApiClient.GetIntegrationsAsync(guild.Id, options).ConfigureAwait(false);
return models.Select(x => RestIntegration.Create(client, guild, x)).ToImmutableArray();
}
public static async Task DeleteIntegrationAsync(IGuild guild, BaseDiscordClient client, ulong id,
RequestOptions options) =>
await client.ApiClient.DeleteIntegrationAsync(guild.Id, id, options).ConfigureAwait(false);
public static Task DeleteIntegrationAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
=> client.ApiClient.DeleteIntegrationAsync(guild.Id, id, options);
#endregion
#region Interactions
@@ -611,7 +609,7 @@ namespace Discord.Rest
return model is null ? null : RestGuildUser.Create(client, guild, model);
}
public static async Task AddGuildUserAsync(ulong guildId, BaseDiscordClient client, ulong userId, string accessToken,
public static Task AddGuildUserAsync(ulong guildId, BaseDiscordClient client, ulong userId, string accessToken,
Action<AddGuildUserProperties> func, RequestOptions options)
{
var args = new AddGuildUserProperties();
@@ -635,7 +633,7 @@ namespace Discord.Rest
RoleIds = args.RoleIds.IsSpecified ? args.RoleIds.Value.Distinct().ToArray() : Optional.Create<ulong[]>()
};
await client.ApiClient.AddGuildMemberAsync(guildId, userId, apiArgs, options);
return client.ApiClient.AddGuildMemberAsync(guildId, userId, apiArgs, options);
}
public static async Task<RestGuildUser> GetUserAsync(IGuild guild, BaseDiscordClient client,
@@ -646,11 +644,9 @@ namespace Discord.Rest
return RestGuildUser.Create(client, guild, model);
return null;
}
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
return await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false);
}
public static Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
=> GetUserAsync(guild, client, client.CurrentUser.Id, options);
public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuild guild, BaseDiscordClient client,
ulong? fromUserId, int? limit, RequestOptions options)
{
@@ -833,7 +829,7 @@ namespace Discord.Rest
return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false);
}
public static async Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Stream file, string filename, IEnumerable<string> tags,
public static Task<API.Sticker> CreateStickerAsync(BaseDiscordClient client, IGuild guild, string name, Stream file, string filename, IEnumerable<string> tags,
string description = null, RequestOptions options = null)
{
Preconditions.NotNull(name, nameof(name));
@@ -865,10 +861,10 @@ namespace Discord.Rest
FileName = filename
};
return await client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options).ConfigureAwait(false);
return client.ApiClient.CreateGuildStickerAsync(apiArgs, guild.Id, options);
}
public static async Task<API.Sticker> ModifyStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, Action<StickerProperties> func,
public static Task<API.Sticker> ModifyStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, Action<StickerProperties> func,
RequestOptions options = null)
{
if (func == null)
@@ -886,11 +882,11 @@ namespace Discord.Rest
Optional<string>.Unspecified
};
return await client.ApiClient.ModifyStickerAsync(apiArgs, guildId, sticker.Id, options).ConfigureAwait(false);
return client.ApiClient.ModifyStickerAsync(apiArgs, guildId, sticker.Id, options);
}
public static async Task DeleteStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, RequestOptions options = null)
=> await client.ApiClient.DeleteStickerAsync(guildId, sticker.Id, options).ConfigureAwait(false);
public static Task DeleteStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, RequestOptions options = null)
=> client.ApiClient.DeleteStickerAsync(guildId, sticker.Id, options);
#endregion
#region Events
@@ -981,7 +977,7 @@ namespace Discord.Rest
);
}
public static async Task<API.GuildScheduledEvent> ModifyGuildEventAsync(BaseDiscordClient client, Action<GuildScheduledEventsProperties> func,
public static Task<API.GuildScheduledEvent> ModifyGuildEventAsync(BaseDiscordClient client, Action<GuildScheduledEventsProperties> func,
IGuildScheduledEvent guildEvent, RequestOptions options = null)
{
var args = new GuildScheduledEventsProperties();
@@ -1042,7 +1038,7 @@ namespace Discord.Rest
};
}
return await client.ApiClient.ModifyGuildScheduledEventAsync(apiArgs, guildEvent.Id, guildEvent.Guild.Id, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildScheduledEventAsync(apiArgs, guildEvent.Id, guildEvent.Guild.Id, options);
}
public static async Task<RestGuildEvent> GetGuildEventAsync(BaseDiscordClient client, ulong id, IGuild guild, RequestOptions options = null)
@@ -1123,10 +1119,8 @@ namespace Discord.Rest
return RestGuildEvent.Create(client, guild, client.CurrentUser, model);
}
public static async Task DeleteEventAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, RequestOptions options = null)
{
await client.ApiClient.DeleteGuildScheduledEventAsync(guildEvent.Id, guildEvent.Guild.Id, options).ConfigureAwait(false);
}
public static Task DeleteEventAsync(BaseDiscordClient client, IGuildScheduledEvent guildEvent, RequestOptions options = null)
=> client.ApiClient.DeleteGuildScheduledEventAsync(guildEvent.Id, guildEvent.Guild.Id, options);
#endregion
@@ -1180,7 +1174,7 @@ namespace Discord.Rest
#region Auto Mod
public static async Task<AutoModerationRule> CreateAutoModRuleAsync(IGuild guild, Action<AutoModRuleProperties> func, BaseDiscordClient client, RequestOptions options)
public static Task<AutoModerationRule> CreateAutoModRuleAsync(IGuild guild, Action<AutoModRuleProperties> func, BaseDiscordClient client, RequestOptions options)
{
var args = new AutoModRuleProperties();
func(args);
@@ -1299,14 +1293,14 @@ namespace Discord.Rest
},
};
return await client.ApiClient.CreateGuildAutoModRuleAsync(guild.Id, props, options);
return client.ApiClient.CreateGuildAutoModRuleAsync(guild.Id, props, options);
}
public static async Task<AutoModerationRule> GetAutoModRuleAsync(ulong ruleId, IGuild guild, BaseDiscordClient client, RequestOptions options)
=> await client.ApiClient.GetGuildAutoModRuleAsync(guild.Id, ruleId, options);
public static Task<AutoModerationRule> GetAutoModRuleAsync(ulong ruleId, IGuild guild, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.GetGuildAutoModRuleAsync(guild.Id, ruleId, options);
public static async Task<AutoModerationRule[]> GetAutoModRulesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
=> await client.ApiClient.GetGuildAutoModRulesAsync(guild.Id, options);
public static Task<AutoModerationRule[]> GetAutoModRulesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.GetGuildAutoModRulesAsync(guild.Id, options);
public static Task<AutoModerationRule> ModifyRuleAsync(BaseDiscordClient client, IAutoModRule rule, Action<AutoModRuleProperties> func, RequestOptions options)
{
@@ -1354,10 +1348,10 @@ namespace Discord.Rest
#region Onboarding
public static async Task<GuildOnboarding> GetGuildOnboardingAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
=> await client.ApiClient.GetGuildOnboardingAsync(guild.Id, options);
public static Task<GuildOnboarding> GetGuildOnboardingAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.GetGuildOnboardingAsync(guild.Id, options);
public static async Task<GuildOnboarding> ModifyGuildOnboardingAsync(IGuild guild, Action<GuildOnboardingProperties> func, BaseDiscordClient client, RequestOptions options)
public static Task<GuildOnboarding> ModifyGuildOnboardingAsync(IGuild guild, Action<GuildOnboardingProperties> func, BaseDiscordClient client, RequestOptions options)
{
var props = new GuildOnboardingProperties();
func(props);
@@ -1394,7 +1388,7 @@ namespace Discord.Rest
: Optional<GuildOnboardingPromptParams[]>.Unspecified,
};
return await client.ApiClient.ModifyGuildOnboardingAsync(guild.Id, args, options);
return client.ApiClient.ModifyGuildOnboardingAsync(guild.Id, args, options);
}
#endregion

View File

@@ -296,10 +296,10 @@ namespace Discord.Rest
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="args" /> is <see langword="null"/>.</exception>
public async Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null)
public Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null)
{
var arr = args.ToArray();
await GuildHelper.ReorderChannelsAsync(this, Discord, arr, options).ConfigureAwait(false);
return GuildHelper.ReorderChannelsAsync(this, Discord, arr, options);
}
/// <inheritdoc />
public async Task ReorderRolesAsync(IEnumerable<ReorderRoleProperties> args, RequestOptions options = null)
@@ -670,12 +670,12 @@ namespace Discord.Rest
/// A task that represents the asynchronous get operation. The task result contains the widget channel set
/// within the server's widget settings; <see langword="null"/> if none is set.
/// </returns>
public async Task<RestGuildChannel> GetWidgetChannelAsync(RequestOptions options = null)
public Task<RestGuildChannel> GetWidgetChannelAsync(RequestOptions options = null)
{
var widgetChannelId = WidgetChannelId;
if (widgetChannelId.HasValue)
return await GuildHelper.GetChannelAsync(this, Discord, widgetChannelId.Value, options).ConfigureAwait(false);
return null;
return GuildHelper.GetChannelAsync(this, Discord, widgetChannelId.Value, options);
return Task.FromResult<RestGuildChannel>(null);
}
/// <summary>
@@ -1053,8 +1053,9 @@ namespace Discord.Rest
/// A task that represents the asynchronous get operation. The task result contains a read-only collection
/// of application commands found within the guild.
/// </returns>
public async Task<IReadOnlyCollection<RestGuildCommand>> GetApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null)
=> await ClientHelper.GetGuildApplicationCommandsAsync(Discord, Id, withLocalizations, locale, options).ConfigureAwait(false);
public Task<IReadOnlyCollection<RestGuildCommand>> GetApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null)
=> ClientHelper.GetGuildApplicationCommandsAsync(Discord, Id, withLocalizations, locale, options);
/// <summary>
/// Gets an application command within this guild with the specified id.
/// </summary>
@@ -1064,8 +1065,9 @@ namespace Discord.Rest
/// A ValueTask that represents the asynchronous get operation. The task result contains a <see cref="IApplicationCommand"/>
/// if found, otherwise <see langword="null"/>.
/// </returns>
public async Task<RestGuildCommand> GetApplicationCommandAsync(ulong id, RequestOptions options = null)
=> await ClientHelper.GetGuildApplicationCommandAsync(Discord, id, Id, options);
public Task<RestGuildCommand> GetApplicationCommandAsync(ulong id, RequestOptions options = null)
=> ClientHelper.GetGuildApplicationCommandAsync(Discord, id, Id, options);
/// <summary>
/// Creates an application command within this guild.
/// </summary>
@@ -1168,6 +1170,7 @@ namespace Discord.Rest
using var fs = File.OpenRead(path);
return await CreateStickerAsync(name, fs, Path.GetFileName(fs.Name), tags, description,options);
}
/// <summary>
/// Creates a new sticker in this guild
/// </summary>
@@ -1587,8 +1590,8 @@ namespace Discord.Rest
async Task<IReadOnlyCollection<IIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
=> await GetIntegrationsAsync(options).ConfigureAwait(false);
/// <inheritdoc />
async Task IGuild.DeleteIntegrationAsync(ulong id, RequestOptions options)
=> await DeleteIntegrationAsync(id, options).ConfigureAwait(false);
Task IGuild.DeleteIntegrationAsync(ulong id, RequestOptions options)
=> DeleteIntegrationAsync(id, options);
/// <inheritdoc />
async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
@@ -1616,7 +1619,8 @@ namespace Discord.Rest
/// </summary>
/// <param name="user">The user to disconnect.</param>
/// <returns>A task that represents the asynchronous operation for disconnecting a user.</returns>
async Task IGuild.DisconnectAsync(IGuildUser user) => await user.ModifyAsync(x => x.Channel = null);
Task IGuild.DisconnectAsync(IGuildUser user)
=> user.ModifyAsync(x => x.Channel = null);
/// <inheritdoc />
async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)

View File

@@ -52,10 +52,8 @@ namespace Discord.Rest
ApproximatePresenceCount = model.ApproximatePresenceCount.IsSpecified ? model.ApproximatePresenceCount.Value : null;
}
public async Task LeaveAsync(RequestOptions options = null)
{
await Discord.ApiClient.LeaveGuildAsync(Id, options).ConfigureAwait(false);
}
public Task LeaveAsync(RequestOptions options = null)
=> Discord.ApiClient.LeaveGuildAsync(Id, options);
public async Task<RestGuildUser> GetCurrentUserGuildMemberAsync(RequestOptions options = null)
{
@@ -64,10 +62,8 @@ namespace Discord.Rest
}
/// <inheritdoc />
public async Task DeleteAsync(RequestOptions options = null)
{
await Discord.ApiClient.DeleteGuildAsync(Id, options).ConfigureAwait(false);
}
public Task DeleteAsync(RequestOptions options = null)
=> Discord.ApiClient.DeleteGuildAsync(Id, options);
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id}{(IsOwner ? ", Owned" : "")})";

View File

@@ -77,10 +77,8 @@ namespace Discord.Rest
_syncedAtTicks = model.SyncedAt.IsSpecified ? model.SyncedAt.Value.UtcTicks : null;
}
public async Task DeleteAsync()
{
await Discord.ApiClient.DeleteIntegrationAsync(GuildId, Id).ConfigureAwait(false);
}
public Task DeleteAsync()
=> Discord.ApiClient.DeleteIntegrationAsync(GuildId, Id);
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id}{(IsEnabled ? ", Enabled" : "")})";

View File

@@ -138,7 +138,7 @@ namespace Discord.Rest
}
/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupAsync(
public override Task<RestFollowupMessage> FollowupAsync(
string text = null,
Embed[] embeds = null,
bool isTTS = false,
@@ -171,7 +171,7 @@ namespace Discord.Rest
if (ephemeral)
args.Flags = MessageFlags.Ephemeral;
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
}
/// <inheritdoc/>
@@ -235,7 +235,7 @@ namespace Discord.Rest
}
/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupWithFilesAsync(
public override Task<RestFollowupMessage> FollowupWithFilesAsync(
IEnumerable<FileAttachment> attachments,
string text = null,
Embed[] embeds = null,
@@ -284,7 +284,7 @@ namespace Discord.Rest
flags |= MessageFlags.Ephemeral;
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified };
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false);
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
}
/// <summary>

View File

@@ -34,14 +34,15 @@ namespace Discord.Rest
return entity;
}
internal virtual async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel, bool doApiCall)
internal virtual Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel, bool doApiCall)
{
Name = model.Name;
if (model.Resolved.IsSpecified && ResolvableData == null)
{
ResolvableData = new RestResolvableData<Model>();
await ResolvableData.PopulateAsync(client, guild, channel, model, doApiCall).ConfigureAwait(false);
return ResolvableData.PopulateAsync(client, guild, channel, model, doApiCall);
}
return Task.CompletedTask;
}
IReadOnlyCollection<IApplicationCommandInteractionDataOption> IApplicationCommandInteractionData.Options

View File

@@ -35,17 +35,13 @@ namespace Discord.Rest
return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(Array.Empty<CreateApplicationCommandParams>(), options);
}
public static async Task SendInteractionResponseAsync(BaseDiscordClient client, InteractionResponse response,
public static Task SendInteractionResponseAsync(BaseDiscordClient client, InteractionResponse response,
IDiscordInteraction interaction, IMessageChannel channel = null, RequestOptions options = null)
{
await client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options).ConfigureAwait(false);
}
=> client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options);
public static async Task SendInteractionResponseAsync(BaseDiscordClient client, UploadInteractionFileParams response,
public static Task SendInteractionResponseAsync(BaseDiscordClient client, UploadInteractionFileParams response,
IDiscordInteraction interaction, IMessageChannel channel = null, RequestOptions options = null)
{
await client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options).ConfigureAwait(false);
}
=> client.ApiClient.CreateInteractionResponseAsync(response, interaction.Id, interaction.Token, options);
public static async Task<RestInteractionMessage> GetOriginalResponseAsync(BaseDiscordClient client, IMessageChannel channel,
IDiscordInteraction interaction, RequestOptions options = null)
@@ -90,7 +86,8 @@ namespace Discord.Rest
func((TArg)args);
return CreateGlobalCommandAsync(client, (TArg)args, options);
}
public static async Task<ApplicationCommand> CreateGlobalCommandAsync(BaseDiscordClient client,
public static Task<ApplicationCommand> CreateGlobalCommandAsync(BaseDiscordClient client,
ApplicationCommandProperties arg, RequestOptions options = null)
{
Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name));
@@ -122,10 +119,10 @@ namespace Discord.Rest
: Optional<ApplicationCommandOption[]>.Unspecified;
}
return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false);
return client.ApiClient.CreateGlobalApplicationCommandAsync(model, options);
}
public static async Task<ApplicationCommand[]> BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client,
public static Task<ApplicationCommand[]> BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client,
ApplicationCommandProperties[] args, RequestOptions options = null)
{
Preconditions.NotNull(args, nameof(args));
@@ -166,7 +163,7 @@ namespace Discord.Rest
models.Add(model);
}
return await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false);
return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options);
}
public static async Task<IReadOnlyCollection<ApplicationCommand>> BulkOverwriteGuildCommandsAsync(BaseDiscordClient client, ulong guildId,
@@ -239,7 +236,7 @@ namespace Discord.Rest
return ModifyGlobalCommandAsync(client, command, arg, options);
}
public static async Task<ApplicationCommand> ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command,
public static Task<ApplicationCommand> ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command,
ApplicationCommandProperties args, RequestOptions options = null)
{
if (args.Name.IsSpecified)
@@ -281,15 +278,15 @@ namespace Discord.Rest
: Optional<ApplicationCommandOption[]>.Unspecified;
}
return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false);
return client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options);
}
public static async Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null)
public static Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null)
{
Preconditions.NotNull(command, nameof(command));
Preconditions.NotEqual(command.Id, 0, nameof(command.Id));
await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false);
return client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options);
}
#endregion
@@ -302,7 +299,7 @@ namespace Discord.Rest
return CreateGuildCommandAsync(client, guildId, (TArg)args, options);
}
public static async Task<ApplicationCommand> CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId,
public static Task<ApplicationCommand> CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId,
ApplicationCommandProperties arg, RequestOptions options = null)
{
var model = new CreateApplicationCommandParams
@@ -332,7 +329,7 @@ namespace Discord.Rest
: Optional<ApplicationCommandOption[]>.Unspecified;
}
return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false);
return client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options);
}
public static Task<ApplicationCommand> ModifyGuildCommandAsync<TArg>(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
@@ -343,7 +340,7 @@ namespace Discord.Rest
return ModifyGuildCommandAsync(client, command, guildId, arg, options);
}
public static async Task<ApplicationCommand> ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
public static Task<ApplicationCommand> ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
ApplicationCommandProperties arg, RequestOptions options = null)
{
var model = new ModifyApplicationCommandParams
@@ -369,15 +366,15 @@ namespace Discord.Rest
: Optional<ApplicationCommandOption[]>.Unspecified;
}
return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options);
}
public static async Task DeleteGuildCommandAsync(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null)
public static Task DeleteGuildCommandAsync(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null)
{
Preconditions.NotNull(command, nameof(command));
Preconditions.NotEqual(command.Id, 0, nameof(command.Id));
await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false);
return client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options);
}
public static Task DeleteUnknownApplicationCommandAsync(BaseDiscordClient client, ulong? guildId, IApplicationCommand command, RequestOptions options = null)
@@ -389,7 +386,7 @@ namespace Discord.Rest
#endregion
#region Responses
public static async Task<Discord.API.Message> ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action<MessageProperties> func,
public static Task<Discord.API.Message> ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action<MessageProperties> func,
RequestOptions options = null)
{
var args = new MessageProperties();
@@ -429,11 +426,13 @@ namespace Discord.Rest
: Optional<API.ActionRowComponent[]>.Unspecified,
};
return await client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options).ConfigureAwait(false);
return client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options);
}
public static async Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null)
=> await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options);
public static async Task<API.Message> ModifyInteractionResponseAsync(BaseDiscordClient client, string token, Action<MessageProperties> func,
public static Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null)
=> client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options);
public static Task<API.Message> ModifyInteractionResponseAsync(BaseDiscordClient client, string token, Action<MessageProperties> func,
RequestOptions options = null)
{
var args = new MessageProperties();
@@ -476,7 +475,7 @@ namespace Discord.Rest
Flags = args.Flags
};
return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false);
return client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options);
}
else
{
@@ -492,15 +491,15 @@ namespace Discord.Rest
: Optional<API.ActionRowComponent[]>.Unspecified
};
return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false);
return client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options);
}
}
public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null)
=> await client.ApiClient.DeleteInteractionResponseAsync(message.Token, options);
public static Task DeleteInteractionResponseAsync(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null)
=> client.ApiClient.DeleteInteractionResponseAsync(message.Token, options);
public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, IDiscordInteraction interaction, RequestOptions options = null)
=> await client.ApiClient.DeleteInteractionResponseAsync(interaction.Token, options);
public static Task DeleteInteractionResponseAsync(BaseDiscordClient client, IDiscordInteraction interaction, RequestOptions options = null)
=> client.ApiClient.DeleteInteractionResponseAsync(interaction.Token, options);
public static Task SendAutocompleteResultAsync(BaseDiscordClient client, IEnumerable<AutocompleteResult> result, ulong interactionId,
string interactionToken, RequestOptions options)
@@ -523,10 +522,10 @@ namespace Discord.Rest
return client.ApiClient.CreateInteractionResponseAsync(apiArgs, interactionId, interactionToken, options);
}
public static async Task RespondWithPremiumRequiredAsync(BaseDiscordClient client, ulong interactionId,
public static Task RespondWithPremiumRequiredAsync(BaseDiscordClient client, ulong interactionId,
string interactionToken, RequestOptions options = null)
{
await client.ApiClient.CreateInteractionResponseAsync(new InteractionResponse
return client.ApiClient.CreateInteractionResponseAsync(new InteractionResponse
{
Type = InteractionResponseType.PremiumRequired,
Data = Optional<InteractionCallbackData>.Unspecified

View File

@@ -243,7 +243,7 @@ namespace Discord.Rest
}
/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupAsync(
public override Task<RestFollowupMessage> FollowupAsync(
string text = null,
Embed[] embeds = null,
bool isTTS = false,
@@ -276,7 +276,7 @@ namespace Discord.Rest
if (ephemeral)
args.Flags = MessageFlags.Ephemeral;
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
}
/// <inheritdoc/>
@@ -340,7 +340,7 @@ namespace Discord.Rest
}
/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupWithFilesAsync(
public override Task<RestFollowupMessage> FollowupWithFilesAsync(
IEnumerable<FileAttachment> attachments,
string text = null,
Embed[] embeds = null,
@@ -389,7 +389,7 @@ namespace Discord.Rest
flags |= MessageFlags.Ephemeral;
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified };
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false);
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
}
/// <summary>

View File

@@ -128,7 +128,7 @@ namespace Discord.Rest
/// <returns>
/// The sent message.
/// </returns>
public override async Task<RestFollowupMessage> FollowupAsync(
public override Task<RestFollowupMessage> FollowupAsync(
string text = null,
Embed[] embeds = null,
bool isTTS = false,
@@ -161,7 +161,7 @@ namespace Discord.Rest
if (ephemeral)
args.Flags = MessageFlags.Ephemeral;
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
}
/// <summary>
@@ -180,7 +180,7 @@ namespace Discord.Rest
/// <returns>
/// The sent message.
/// </returns>
public override async Task<RestFollowupMessage> FollowupWithFileAsync(
public override Task<RestFollowupMessage> FollowupWithFileAsync(
Stream fileStream,
string fileName,
string text = null,
@@ -218,7 +218,7 @@ namespace Discord.Rest
if (ephemeral)
args.Flags = MessageFlags.Ephemeral;
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
}
/// <summary>
@@ -368,7 +368,7 @@ namespace Discord.Rest
}
/// <inheritdoc/>
public override async Task<RestFollowupMessage> FollowupWithFilesAsync(
public override Task<RestFollowupMessage> FollowupWithFilesAsync(
IEnumerable<FileAttachment> attachments,
string text = null,
Embed[] embeds = null,
@@ -417,7 +417,7 @@ namespace Discord.Rest
flags |= MessageFlags.Ephemeral;
var args = new API.Rest.UploadWebhookFileParams(attachments.ToArray()) { Flags = flags, Content = text, IsTTS = isTTS, Embeds = embeds.Any() ? embeds.Select(x => x.ToModel()).ToArray() : Optional<API.Embed[]>.Unspecified, AllowedMentions = allowedMentions?.ToModel() ?? Optional<API.AllowedMentions>.Unspecified, MessageComponents = components?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional<API.ActionRowComponent[]>.Unspecified };
return await InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options).ConfigureAwait(false);
return InteractionHelper.SendFollowupAsync(Discord, args, Token, Channel, options);
}
/// <inheritdoc/>

View File

@@ -20,8 +20,8 @@ namespace Discord.Rest
}
/// <inheritdoc/>
public override async Task DeleteAsync(RequestOptions options = null)
=> await InteractionHelper.DeleteGlobalCommandAsync(Discord, this).ConfigureAwait(false);
public override Task DeleteAsync(RequestOptions options = null)
=> InteractionHelper.DeleteGlobalCommandAsync(Discord, this);
/// <summary>
/// Modifies this <see cref="RestApplicationCommand"/>.

View File

@@ -28,8 +28,8 @@ namespace Discord.Rest
}
/// <inheritdoc/>
public override async Task DeleteAsync(RequestOptions options = null)
=> await InteractionHelper.DeleteGuildCommandAsync(Discord, GuildId, this).ConfigureAwait(false);
public override Task DeleteAsync(RequestOptions options = null)
=> InteractionHelper.DeleteGuildCommandAsync(Discord, GuildId, this);
/// <summary>
/// Modifies this <see cref="RestApplicationCommand"/>.

View File

@@ -4,10 +4,7 @@ namespace Discord.Rest
{
internal static class InviteHelper
{
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false);
}
public static Task DeleteAsync(IInvite invite, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.DeleteInviteAsync(invite.Code, options);
}
}

View File

@@ -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)
{

View File

@@ -188,14 +188,14 @@ namespace Discord.Rest
/// <inheritdoc />
/// <exception cref="InvalidOperationException">This operation may only be called on a <see cref="INewsChannel"/> channel.</exception>
public async Task CrosspostAsync(RequestOptions options = null)
public Task CrosspostAsync(RequestOptions options = null)
{
if (!(Channel is INewsChannel))
{
throw new InvalidOperationException("Publishing (crossposting) is only valid in news channels.");
}
await MessageHelper.CrosspostAsync(this, Discord, options);
return MessageHelper.CrosspostAsync(this, Discord, options);
}
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")})";

View File

@@ -8,11 +8,9 @@ namespace Discord.Rest
internal static class RoleHelper
{
#region General
public static async Task DeleteAsync(IRole role, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false);
}
public static Task DeleteAsync(IRole role, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options);
public static async Task<Model> ModifyAsync(IRole role, BaseDiscordClient client,
Action<RoleProperties> func, RequestOptions options)
{

View File

@@ -10,8 +10,7 @@ namespace Discord.Rest
{
internal static class UserHelper
{
public static async Task<Model> ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<SelfUserProperties> func,
RequestOptions options)
public static Task<Model> ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<SelfUserProperties> func, RequestOptions options)
{
var args = new SelfUserProperties();
func(args);
@@ -24,7 +23,7 @@ namespace Discord.Rest
if (!apiArgs.Avatar.IsSpecified && user.AvatarId != null)
apiArgs.Avatar = new ImageModel(user.AvatarId);
return await client.ApiClient.ModifySelfAsync(apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifySelfAsync(apiArgs, options);
}
public static async Task<GuildUserProperties> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<GuildUserProperties> func,
RequestOptions options)
@@ -66,11 +65,8 @@ namespace Discord.Rest
return args;
}
public static async Task KickAsync(IGuildUser user, BaseDiscordClient client,
string reason, RequestOptions options)
{
await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, reason, options).ConfigureAwait(false);
}
public static Task KickAsync(IGuildUser user, BaseDiscordClient client, string reason, RequestOptions options)
=> client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, reason, options);
public static async Task<RestDMChannel> CreateDMChannelAsync(IUser user, BaseDiscordClient client,
RequestOptions options)
@@ -91,7 +87,7 @@ namespace Discord.Rest
await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false);
}
public static async Task SetTimeoutAsync(IGuildUser user, BaseDiscordClient client, TimeSpan span, RequestOptions options)
public static Task SetTimeoutAsync(IGuildUser user, BaseDiscordClient client, TimeSpan span, RequestOptions options)
{
if (span.TotalDays > 28) // As its double, an exact value of 28 can be accepted.
throw new ArgumentOutOfRangeException(nameof(span), "Offset cannot be more than 28 days from the current date.");
@@ -101,16 +97,16 @@ namespace Discord.Rest
{
TimedOutUntil = DateTimeOffset.UtcNow.Add(span)
};
await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options);
}
public static async Task RemoveTimeOutAsync(IGuildUser user, BaseDiscordClient client, RequestOptions options)
public static Task RemoveTimeOutAsync(IGuildUser user, BaseDiscordClient client, RequestOptions options)
{
var apiArgs = new API.Rest.ModifyGuildMemberParams()
{
TimedOutUntil = null
};
await client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options).ConfigureAwait(false);
return client.ApiClient.ModifyGuildMemberAsync(user.Guild.Id, user.Id, apiArgs, options);
}
}
}

View File

@@ -8,7 +8,7 @@ namespace Discord.Rest
{
internal static class WebhookHelper
{
public static async Task<Model> ModifyAsync(IWebhook webhook, BaseDiscordClient client,
public static Task<Model> ModifyAsync(IWebhook webhook, BaseDiscordClient client,
Action<WebhookProperties> func, RequestOptions options)
{
var args = new WebhookProperties();
@@ -27,11 +27,10 @@ namespace Discord.Rest
else if (args.ChannelId.IsSpecified)
apiArgs.ChannelId = args.ChannelId.Value;
return await client.ApiClient.ModifyWebhookAsync(webhook.Id, apiArgs, options).ConfigureAwait(false);
}
public static async Task DeleteAsync(IWebhook webhook, BaseDiscordClient client, RequestOptions options)
{
await client.ApiClient.DeleteWebhookAsync(webhook.Id, options).ConfigureAwait(false);
return client.ApiClient.ModifyWebhookAsync(webhook.Id, apiArgs, options);
}
public static Task DeleteAsync(IWebhook webhook, BaseDiscordClient client, RequestOptions options)
=> client.ApiClient.DeleteWebhookAsync(webhook.Id, options);
}
}

View File

@@ -97,7 +97,7 @@ namespace Discord.Net.Rest
}
/// <exception cref="InvalidOperationException">Unsupported param type.</exception>
public async Task<RestResponse> SendAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, CancellationToken cancelToken, bool headerOnly, string reason = null,
public Task<RestResponse> SendAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartParams, CancellationToken cancelToken, bool headerOnly, string reason = null,
IEnumerable<KeyValuePair<string, IEnumerable<string>>> requestHeaders = null)
{
string uri = Path.Combine(_baseUrl, endpoint);
@@ -162,7 +162,7 @@ namespace Discord.Net.Rest
}
restRequest.Content = content;
return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false);
return SendInternalAsync(restRequest, cancelToken, headerOnly);
}
private async Task<RestResponse> SendInternalAsync(HttpRequestMessage request, CancellationToken cancelToken, bool headerOnly)

View File

@@ -99,7 +99,7 @@ namespace Discord.Net.Queue
createdTokenSource?.Dispose();
}
internal async Task EnterGlobalAsync(int id, RestRequest request)
internal Task EnterGlobalAsync(int id, RestRequest request)
{
int millis = (int)Math.Ceiling((_waitUntil - DateTimeOffset.UtcNow).TotalMilliseconds);
if (millis > 0)
@@ -107,19 +107,23 @@ namespace Discord.Net.Queue
#if DEBUG_LIMITS
Debug.WriteLine($"[{id}] Sleeping {millis} ms (Pre-emptive) [Global]");
#endif
await Task.Delay(millis).ConfigureAwait(false);
return Task.Delay(millis);
}
return Task.CompletedTask;
}
internal void PauseGlobal(RateLimitInfo info)
{
_waitUntil = DateTimeOffset.UtcNow.AddMilliseconds(info.RetryAfter.Value + (info.Lag?.TotalMilliseconds ?? 0.0));
}
internal async Task EnterGlobalAsync(int id, WebSocketRequest request)
internal Task EnterGlobalAsync(int id, WebSocketRequest request)
{
//If this is a global request (unbucketed), it'll be dealt in EnterAsync
var requestBucket = GatewayBucket.Get(request.Options.BucketId);
if (requestBucket.Type == GatewayBucketType.Unbucketed)
return;
return Task.CompletedTask;
//It's not a global request, so need to remove one from global (per-session)
var globalBucketType = GatewayBucket.Get(GatewayBucketType.Unbucketed);
@@ -127,7 +131,7 @@ namespace Discord.Net.Queue
options.BucketId = globalBucketType.Id;
var globalRequest = new WebSocketRequest(null, null, false, false, options);
var globalBucket = GetOrCreateBucket(options, globalRequest);
await globalBucket.TriggerAsync(id, globalRequest);
return globalBucket.TriggerAsync(id, globalRequest);
}
private RequestBucket GetOrCreateBucket(RequestOptions options, IRequest request)
@@ -141,10 +145,9 @@ namespace Discord.Net.Queue
}
return (RequestBucket)obj;
}
internal async Task RaiseRateLimitTriggered(BucketId bucketId, RateLimitInfo? info, string endpoint)
{
await RateLimitTriggered(bucketId, info, endpoint).ConfigureAwait(false);
}
internal Task RaiseRateLimitTriggered(BucketId bucketId, RateLimitInfo? info, string endpoint)
=> RateLimitTriggered(bucketId, info, endpoint);
internal (RequestBucket, BucketId) UpdateBucketHash(BucketId id, string discordHash)
{
if (!id.IsHashBucket)

View File

@@ -13,9 +13,7 @@ namespace Discord.Net.Queue
Json = json;
}
public override async Task<RestResponse> SendAsync()
{
return await Client.SendAsync(Method, Endpoint, Json, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason).ConfigureAwait(false);
}
public override Task<RestResponse> SendAsync()
=> Client.SendAsync(Method, Endpoint, Json, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason);
}
}

View File

@@ -14,9 +14,7 @@ namespace Discord.Net.Queue
MultipartParams = multipartParams;
}
public override async Task<RestResponse> SendAsync()
{
return await Client.SendAsync(Method, Endpoint, MultipartParams, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason).ConfigureAwait(false);
}
public override Task<RestResponse> SendAsync()
=> Client.SendAsync(Method, Endpoint, MultipartParams, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason);
}
}

View File

@@ -29,9 +29,7 @@ namespace Discord.Net.Queue
Promise = new TaskCompletionSource<Stream>();
}
public virtual async Task<RestResponse> SendAsync()
{
return await Client.SendAsync(Method, Endpoint, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason, Options.RequestHeaders).ConfigureAwait(false);
}
public virtual Task<RestResponse> SendAsync()
=> Client.SendAsync(Method, Endpoint, Options.CancelToken, Options.HeaderOnly, Options.AuditLogReason, Options.RequestHeaders);
}
}

View File

@@ -30,9 +30,7 @@ namespace Discord.Net.Queue
Promise = new TaskCompletionSource<Stream>();
}
public async Task SendAsync()
{
await Client.SendAsync(Data, 0, Data.Length, IsText).ConfigureAwait(false);
}
public Task SendAsync()
=> Client.SendAsync(Data, 0, Data.Length, IsText);
}
}