From 867380439b738a07b27ab7f836fbeb9893f8a696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Hjorth=C3=B8j?= Date: Tue, 21 Sep 2021 15:57:07 +0200 Subject: [PATCH] Regions discord.net.rest (#168) * BaseDiscordClient * ClientHelper * DiscordRestApiClient * DiscordRestClient * DiscordContractResolver * RestGuildUser * RestUser * RestWebhookUser * RestWebhook * RestRole * RoleHelper * RestApplicationCommandOption * InteractionHelper * GuildHelper * RestGuild --- src/Discord.Net.Rest/BaseDiscordClient.cs | 5 +- src/Discord.Net.Rest/ClientHelper.cs | 3 +- src/Discord.Net.Rest/DiscordRestApiClient.cs | 91 +++++++++++++------ src/Discord.Net.Rest/DiscordRestClient.cs | 6 +- .../Entities/Guilds/GuildHelper.cs | 36 +++++--- .../Entities/Guilds/RestGuild.cs | 35 ++++--- .../Interactions/InteractionHelper.cs | 14 ++- .../RestApplicationCommandOption.cs | 5 +- .../Entities/Roles/RestRole.cs | 6 +- .../Entities/Roles/RoleHelper.cs | 3 +- .../Entities/Users/RestGuildUser.cs | 8 +- .../Entities/Users/RestUser.cs | 5 +- .../Entities/Users/RestWebhookUser.cs | 8 +- .../Entities/Webhooks/RestWebhook.cs | 5 +- .../Net/Converters/DiscordContractResolver.cs | 5 +- 15 files changed, 164 insertions(+), 71 deletions(-) diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index 93b82c929..431859a10 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -10,6 +10,7 @@ namespace Discord.Rest { public abstract class BaseDiscordClient : IDiscordClient { + #region BaseDiscordClient public event Func Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } } internal readonly AsyncEvent> _logEvent = new AsyncEvent>(); @@ -155,8 +156,9 @@ namespace Discord.Rest /// public Task GetBotGatewayAsync(RequestOptions options = null) => ClientHelper.GetBotGatewayAsync(this, options); + #endregion - //IDiscordClient + #region IDiscordClient /// ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; /// @@ -235,5 +237,6 @@ namespace Discord.Rest /// Task IDiscordClient.StopAsync() => Task.Delay(0); + #endregion } } diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 2fc382900..4581219bb 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -10,7 +10,7 @@ namespace Discord.Rest { internal static class ClientHelper { - //Applications + #region Applications public static async Task GetApplicationInfoAsync(BaseDiscordClient client, RequestOptions options) { var model = await client.ApiClient.GetMyApplicationAsync(options).ConfigureAwait(false); @@ -263,5 +263,6 @@ namespace Discord.Rest public static Task RemoveRoleAsync(BaseDiscordClient client, ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) => client.ApiClient.RemoveRoleAsync(guildId, userId, roleId, options); + #endregion } } diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index ead0c0e8a..0db6985b0 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -24,6 +24,7 @@ namespace Discord.API { internal class DiscordRestApiClient : IDisposable { + #region DiscordRestApiClient private static readonly ConcurrentDictionary> _bucketIdGenerators = new ConcurrentDictionary>(); public event Func SentRequest { add { _sentRequestEvent.Add(value); } remove { _sentRequestEvent.Remove(value); } } @@ -167,8 +168,9 @@ namespace Discord.API internal virtual Task ConnectInternalAsync() => Task.Delay(0); internal virtual Task DisconnectInternalAsync(Exception ex = null) => Task.Delay(0); + #endregion - //Core + #region Core internal Task SendAsync(string method, Expression> endpointExpr, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) => SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(method, ids, endpointExpr, funcName), clientBucket, options); @@ -271,15 +273,17 @@ namespace Discord.API return responseStream; } + #endregion - //Auth + #region Auth public async Task ValidateTokenAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); await SendAsync("GET", () => "auth/login", new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Gateway + #region Gateway public async Task GetGatewayAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -290,8 +294,9 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); return await SendAsync("GET", () => "gateway/bot", new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Channels + #region Channels public async Task GetChannelAsync(ulong channelId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -414,8 +419,9 @@ namespace Discord.API break; } } + #endregion - // Threads + #region Threads public async Task ModifyThreadAsync(ulong channelId, ModifyThreadParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -582,8 +588,9 @@ namespace Discord.API return await SendAsync("GET", () => $"channels/{channelId}/users/@me/threads/archived/private{query}", bucket, options: options); } + #endregion - // stage + #region Stage public async Task CreateStageInstanceAsync(CreateStageInstanceParams args, RequestOptions options = null) { @@ -658,8 +665,9 @@ namespace Discord.API await SendJsonAsync("PATCH", () => $"guilds/{guildId}/voice-states/{userId}", args, bucket, options: options).ConfigureAwait(false); } + #endregion - // roles + #region Roles public async Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -682,8 +690,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options).ConfigureAwait(false); } + #endregion - //Channel Messages + #region Channel Messages public async Task GetChannelMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -886,8 +895,9 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); return await SendJsonAsync("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); } + #endregion - // Stickers + #region Stickers public async Task GetStickerAsync(ulong id, RequestOptions options = null) { Preconditions.NotEqual(id, 0, nameof(id)); @@ -1044,8 +1054,9 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); await SendAsync("POST", () => $"channels/{channelId}/messages/{messageId}/crosspost", ids, options: options).ConfigureAwait(false); } + #endregion - //Channel Permissions + #region Channel Permissions public async Task ModifyChannelPermissionsAsync(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -1065,8 +1076,9 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); await SendAsync("DELETE", () => $"channels/{channelId}/permissions/{targetId}", ids, options: options).ConfigureAwait(false); } + #endregion - //Channel Pins + #region Channel Pins public async Task AddPinAsync(ulong channelId, ulong messageId, RequestOptions options = null) { Preconditions.GreaterThan(channelId, 0, nameof(channelId)); @@ -1094,8 +1106,9 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); return await SendAsync>("GET", () => $"channels/{channelId}/pins", ids, options: options).ConfigureAwait(false); } + #endregion - //Channel Recipients + #region Channel Recipients public async Task AddGroupRecipientAsync(ulong channelId, ulong userId, RequestOptions options = null) { Preconditions.GreaterThan(channelId, 0, nameof(channelId)); @@ -1115,8 +1128,9 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); await SendAsync("DELETE", () => $"channels/{channelId}/recipients/{userId}", ids, options: options).ConfigureAwait(false); } + #endregion - //Interactions + #region Interactions public async Task GetGlobalApplicationCommandsAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -1252,8 +1266,9 @@ namespace Discord.API return await TrySendApplicationCommand(SendJsonAsync("PUT", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands", commands, bucket, options: options)).ConfigureAwait(false); } + #endregion - //Interaction Responses + #region Interaction Responses public async Task CreateInteractionResponse(InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) { if(response.Data.IsSpecified && response.Data.Value.Content.IsSpecified) @@ -1322,8 +1337,9 @@ namespace Discord.API await SendAsync("DELETE", () => $"webhooks/{CurrentUserId}/{token}/messages/{id}", new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - // Application Command permissions + #region Application Command permissions public async Task GetGuildApplicationCommandPermissions(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1362,8 +1378,9 @@ namespace Discord.API return await SendJsonAsync("PUT", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands/permissions", permissions, new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Guilds + #region Guilds public async Task GetGuildAsync(ulong guildId, bool withCounts, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1436,8 +1453,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendAsync("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Bans + #region Guild Bans public async Task> GetGuildBansAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1488,8 +1506,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); await SendAsync("DELETE", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Widget + #region Guild Widget /// must not be equal to zero. public async Task GetGuildWidgetAsync(ulong guildId, RequestOptions options = null) { @@ -1514,8 +1533,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendJsonAsync("PATCH", () => $"guilds/{guildId}/widget", args, ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Integrations + #region Guild Integrations /// must not be equal to zero. public async Task> GetGuildIntegrationsAsync(ulong guildId, RequestOptions options = null) { @@ -1567,8 +1587,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendAsync("POST", () => $"guilds/{guildId}/integrations/{integrationId}/sync", ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Invites + #region Guild Invites /// cannot be blank. /// must not be . public async Task GetInviteAsync(string inviteId, RequestOptions options = null) @@ -1651,8 +1672,9 @@ namespace Discord.API return await SendAsync("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Guild Members + #region Guild Members public async Task AddGuildMemberAsync(ulong guildId, ulong userId, AddGuildMemberParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1750,8 +1772,9 @@ namespace Discord.API Expression> endpoint = () => $"guilds/{guildId}/members/search?limit={limit}&query={query}"; return await SendAsync>("GET", endpoint, ids, options: options).ConfigureAwait(false); } + #endregion - //Guild Roles + #region Guild Roles public async Task> GetGuildRolesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1798,8 +1821,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendJsonAsync>("PATCH", () => $"guilds/{guildId}/roles", args, ids, options: options).ConfigureAwait(false); } + #endregion - //Guild emoji + #region Guild emoji public async Task> GetGuildEmotesAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1851,8 +1875,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); await SendAsync("DELETE", () => $"guilds/{guildId}/emojis/{emoteId}", ids, options: options).ConfigureAwait(false); } + #endregion - //Users + #region Users public async Task GetUserAsync(ulong userId, RequestOptions options = null) { Preconditions.NotEqual(userId, 0, nameof(userId)); @@ -1864,8 +1889,9 @@ namespace Discord.API } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } } + #endregion - //Current User/DMs + #region Current User/DMs public async Task GetMyUserAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -1924,8 +1950,9 @@ namespace Discord.API return await SendJsonAsync("POST", () => "users/@me/channels", args, new BucketIds(), options: options).ConfigureAwait(false); } + #endregion - //Voice Regions + #region Voice Regions public async Task> GetVoiceRegionsAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); @@ -1939,8 +1966,9 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return await SendAsync>("GET", () => $"guilds/{guildId}/regions", ids, options: options).ConfigureAwait(false); } + #endregion - //Audit logs + #region Audit logs public async Task GetAuditLogsAsync(ulong guildId, GetAuditLogsParams args, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -1969,12 +1997,13 @@ namespace Discord.API .Append(args.ActionType.Value); } - // still use string interp for the query w/o params, as this is necessary for CreateBucketId + // Still use string interp for the query w/o params, as this is necessary for CreateBucketId endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}{queryArgs.ToString()}"; return await SendAsync("GET", endpoint, ids, options: options).ConfigureAwait(false); } + #endregion - //Webhooks + #region Webhooks public async Task CreateWebhookAsync(ulong channelId, CreateWebhookParams args, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -2037,8 +2066,9 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); return await SendAsync>("GET", () => $"channels/{channelId}/webhooks", ids, options: options).ConfigureAwait(false); } + #endregion - //Helpers + #region Helpers /// Client is not logged in. protected void CheckState() { @@ -2248,5 +2278,6 @@ namespace Discord.API return (expr as MemberExpression).Member.Name; } + #endregion } } diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 10a4c40a9..8254eabe9 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -12,6 +12,7 @@ namespace Discord.Rest /// public class DiscordRestClient : BaseDiscordClient, IDiscordClient { + #region DiscordRestClient private RestApplication _applicationInfo; /// @@ -138,7 +139,9 @@ namespace Discord.Rest => MessageHelper.RemoveAllReactionsAsync(channelId, messageId, this, options); public Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null) => MessageHelper.RemoveAllReactionsForEmoteAsync(channelId, messageId, emote, this, options); - //IDiscordClient +#endregion + + #region IDiscordClient /// async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync(options).ConfigureAwait(false); @@ -229,5 +232,6 @@ namespace Discord.Rest /// async Task IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options) => await ClientHelper.GetGlobalApplicationCommand(this, id, options).ConfigureAwait(false); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 73f59b566..1fb4b774a 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -14,7 +14,7 @@ namespace Discord.Rest { internal static class GuildHelper { - //General + #region General /// is null. public static async Task ModifyAsync(IGuild guild, BaseDiscordClient client, Action func, RequestOptions options) @@ -123,8 +123,9 @@ namespace Discord.Rest { await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false); } + #endregion - //Bans + #region Bans public static async Task> GetBansAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { @@ -148,8 +149,9 @@ namespace Discord.Rest { await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); } + #endregion - //Channels + #region Channels public static async Task GetChannelAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) { @@ -275,16 +277,18 @@ namespace Discord.Rest var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestCategoryChannel.Create(client, guild, model); } + #endregion - //Voice Regions + #region Voice Regions public static async Task> GetVoiceRegionsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { var models = await client.ApiClient.GetGuildVoiceRegionsAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestVoiceRegion.Create(client, x)).ToImmutableArray(); } + #endregion - //Integrations + #region Integrations public static async Task> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { @@ -298,8 +302,9 @@ namespace Discord.Rest var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args, options).ConfigureAwait(false); return RestGuildIntegration.Create(client, guild, model); } + #endregion - //Interactions + #region Interactions public static async Task> GetSlashCommandsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { @@ -312,8 +317,9 @@ namespace Discord.Rest var model = await client.ApiClient.GetGuildApplicationCommandAsync(guild.Id, id, options); return RestGuildCommand.Create(client, model, guild.Id); } + #endregion - //Invites + #region Invites public static async Task> GetInvitesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { @@ -329,8 +335,9 @@ namespace Discord.Rest inviteModel.Uses = vanityModel.Uses; return RestInviteMetadata.Create(client, guild, null, inviteModel); } + #endregion - //Roles + #region Roles /// is null. public static async Task CreateRoleAsync(IGuild guild, BaseDiscordClient client, string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options) @@ -350,8 +357,9 @@ namespace Discord.Rest return RestRole.Create(client, guild, model); } + #endregion - //Users + #region Users public static async Task AddGuildUserAsync(IGuild guild, BaseDiscordClient client, ulong userId, string accessToken, Action func, RequestOptions options) { @@ -470,8 +478,9 @@ namespace Discord.Rest var models = await client.ApiClient.SearchGuildMembersAsync(guild.Id, apiArgs, options).ConfigureAwait(false); return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray(); } + #endregion - // Audit logs + #region Audit logs public static IAsyncEnumerable> GetAuditLogsAsync(IGuild guild, BaseDiscordClient client, ulong? from, int? limit, RequestOptions options, ulong? userId = null, ActionType? actionType = null) { @@ -503,8 +512,9 @@ namespace Discord.Rest count: limit ); } + #endregion - //Webhooks + #region Webhooks public static async Task GetWebhookAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) { var model = await client.ApiClient.GetWebhookAsync(id, options: options).ConfigureAwait(false); @@ -517,8 +527,9 @@ namespace Discord.Rest var models = await client.ApiClient.GetGuildWebhooksAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestWebhook.Create(client, guild, x)).ToImmutableArray(); } + #endregion - //Emotes + #region Emotes public static async Task> GetEmotesAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { var models = await client.ApiClient.GetGuildEmotesAsync(guild.Id, options).ConfigureAwait(false); @@ -637,5 +648,6 @@ namespace Discord.Rest public static async Task DeleteStickerAsync(BaseDiscordClient client, ulong guildId, ISticker sticker, RequestOptions options = null) => await client.ApiClient.DeleteStickerAsync(guildId, sticker.Id, options).ConfigureAwait(false); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index d566afc81..a313de810 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -18,6 +18,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestGuild : RestEntity, IGuild, IUpdateable { + #region RestGuild private ImmutableDictionary _roles; private ImmutableArray _emotes; private ImmutableArray _stickers; @@ -217,8 +218,9 @@ namespace Discord.Rest WidgetChannelId = model.ChannelId; IsWidgetEnabled = model.Enabled; } + #endregion - //General + #region General /// public async Task UpdateAsync(RequestOptions options = null) => Update(await Discord.ApiClient.GetGuildAsync(Id, false, options).ConfigureAwait(false)); @@ -277,8 +279,9 @@ namespace Discord.Rest /// public Task LeaveAsync(RequestOptions options = null) => GuildHelper.LeaveAsync(this, Discord, options); + #endregion - //Interactions + #region Interactions /// /// Deletes all slash commands in the current guild. /// @@ -311,8 +314,9 @@ namespace Discord.Rest /// public Task GetSlashCommandAsync(ulong id, RequestOptions options = null) => GuildHelper.GetSlashCommandAsync(this, id, Discord, options); + #endregion - //Bans + #region Bans /// /// Gets a collection of all users banned in this guild. /// @@ -360,8 +364,9 @@ namespace Discord.Rest /// public Task RemoveBanAsync(ulong userId, RequestOptions options = null) => GuildHelper.RemoveBanAsync(this, Discord, userId, options); + #endregion - //Channels + #region Channels /// /// Gets a collection of all channels in this guild. /// @@ -697,14 +702,16 @@ namespace Discord.Rest /// public Task> GetVoiceRegionsAsync(RequestOptions options = null) => GuildHelper.GetVoiceRegionsAsync(this, Discord, options); + #endregion - //Integrations + #region Integrations public Task> GetIntegrationsAsync(RequestOptions options = null) => GuildHelper.GetIntegrationsAsync(this, Discord, options); public Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null) => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); + #endregion - //Invites + #region Invites /// /// Gets a collection of all invites in this guild. /// @@ -724,8 +731,9 @@ namespace Discord.Rest /// public Task GetVanityInviteAsync(RequestOptions options = null) => GuildHelper.GetVanityInviteAsync(this, Discord, options); + #endregion - //Roles + #region Roles /// /// Gets a role in this guild. /// @@ -765,8 +773,9 @@ namespace Discord.Rest _roles = _roles.Add(role.Id, role); return role; } + #endregion - //Users + #region Users /// /// Gets a collection of all users in this guild. /// @@ -860,8 +869,9 @@ namespace Discord.Rest /// public Task> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, RequestOptions options = null) => GuildHelper.SearchUsersAsync(this, Discord, query, limit, options); + #endregion - //Audit logs + #region Audit logs /// /// Gets the specified number of audit log entries for this guild. /// @@ -876,8 +886,9 @@ namespace Discord.Rest /// public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null) => GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType); + #endregion - //Webhooks + #region Webhooks /// /// Gets a webhook found within this guild. /// @@ -900,8 +911,9 @@ namespace Discord.Rest /// public Task> GetWebhooksAsync(RequestOptions options = null) => GuildHelper.GetWebhooksAsync(this, Discord, options); + #endregion - //Interactions + #region Interactions /// /// Gets this guilds slash commands commands /// @@ -961,6 +973,7 @@ namespace Discord.Rest /// public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; + #endregion #region Emotes /// diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index 8bc87339e..7a4b49166 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -11,6 +11,7 @@ namespace Discord.Rest { internal static class InteractionHelper { + #region InteractionHelper public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null) { return client.ApiClient.BulkOverwriteGuildApplicationCommands(guildId, new CreateApplicationCommandParams[0], options); @@ -42,8 +43,9 @@ namespace Discord.Rest RestFollowupMessage entity = RestFollowupMessage.Create(client, model, token, channel); return entity; } +#endregion - // Global commands + #region Global commands public static async Task GetGlobalCommandAsync(BaseDiscordClient client, ulong id, RequestOptions options = null) { @@ -236,8 +238,9 @@ namespace Discord.Rest await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false); } + #endregion - // Guild Commands + #region Guild Commands public static Task CreateGuildCommand(BaseDiscordClient client, ulong guildId, Action func, RequestOptions options) where TArg : ApplicationCommandProperties { @@ -324,8 +327,9 @@ namespace Discord.Rest return DeleteGlobalCommand(client, command, options); } } + #endregion - // Responses + #region Responses public static async Task ModifyFollowupMessage(BaseDiscordClient client, RestFollowupMessage message, Action func, RequestOptions options = null) { @@ -412,8 +416,9 @@ namespace Discord.Rest public static async Task DeletedInteractionResponse(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null) => await client.ApiClient.DeleteInteractionFollowupMessage(message.Id, message.Token, options); + #endregion - // Guild permissions + #region Guild permissions public static async Task> GetGuildCommandPermissionsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options) { @@ -506,5 +511,6 @@ namespace Discord.Rest x => new GuildApplicationCommandPermission(x.Id, x.ApplicationId, x.GuildId, x.Permissions.Select( y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)).ToArray())).ToArray(); } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs index b135ae578..78f9c0e30 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs @@ -13,6 +13,7 @@ namespace Discord.Rest /// public class RestApplicationCommandOption : IApplicationCommandOption { + #region RestApplicationCommandOption /// public ApplicationCommandOptionType Type { get; private set; } @@ -67,11 +68,13 @@ namespace Discord.Rest ? model.Choices.Value.Select(x => new RestApplicationCommandChoice(x)).ToImmutableArray() : null; } + #endregion - //IApplicationCommandOption + #region IApplicationCommandOption IReadOnlyCollection IApplicationCommandOption.Options => Options; IReadOnlyCollection IApplicationCommandOption.Choices => Choices; + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs index aa33ae7e5..03e954f47 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs @@ -11,6 +11,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestRole : RestEntity, IRole { + #region RestRole internal IGuild Guild { get; } /// public Color Color { get; private set; } @@ -64,7 +65,7 @@ namespace Discord.Rest /// public async Task ModifyAsync(Action func, RequestOptions options = null) - { + { var model = await RoleHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } @@ -83,8 +84,9 @@ namespace Discord.Rest /// public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; + #endregion - //IRole + #region IRole /// IGuild IRole.Guild { diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index 73ab7ca31..8d525d4c3 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -7,7 +7,7 @@ namespace Discord.Rest { internal static class RoleHelper { - //General + #region General public static async Task DeleteAsync(IRole role, BaseDiscordClient client, RequestOptions options) { @@ -36,5 +36,6 @@ namespace Discord.Rest } return model; } + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs index 9ad36a074..556e5e124 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs @@ -14,6 +14,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestGuildUser : RestUser, IGuildUser { + #region RestGuildUser private long? _premiumSinceTicks; private long? _joinedAtTicks; private ImmutableArray _roleIds; @@ -155,8 +156,9 @@ namespace Discord.Rest var guildPerms = GuildPermissions; return new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, guildPerms.RawValue)); } +#endregion - //IGuildUser + #region IGuildUser /// IGuild IGuildUser.Guild { @@ -167,8 +169,9 @@ namespace Discord.Rest throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); } } + #endregion - //IVoiceState + #region IVoiceState /// bool IVoiceState.IsSelfDeafened => false; /// @@ -183,5 +186,6 @@ namespace Discord.Rest bool IVoiceState.IsStreaming => false; /// DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null; + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs index 618804fef..7304f5f39 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs @@ -13,6 +13,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestUser : RestEntity, IUser, IUpdateable { + #region RestUser /// public bool IsBot { get; private set; } /// @@ -116,10 +117,12 @@ namespace Discord.Rest /// public override string ToString() => $"{Username}#{Discriminator}"; private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; + #endregion - //IUser + #region IUser /// async Task IUser.CreateDMChannelAsync(RequestOptions options) => await CreateDMChannelAsync(options).ConfigureAwait(false); + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs b/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs index 40a173976..561cd92ee 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs @@ -10,6 +10,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestWebhookUser : RestUser, IWebhookUser { + #region RestWebhookUser /// public ulong WebhookId { get; } internal IGuild Guild { get; } @@ -33,8 +34,9 @@ namespace Discord.Rest entity.Update(model); return entity; } +#endregion - //IGuildUser + #region IGuildUser /// IGuild IGuildUser.Guild { @@ -91,8 +93,9 @@ namespace Discord.Rest /// Task IGuildUser.RemoveRolesAsync(IEnumerable roles, RequestOptions options) => throw new NotSupportedException("Roles are not supported on webhook users."); + #endregion - //IVoiceState + #region IVoiceState /// bool IVoiceState.IsDeafened => false; /// @@ -111,5 +114,6 @@ namespace Discord.Rest bool IVoiceState.IsStreaming => false; /// DateTimeOffset? IVoiceState.RequestToSpeakTimestamp => null; + #endregion } } diff --git a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs index 5ae09fde0..f40b786cd 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs @@ -8,6 +8,7 @@ namespace Discord.Rest [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public class RestWebhook : RestEntity, IWebhook, IUpdateable { + #region RestWebhook internal IGuild Guild { get; private set; } internal ITextChannel Channel { get; private set; } @@ -95,8 +96,9 @@ namespace Discord.Rest public override string ToString() => $"Webhook: {Name}:{Id}"; private string DebuggerDisplay => $"Webhook: {Name} ({Id})"; + #endregion - //IWebhook + #region IWebhook /// IGuild IWebhook.Guild => Guild ?? throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); @@ -106,5 +108,6 @@ namespace Discord.Rest /// Task IWebhook.ModifyAsync(Action func, RequestOptions options) => ModifyAsync(func, options); + #endregion } } diff --git a/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs b/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs index 5981a266e..feea164f9 100644 --- a/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs +++ b/src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs @@ -10,6 +10,7 @@ namespace Discord.Net.Converters { internal class DiscordContractResolver : DefaultContractResolver { + #region DiscordContractResolver private static readonly TypeInfo _ienumerable = typeof(IEnumerable).GetTypeInfo(); private static readonly MethodInfo _shouldSerialize = typeof(DiscordContractResolver).GetTypeInfo().GetDeclaredMethod("ShouldSerialize"); @@ -57,8 +58,9 @@ namespace Discord.Net.Converters else if (genericType == typeof(EntityOrId<>)) return MakeGenericConverter(property, propInfo, typeof(UInt64EntityOrIdConverter<>), type.GenericTypeArguments[0], depth); } +#endregion - //Primitives + #region Primitives bool hasInt53 = propInfo.GetCustomAttribute() != null; if (!hasInt53) { @@ -107,5 +109,6 @@ namespace Discord.Net.Converters var innerConverter = GetConverter(property, propInfo, innerType, depth + 1); return genericType.DeclaredConstructors.First().Invoke(new object[] { innerConverter }) as JsonConverter; } + #endregion } }