From 0b6838fd01cc932010d1a1cf5b549419e4f0105b Mon Sep 17 00:00:00 2001 From: Paulo Date: Mon, 19 Jul 2021 08:48:07 -0300 Subject: [PATCH] Add missing rest endpoints Add guild template, invite, stage instance, user, voice, and webhhok rest endpoints --- src/Models/Channels/Channel.cs | 4 +- src/Models/Channels/StageInstance.cs | 10 + src/Models/Guilds/Guild.cs | 10 + src/Models/Guilds/GuildTemplate.cs | 20 + src/Models/Webhooks/Webhook.cs | 10 + src/Rest/DiscordRestClient.cs | 295 +++++++++ src/Rest/Net/IDiscordRestApi.cs | 680 ++++++++++++++++++++- src/Rest/Net/Requests/Channels/CreateDMParams.cs | 21 + .../Requests/Channels/CreateStageInstanceParams.cs | 36 ++ .../Requests/Channels/ModifyStageInstanceParams.cs | 30 + .../Requests/Guilds/CreateGuildTemplateParams.cs | 32 + .../Guilds/CreateGuildfromGuildTemplateParams.cs | 30 + .../Requests/Guilds/ModifyGuildTemplateParams.cs | 32 + src/Rest/Net/Requests/Invites/GetInviteParams.cs | 25 + .../Requests/Users/GetCurrentUserGuildsParams.cs | 35 ++ .../Net/Requests/Users/ModifyCurrentUserParams.cs | 28 + .../Net/Requests/Webhooks/CreateWebhookParams.cs | 30 + .../Requests/Webhooks/EditWebhookMessageParams.cs | 54 ++ .../Net/Requests/Webhooks/ExecuteWebhookParams.cs | 78 +++ .../Net/Requests/Webhooks/ModifyWebhookParams.cs | 36 ++ .../Webhooks/ModifyWebhookWithTokenParams.cs | 30 + 21 files changed, 1515 insertions(+), 11 deletions(-) create mode 100644 src/Rest/Net/Requests/Channels/CreateDMParams.cs create mode 100644 src/Rest/Net/Requests/Channels/CreateStageInstanceParams.cs create mode 100644 src/Rest/Net/Requests/Channels/ModifyStageInstanceParams.cs create mode 100644 src/Rest/Net/Requests/Guilds/CreateGuildTemplateParams.cs create mode 100644 src/Rest/Net/Requests/Guilds/CreateGuildfromGuildTemplateParams.cs create mode 100644 src/Rest/Net/Requests/Guilds/ModifyGuildTemplateParams.cs create mode 100644 src/Rest/Net/Requests/Invites/GetInviteParams.cs create mode 100644 src/Rest/Net/Requests/Users/GetCurrentUserGuildsParams.cs create mode 100644 src/Rest/Net/Requests/Users/ModifyCurrentUserParams.cs create mode 100644 src/Rest/Net/Requests/Webhooks/CreateWebhookParams.cs create mode 100644 src/Rest/Net/Requests/Webhooks/EditWebhookMessageParams.cs create mode 100644 src/Rest/Net/Requests/Webhooks/ExecuteWebhookParams.cs create mode 100644 src/Rest/Net/Requests/Webhooks/ModifyWebhookParams.cs create mode 100644 src/Rest/Net/Requests/Webhooks/ModifyWebhookWithTokenParams.cs diff --git a/src/Models/Channels/Channel.cs b/src/Models/Channels/Channel.cs index 786b3c60a..eac73142a 100644 --- a/src/Models/Channels/Channel.cs +++ b/src/Models/Channels/Channel.cs @@ -32,12 +32,12 @@ namespace Discord.Net.Models public const int MaxChannelTopicLength = 1024; /// - /// Minimum langth of a channel topic. + /// Minimum duration to rate limit per user. /// public const int MinRateLimitPerUserDuration = 0; /// - /// Maximum langth of a channel topic. + /// Maximum duration to rate limit per user. /// public const int MaxRateLimitPerUserDuration = 21600; diff --git a/src/Models/Channels/StageInstance.cs b/src/Models/Channels/StageInstance.cs index 5263243b1..7e29c956d 100644 --- a/src/Models/Channels/StageInstance.cs +++ b/src/Models/Channels/StageInstance.cs @@ -11,6 +11,16 @@ namespace Discord.Net.Models public record StageInstance { /// + /// Minimum langth of a stage channel topic. + /// + public const int MinStageChannelTopicLength = 1; + + /// + /// Maximum langth of a stage channel topic. + /// + public const int MaxStageChannelTopicLength = 120; + + /// /// The id of this . /// [JsonPropertyName("id")] diff --git a/src/Models/Guilds/Guild.cs b/src/Models/Guilds/Guild.cs index a938801e7..12af172cc 100644 --- a/src/Models/Guilds/Guild.cs +++ b/src/Models/Guilds/Guild.cs @@ -42,6 +42,16 @@ namespace Discord.Net.Models public const int MaxUserLimitToList = 1000; /// + /// Minimum limit of guilds to list. + /// + public const int MinGetGuildsAmount = 1; + + /// + /// Maximum limit of guilds to list. + /// + public const int MaxGetGuildsAmount = 200; + + /// /// id. /// [JsonPropertyName("id")] diff --git a/src/Models/Guilds/GuildTemplate.cs b/src/Models/Guilds/GuildTemplate.cs index 1a14433d1..599b2cc1e 100644 --- a/src/Models/Guilds/GuildTemplate.cs +++ b/src/Models/Guilds/GuildTemplate.cs @@ -12,6 +12,26 @@ namespace Discord.Net.Models public record GuildTemplate { /// + /// Minimum langth of a template name. + /// + public const int MinTemplateNameLength = 1; + + /// + /// Maximum langth of a template name. + /// + public const int MaxTemplateNameLength = 100; + + /// + /// Minimum langth of a template description. + /// + public const int MinTemplateDescriptionLength = 0; + + /// + /// Maximum langth of a template description. + /// + public const int MaxTemplateDescriptionLength = 120; + + /// /// The template code (unique ID). /// [JsonPropertyName("code")] diff --git a/src/Models/Webhooks/Webhook.cs b/src/Models/Webhooks/Webhook.cs index a3267abd3..d36223853 100644 --- a/src/Models/Webhooks/Webhook.cs +++ b/src/Models/Webhooks/Webhook.cs @@ -11,6 +11,16 @@ namespace Discord.Net.Models public record Webhook { /// + /// Maximum langth of a webhook name. + /// + public const int MinNameLength = 1; + + /// + /// Maximum langth of a webhook name. + /// + public const int MaxNameLength = 80; + + /// /// The id of the . /// [JsonPropertyName("id")] diff --git a/src/Rest/DiscordRestClient.cs b/src/Rest/DiscordRestClient.cs index a3a8cb108..92c7e5642 100644 --- a/src/Rest/DiscordRestClient.cs +++ b/src/Rest/DiscordRestClient.cs @@ -771,5 +771,300 @@ namespace Discord.Net } #endregion Guild + + #region Guild Template + + /// + public Task GetGuildTemplateAsync(string templateCode, CancellationToken cancellationToken = default) + { + Preconditions.NotNullOrEmpty(templateCode, nameof(templateCode)); + return _api.GetGuildTemplateAsync(templateCode, cancellationToken); + } + + /// + public Task CreateGuildfromGuildTemplateAsync(string templateCode, CreateGuildfromGuildTemplateParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotNullOrEmpty(templateCode, nameof(templateCode)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.CreateGuildfromGuildTemplateAsync(templateCode, args, cancellationToken); + } + + /// + public Task> GetGuildTemplatesAsync(Snowflake guildId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(guildId, nameof(guildId)); + return _api.GetGuildTemplatesAsync(guildId, cancellationToken); + } + + /// + public Task CreateGuildTemplateAsync(Snowflake guildId, CreateGuildTemplateParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(guildId, nameof(guildId)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.CreateGuildTemplateAsync(guildId, args, cancellationToken); + } + + /// + public Task SyncGuildTemplateAsync(Snowflake guildId, string templateCode, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(guildId, nameof(guildId)); + Preconditions.NotNullOrEmpty(templateCode, nameof(templateCode)); + return _api.SyncGuildTemplateAsync(guildId, templateCode, cancellationToken); + } + + /// + public Task ModifyGuildTemplateAsync(Snowflake guildId, string templateCode, ModifyGuildTemplateParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(guildId, nameof(guildId)); + Preconditions.NotNullOrEmpty(templateCode, nameof(templateCode)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.ModifyGuildTemplateAsync(guildId, templateCode, args, cancellationToken); + } + + /// + public Task DeleteGuildTemplateAsync(Snowflake guildId, string templateCode, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(guildId, nameof(guildId)); + Preconditions.NotNullOrEmpty(templateCode, nameof(templateCode)); + return _api.DeleteGuildTemplateAsync(guildId, templateCode, cancellationToken); + } + + #endregion Guild Template + + #region Invite + + /// + public Task GetInviteAsync(string inviteCode, GetInviteParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotNullOrEmpty(inviteCode, nameof(inviteCode)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.GetInviteAsync(inviteCode, args, cancellationToken); + } + + /// + public Task DeleteInviteAsync(string inviteCode, CancellationToken cancellationToken = default) + { + Preconditions.NotNullOrEmpty(inviteCode, nameof(inviteCode)); + return _api.DeleteInviteAsync(inviteCode, cancellationToken); + } + + #endregion Invite + + #region Stage Instance + + /// + public Task CreateStageInstanceAsync(CreateStageInstanceParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.CreateStageInstanceAsync(args, cancellationToken); + } + + /// + public Task GetStageInstanceAsync(Snowflake channelId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(channelId, nameof(channelId)); + return _api.GetStageInstanceAsync(channelId, cancellationToken); + } + + /// + public Task ModifyStageInstanceAsync(Snowflake channelId, ModifyStageInstanceParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(channelId, nameof(channelId)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.ModifyStageInstanceAsync(channelId, args, cancellationToken); + } + + /// + public Task DeleteStageInstanceAsync(Snowflake channelId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(channelId, nameof(channelId)); + return _api.DeleteStageInstanceAsync(channelId, cancellationToken); + } + + #endregion Stage Instance + + #region User + + /// + public Task GetCurrentUserAsync(CancellationToken cancellationToken = default) + { + return _api.GetCurrentUserAsync(cancellationToken); + } + + /// + public Task GetUserAsync(Snowflake userId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(userId, nameof(userId)); + return _api.GetUserAsync(userId, cancellationToken); + } + + /// + public Task ModifyCurrentUserAsync(ModifyCurrentUserParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.ModifyCurrentUserAsync(args, cancellationToken); + } + + /// + public Task> GetCurrentUserGuildsAsync(GetCurrentUserGuildsParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.GetCurrentUserGuildsAsync(args, cancellationToken); + } + + /// + public Task LeaveGuildAsync(Snowflake guildId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(guildId, nameof(guildId)); + return _api.LeaveGuildAsync(guildId, cancellationToken); + } + + /// + public Task CreateDMAsync(CreateDMParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.CreateDMAsync(args, cancellationToken); + } + + /// + public Task> GetUserConnectionsAsync(CancellationToken cancellationToken = default) + { + return _api.GetUserConnectionsAsync(cancellationToken); + } + + #endregion User + + #region Voice + + /// + public Task> ListVoiceRegionsAsync(CancellationToken cancellationToken = default) + { + return _api.ListVoiceRegionsAsync(cancellationToken); + } + + #endregion Voice + + #region Webhook + + /// + public Task CreateWebhookAsync(Snowflake channelId, CreateWebhookParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(channelId, nameof(channelId)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.CreateWebhookAsync(channelId, args, cancellationToken); + } + + /// + public Task> GetChannelWebhooksAsync(Snowflake channelId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(channelId, nameof(channelId)); + return _api.GetChannelWebhooksAsync(channelId, cancellationToken); + } + + /// + public Task> GetGuildWebhooksAsync(Snowflake guildId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(guildId, nameof(guildId)); + return _api.GetGuildWebhooksAsync(guildId, cancellationToken); + } + + /// + public Task GetWebhookAsync(Snowflake webhookId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(webhookId, nameof(webhookId)); + return _api.GetWebhookAsync(webhookId, cancellationToken); + } + + /// + public Task GetWebhookAsync(Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(webhookToken, nameof(webhookToken)); + return _api.GetWebhookAsync(webhookId, webhookToken, cancellationToken); + } + + /// + public Task ModifyWebhookAsync(Snowflake webhookId, ModifyWebhookParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.ModifyWebhookAsync(webhookId, args, cancellationToken); + } + + /// + public Task ModifyWebhookAsync(Snowflake webhookId, string webhookToken, ModifyWebhookWithTokenParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.ModifyWebhookAsync(webhookId, webhookToken, args, cancellationToken); + } + + /// + public Task DeleteWebhookAsync(Snowflake webhookId, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(webhookId, nameof(webhookId)); + return _api.DeleteWebhookAsync(webhookId, cancellationToken); + } + + /// + public Task DeleteWebhookAsync(Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(webhookToken, nameof(webhookToken)); + return _api.DeleteWebhookAsync(webhookId, webhookToken, cancellationToken); + } + + /// + public Task ExecuteWebhookAsync(Snowflake webhookId, string webhookToken, ExecuteWebhookParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(webhookToken, nameof(webhookToken)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.ExecuteWebhookAsync(webhookId, webhookToken, args, cancellationToken); + } + + /// + public Task GetWebhookMessageAsync(Snowflake messageId, Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(messageId, nameof(messageId)); + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(webhookToken, nameof(webhookToken)); + return _api.GetWebhookMessageAsync(messageId, webhookId, webhookToken, cancellationToken); + } + + /// + public Task EditWebhookMessageAsync(Snowflake messageId, Snowflake webhookId, string webhookToken, EditWebhookMessageParams args, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(messageId, nameof(messageId)); + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(webhookToken, nameof(webhookToken)); + Preconditions.NotNull(args, nameof(args)); + args.Validate(); + return _api.EditWebhookMessageAsync(messageId, webhookId, webhookToken, args, cancellationToken); + } + + /// + public Task DeleteWebhookMessageAsync(Snowflake messageId, Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default) + { + Preconditions.NotZero(messageId, nameof(messageId)); + Preconditions.NotZero(webhookId, nameof(webhookId)); + Preconditions.NotNull(webhookToken, nameof(webhookToken)); + return _api.DeleteWebhookMessageAsync(messageId, webhookId, webhookToken, cancellationToken); + } + + #endregion Webhook } } diff --git a/src/Rest/Net/IDiscordRestApi.cs b/src/Rest/Net/IDiscordRestApi.cs index a84933fc3..80fbf31ae 100644 --- a/src/Rest/Net/IDiscordRestApi.cs +++ b/src/Rest/Net/IDiscordRestApi.cs @@ -153,7 +153,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains an array of s from the . + /// A task that contains a collection of s from the . /// Task> GetChannelMessagesAsync(Snowflake channelId, GetChannelMessagesParams args, CancellationToken cancellationToken = default); @@ -193,7 +193,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains the created. + /// A task that contains the created . /// Task CreateMessageAsync(Snowflake channelId, CreateMessageParams args, CancellationToken cancellationToken = default); @@ -311,7 +311,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains an array of s that reacted with + /// A task that contains a collection of s that reacted with /// the provided . /// Task> GetReactionsAsync(Snowflake channelId, Snowflake messageId, Emoji emoji, GetReactionsParams args, CancellationToken cancellationToken = default); @@ -462,7 +462,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains an array of s. + /// A task that contains a collection of s. /// Task> GetChannelInvitesAsync(Snowflake channelId, CancellationToken cancellationToken = default); @@ -553,7 +553,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains an array of all pinned s. + /// A task that contains a collection of all pinned s. /// Task> GetPinnedMessagesAsync(Snowflake channelId, CancellationToken cancellationToken = default); @@ -776,7 +776,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains an array of s that are part of the + /// A task that contains a collection of s that are part of the /// specified . /// Task> ListThreadMembersAsync(Snowflake channelId, CancellationToken cancellationToken = default); @@ -879,7 +879,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains an array of s. + /// A task that contains a collection of s. /// Task> ListGuildEmojisAsync(Snowflake guildId, Emoji emoji, CancellationToken cancellationToken = default); @@ -1158,7 +1158,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains the returned collection of s. + /// A task that contains a collection of s. /// Task> ListGuildMembersAsync(Snowflake guildId, ListGuildMembersParams args, CancellationToken cancellationToken = default); @@ -1178,7 +1178,7 @@ namespace Discord.Net.Rest /// Cancellation token for the request. /// /// - /// A task that contains the returned collection of s. + /// A task that contains a collection of s. /// Task> SearchGuildMembersAsync(Snowflake guildId, SearchGuildMembersParams args, CancellationToken cancellationToken = default); @@ -1758,5 +1758,667 @@ namespace Discord.Net.Rest Task ModifyUserVoiceStateAsync(Snowflake guildId, Snowflake userId, ModifyUserVoiceStateParams args, CancellationToken cancellationToken = default); #endregion Guild + + #region Guild Template + + /// + /// Gets a for the given code. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the requested ; or if it's not found. + /// + Task GetGuildTemplateAsync(string templateCode, CancellationToken cancellationToken = default); + + /// + /// Creates a new based on a template. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the created . + /// + Task CreateGuildfromGuildTemplateAsync(string templateCode, CreateGuildfromGuildTemplateParams args, CancellationToken cancellationToken = default); + + /// + /// Gets all s within a . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains a collection of s. + /// + Task> GetGuildTemplatesAsync(Snowflake guildId, CancellationToken cancellationToken = default); + + /// + /// Creates a for the . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the created . + /// + Task CreateGuildTemplateAsync(Snowflake guildId, CreateGuildTemplateParams args, CancellationToken cancellationToken = default); + + /// + /// Syncs the to the guild's current state. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the updated . + /// + Task SyncGuildTemplateAsync(Snowflake guildId, string templateCode, CancellationToken cancellationToken = default); + + /// + /// Modifies the 's metadata. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The identifier. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the updated . + /// + Task ModifyGuildTemplateAsync(Snowflake guildId, string templateCode, ModifyGuildTemplateParams args, CancellationToken cancellationToken = default); + + /// + /// Deletes the . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the deleted . + /// + Task DeleteGuildTemplateAsync(Snowflake guildId, string templateCode, CancellationToken cancellationToken = default); + + #endregion Guild Template + + #region Invite + + /// + /// Gets an for the given code. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains an ; or if it is not found. + /// + Task GetInviteAsync(string inviteCode, GetInviteParams args, CancellationToken cancellationToken = default); + + /// + /// Deletes an . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the deleted . + /// + Task DeleteInviteAsync(string inviteCode, CancellationToken cancellationToken = default); + + #endregion Invite + + #region Stage Instance + + /// + /// Creates a new associated to a . + /// + /// + /// + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the created . + /// + Task CreateStageInstanceAsync(CreateStageInstanceParams args, CancellationToken cancellationToken = default); + + /// + /// Gets the associated with the , if it exists. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the created ; or if it does not exist. + /// + Task GetStageInstanceAsync(Snowflake channelId, CancellationToken cancellationToken = default); + + /// + /// Modifies an existing . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the updated . + /// + Task ModifyStageInstanceAsync(Snowflake channelId, ModifyStageInstanceParams args, CancellationToken cancellationToken = default); + + /// + /// Deletes an . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that represents this asynchronous operation. + /// + Task DeleteStageInstanceAsync(Snowflake channelId, CancellationToken cancellationToken = default); + + #endregion Stage Instance + + #region User + + /// + /// Gets the current . + /// + /// + /// + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing the current . + /// + Task GetCurrentUserAsync(CancellationToken cancellationToken = default); + + /// + /// Gets a for a given identifier. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a ; or if not found. + /// + Task GetUserAsync(Snowflake userId, CancellationToken cancellationToken = default); + + /// + /// Modifies the current 's account settings. + /// + /// + /// + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing the updated current . + /// + Task ModifyCurrentUserAsync(ModifyCurrentUserParams args, CancellationToken cancellationToken = default); + + /// + /// Gets a collection of partial s the current user is a member of. + /// + /// + /// + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a collection of s. + /// + Task> GetCurrentUserGuildsAsync(GetCurrentUserGuildsParams args, CancellationToken cancellationToken = default); + + /// + /// Leaves a guild for the current . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that represents this asynchronous operation. + /// + Task LeaveGuildAsync(Snowflake guildId, CancellationToken cancellationToken = default); + + /// + /// Creates a new with a . + /// + /// + /// + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a . + /// + Task CreateDMAsync(CreateDMParams args, CancellationToken cancellationToken = default); + + /// + /// Gets the current 's s. + /// + /// + /// + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a collection of s. + /// + Task> GetUserConnectionsAsync(CancellationToken cancellationToken = default); + + #endregion User + + #region Voice + + /// + /// Gets a collection of s. + /// + /// + /// + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a collection of s. + /// + Task> ListVoiceRegionsAsync(CancellationToken cancellationToken = default); + + #endregion Voice + + #region Webhook + + /// + /// Creates a new . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing the created . + /// + Task CreateWebhookAsync(Snowflake channelId, CreateWebhookParams args, CancellationToken cancellationToken = default); + + /// + /// Gets all s in a . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a collection of s. + /// + Task> GetChannelWebhooksAsync(Snowflake channelId, CancellationToken cancellationToken = default); + + /// + /// Gets all s in a . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a collection of s. + /// + Task> GetGuildWebhooksAsync(Snowflake guildId, CancellationToken cancellationToken = default); + + /// + /// Gets the for the given id. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a ; or if it does not exist. + /// + Task GetWebhookAsync(Snowflake webhookId, CancellationToken cancellationToken = default); + + /// + /// Gets the for the given id and token. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The token. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing a ; or if it does not exist. + /// + Task GetWebhookAsync(Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default); + + /// + /// Modifies a . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing the updated . + /// + Task ModifyWebhookAsync(Snowflake webhookId, ModifyWebhookParams args, CancellationToken cancellationToken = default); + + /// + /// Modifies a without requiring authentication. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The token. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task containing the updated . + /// + Task ModifyWebhookAsync(Snowflake webhookId, string webhookToken, ModifyWebhookWithTokenParams args, CancellationToken cancellationToken = default); + + /// + /// Deletes a permanently. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that represents this asynchronous operation. + /// + Task DeleteWebhookAsync(Snowflake webhookId, CancellationToken cancellationToken = default); + + /// + /// Deletes a permanently without requiring authentication. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The token. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that represents this asynchronous operation. + /// + Task DeleteWebhookAsync(Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default); + + /// + /// Sends a as a . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The token. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the created . + /// + Task ExecuteWebhookAsync(Snowflake webhookId, string webhookToken, ExecuteWebhookParams args, CancellationToken cancellationToken = default); + + /// + /// Gets a previously-sent from the same token. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The identifier. + /// + /// + /// The token. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains a ; or if not found. + /// + Task GetWebhookMessageAsync(Snowflake messageId, Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default); + + /// + /// Edits a previously-sent from the same token. + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The identifier. + /// + /// + /// The token. + /// + /// + /// Parameters to include in the request. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that contains the updated . + /// + Task EditWebhookMessageAsync(Snowflake messageId, Snowflake webhookId, string webhookToken, EditWebhookMessageParams args, CancellationToken cancellationToken = default); + + /// + /// Deletes a that was created by the . + /// + /// + /// + /// + /// + /// The identifier. + /// + /// + /// The identifier. + /// + /// + /// The token. + /// + /// + /// Cancellation token for the request. + /// + /// + /// A task that represents this asynchronous operation. + /// + Task DeleteWebhookMessageAsync(Snowflake messageId, Snowflake webhookId, string webhookToken, CancellationToken cancellationToken = default); + + #endregion Webhook } } diff --git a/src/Rest/Net/Requests/Channels/CreateDMParams.cs b/src/Rest/Net/Requests/Channels/CreateDMParams.cs new file mode 100644 index 000000000..82fecadcf --- /dev/null +++ b/src/Rest/Net/Requests/Channels/CreateDMParams.cs @@ -0,0 +1,21 @@ +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record CreateDMParams + { + /// + /// The recipient to open a DM channel with. + /// + public Snowflake RecipientId { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotZero(RecipientId, nameof(RecipientId)); + } + } +} diff --git a/src/Rest/Net/Requests/Channels/CreateStageInstanceParams.cs b/src/Rest/Net/Requests/Channels/CreateStageInstanceParams.cs new file mode 100644 index 000000000..bc04a0168 --- /dev/null +++ b/src/Rest/Net/Requests/Channels/CreateStageInstanceParams.cs @@ -0,0 +1,36 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record CreateStageInstanceParams + { + /// + /// The id of the Stage channel. + /// + public Snowflake ChannelId { get; set; } + + /// + /// The topic of the Stage instance (1-120 characters). + /// + public string? Topic { get; set; } // Required property candidate + + /// + /// The privacy level of the Stage instance (default ). + /// + public Optional PrivacyLevel { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotZero(ChannelId, nameof(ChannelId)); + Preconditions.NotNull(Topic, nameof(Topic)); + Preconditions.LengthAtLeast(Topic, StageInstance.MinStageChannelTopicLength, nameof(Topic)); + Preconditions.LengthAtMost(Topic, StageInstance.MaxStageChannelTopicLength, nameof(Topic)); + } + } +} diff --git a/src/Rest/Net/Requests/Channels/ModifyStageInstanceParams.cs b/src/Rest/Net/Requests/Channels/ModifyStageInstanceParams.cs new file mode 100644 index 000000000..9d53d0751 --- /dev/null +++ b/src/Rest/Net/Requests/Channels/ModifyStageInstanceParams.cs @@ -0,0 +1,30 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record ModifyStageInstanceParams + { + /// + /// The topic of the Stage instance (1-120 characters). + /// + public Optional Topic { get; set; } + + /// + /// The privacy level of the Stage instance. + /// + public Optional PrivacyLevel { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotNull(Topic!, nameof(Topic)); + Preconditions.LengthAtLeast(Topic!, StageInstance.MinStageChannelTopicLength, nameof(Topic)); + Preconditions.LengthAtMost(Topic!, StageInstance.MaxStageChannelTopicLength, nameof(Topic)); + } + } +} diff --git a/src/Rest/Net/Requests/Guilds/CreateGuildTemplateParams.cs b/src/Rest/Net/Requests/Guilds/CreateGuildTemplateParams.cs new file mode 100644 index 000000000..080b48608 --- /dev/null +++ b/src/Rest/Net/Requests/Guilds/CreateGuildTemplateParams.cs @@ -0,0 +1,32 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record CreateGuildTemplateParams + { + /// + /// Name of the template (1-100 characters). + /// + public string? Name { get; set; } // Required property candidate + + /// + /// Description for the template (0-120 characters). + /// + public Optional Description { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotNull(Name, nameof(Name)); + Preconditions.LengthAtLeast(Name, GuildTemplate.MinTemplateNameLength, nameof(Name)); + Preconditions.LengthAtMost(Name, GuildTemplate.MaxTemplateNameLength, nameof(Name)); + Preconditions.LengthAtLeast(Description, GuildTemplate.MinTemplateDescriptionLength, nameof(Description)); + Preconditions.LengthAtMost(Description, GuildTemplate.MaxTemplateDescriptionLength, nameof(Description)); + } + } +} diff --git a/src/Rest/Net/Requests/Guilds/CreateGuildfromGuildTemplateParams.cs b/src/Rest/Net/Requests/Guilds/CreateGuildfromGuildTemplateParams.cs new file mode 100644 index 000000000..0bdcffbd3 --- /dev/null +++ b/src/Rest/Net/Requests/Guilds/CreateGuildfromGuildTemplateParams.cs @@ -0,0 +1,30 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record CreateGuildfromGuildTemplateParams + { + /// + /// Name of the guild (2-100 characters). + /// + public string? Name { get; set; } // Required property candidate + + /// + /// Image for the guild icon. + /// + public Optional Icon { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotNull(Name, nameof(Name)); + Preconditions.LengthAtLeast(Name, Guild.MinGuildNameLength, nameof(Name)); + Preconditions.LengthAtMost(Name, Guild.MaxGuildNameLength, nameof(Name)); + } + } +} diff --git a/src/Rest/Net/Requests/Guilds/ModifyGuildTemplateParams.cs b/src/Rest/Net/Requests/Guilds/ModifyGuildTemplateParams.cs new file mode 100644 index 000000000..3b7d242bf --- /dev/null +++ b/src/Rest/Net/Requests/Guilds/ModifyGuildTemplateParams.cs @@ -0,0 +1,32 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record ModifyGuildTemplateParams + { + /// + /// Name of the template (1-100 characters). + /// + public Optional Name { get; set; } + + /// + /// Description for the template (0-120 characters). + /// + public Optional Description { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotNull(Name!, nameof(Name)); + Preconditions.LengthAtLeast(Name!, GuildTemplate.MinTemplateNameLength, nameof(Name)); + Preconditions.LengthAtMost(Name!, GuildTemplate.MaxTemplateNameLength, nameof(Name)); + Preconditions.LengthAtLeast(Description, GuildTemplate.MinTemplateDescriptionLength, nameof(Description)); + Preconditions.LengthAtMost(Description, GuildTemplate.MaxTemplateDescriptionLength, nameof(Description)); + } + } +} diff --git a/src/Rest/Net/Requests/Invites/GetInviteParams.cs b/src/Rest/Net/Requests/Invites/GetInviteParams.cs new file mode 100644 index 000000000..66521ddb1 --- /dev/null +++ b/src/Rest/Net/Requests/Invites/GetInviteParams.cs @@ -0,0 +1,25 @@ +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record GetInviteParams + { + /// + /// Whether the invite should contain approximate member counts. + /// + public Optional WithCounts { get; set; } + + /// + /// Whether the invite should contain the expiration date. + /// + public Optional WithExpiration { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + } + } +} diff --git a/src/Rest/Net/Requests/Users/GetCurrentUserGuildsParams.cs b/src/Rest/Net/Requests/Users/GetCurrentUserGuildsParams.cs new file mode 100644 index 000000000..2fcb95a19 --- /dev/null +++ b/src/Rest/Net/Requests/Users/GetCurrentUserGuildsParams.cs @@ -0,0 +1,35 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record GetCurrentUserGuildsParams + { + /// + /// Get guilds before this guild ID. + /// + public Snowflake Before { get; set; } + + /// + /// Get guilds after this guild ID. + /// + public Snowflake After { get; set; } + + /// + /// Max number of guilds to return (1-200). + /// + public int Limit { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotZero(Before, nameof(Before)); + Preconditions.AtLeast(Limit, Guild.MinGetGuildsAmount, nameof(Limit)); + Preconditions.AtMost(Limit, Guild.MaxGetGuildsAmount, nameof(Limit)); + } + } +} diff --git a/src/Rest/Net/Requests/Users/ModifyCurrentUserParams.cs b/src/Rest/Net/Requests/Users/ModifyCurrentUserParams.cs new file mode 100644 index 000000000..a701cb935 --- /dev/null +++ b/src/Rest/Net/Requests/Users/ModifyCurrentUserParams.cs @@ -0,0 +1,28 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record ModifyCurrentUserParams + { + /// + /// 's username, if changed may cause the 's + /// discriminator to be randomized. + /// + public Optional Username { get; set; } + + /// + /// If passed, modifies the 's avatar. + /// + public Optional Avatar { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + } + } +} diff --git a/src/Rest/Net/Requests/Webhooks/CreateWebhookParams.cs b/src/Rest/Net/Requests/Webhooks/CreateWebhookParams.cs new file mode 100644 index 000000000..34509c03d --- /dev/null +++ b/src/Rest/Net/Requests/Webhooks/CreateWebhookParams.cs @@ -0,0 +1,30 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record CreateWebhookParams + { + /// + /// Name of the webhook (1-80 characters). + /// + public string? Name { get; set; } // Required property candidate + + /// + /// Image for the default webhook avatar. + /// + public Optional Avatar { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotNull(Name, nameof(Name)); + Preconditions.LengthAtLeast(Name, Webhook.MinNameLength, nameof(Name)); + Preconditions.LengthAtMost(Name, Webhook.MaxNameLength, nameof(Name)); + } + } +} diff --git a/src/Rest/Net/Requests/Webhooks/EditWebhookMessageParams.cs b/src/Rest/Net/Requests/Webhooks/EditWebhookMessageParams.cs new file mode 100644 index 000000000..ecf620681 --- /dev/null +++ b/src/Rest/Net/Requests/Webhooks/EditWebhookMessageParams.cs @@ -0,0 +1,54 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record EditWebhookMessageParams + { + /// + /// The message contents. + /// + public Optional Content { get; set; } + + /// + /// Embedded rich content. + /// + public Optional Embeds { get; set; } + + /// + /// The contents of the file being sent/edited. + /// + public Optional File { get; set; } + + /// + /// JSON encoded body of non-file params (multipart/form-data only). + /// + public Optional PayloadJson { get; set; } // TODO: Should change this to an easy way to convert to form data. + + /// + /// Allowed mentions for the message. + /// + public Optional AllowedMentions { get; set; } + + /// + /// Attached files to keep. + /// + public Optional Attachments { get; set; } + + /// + /// The components to include with the message. + /// + public Optional Components { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.LengthAtMost(Content, Message.MaxContentLength, nameof(Content)); + Preconditions.LengthAtMost(Embeds, Message.MaxEmbeds, nameof(Embeds)); + } + } +} diff --git a/src/Rest/Net/Requests/Webhooks/ExecuteWebhookParams.cs b/src/Rest/Net/Requests/Webhooks/ExecuteWebhookParams.cs new file mode 100644 index 000000000..126ba2e46 --- /dev/null +++ b/src/Rest/Net/Requests/Webhooks/ExecuteWebhookParams.cs @@ -0,0 +1,78 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record ExecuteWebhookParams + { + /// + /// Waits for server confirmation of message send before response, and returns the created message. + /// + public Optional Wait { get; set; } + + /// + /// Send a message to the specified thread within a webhook's channel. The thread will automatically be unarchived. + /// + public Optional ThreadId { get; set; } + + /// + /// The message contents. + /// + public Optional Content { get; set; } + + /// + /// Override the default username of the webhook. + /// + public Optional Username { get; set; } + + /// + /// Override the default avatar of the webhook. + /// + public Optional AvatarUrl { get; set; } + + /// + /// True if this is a TTS message. + /// + public Optional Tts { get; set; } + + /// + /// The contents of the file being sent. + /// + public Optional File { get; set; } + + /// + /// Embedded rich content. + /// + public Optional Embeds { get; set; } + + /// + /// JSON encoded body of non-file params. + /// + public Optional PayloadJson { get; set; } + + /// + /// Allowed mentions for the message. + /// + public Optional AllowedMentions { get; set; } + + /// + /// The components to include with the message. + /// + public Optional Components { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotZero(ThreadId, nameof(ThreadId)); + Preconditions.LengthAtMost(Content!, Message.MaxContentLength, nameof(Content)); + Preconditions.NotNull(Username!, nameof(Username)); + Preconditions.LengthAtLeast(Username!, Webhook.MinNameLength, nameof(Username)); + Preconditions.LengthAtMost(Username!, Webhook.MaxNameLength, nameof(Username)); + Preconditions.LengthAtMost(Embeds!, Message.MaxEmbeds, nameof(Embeds)); + } + } +} diff --git a/src/Rest/Net/Requests/Webhooks/ModifyWebhookParams.cs b/src/Rest/Net/Requests/Webhooks/ModifyWebhookParams.cs new file mode 100644 index 000000000..189e993be --- /dev/null +++ b/src/Rest/Net/Requests/Webhooks/ModifyWebhookParams.cs @@ -0,0 +1,36 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record ModifyWebhookParams + { + /// + /// The default name of the webhook. + /// + public Optional Name { get; set; } + + /// + /// Image for the default webhook avatar. + /// + public Optional Avatar { get; set; } + + /// + /// The new channel id this webhook should be moved to. + /// + public Optional ChannelId { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotNull(Name!, nameof(Name)); + Preconditions.LengthAtLeast(Name!, Webhook.MinNameLength, nameof(Name)); + Preconditions.LengthAtMost(Name!, Webhook.MaxNameLength, nameof(Name)); + Preconditions.NotZero(ChannelId, nameof(ChannelId)); + } + } +} diff --git a/src/Rest/Net/Requests/Webhooks/ModifyWebhookWithTokenParams.cs b/src/Rest/Net/Requests/Webhooks/ModifyWebhookWithTokenParams.cs new file mode 100644 index 000000000..e9d63389c --- /dev/null +++ b/src/Rest/Net/Requests/Webhooks/ModifyWebhookWithTokenParams.cs @@ -0,0 +1,30 @@ +using Discord.Net.Models; + +namespace Discord.Net.Rest +{ + /// + /// Parameters to add to the request. + /// + public record ModifyWebhookWithTokenParams + { + /// + /// The default name of the webhook. + /// + public Optional Name { get; set; } + + /// + /// Image for the default webhook avatar. + /// + public Optional Avatar { get; set; } + + /// + /// Validates the data. + /// + public void Validate() + { + Preconditions.NotNull(Name!, nameof(Name)); + Preconditions.LengthAtLeast(Name!, Webhook.MinNameLength, nameof(Name)); + Preconditions.LengthAtMost(Name!, Webhook.MaxNameLength, nameof(Name)); + } + } +}