Added ApplicationCommand types: Slash : 1 User: 2 Message: 3 And the appropriate CRUD methods.pull/1923/head
| @@ -1,6 +1,6 @@ | |||||
| Microsoft Visual Studio Solution File, Format Version 12.00 | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
| # Visual Studio Version 16 | |||||
| VisualStudioVersion = 16.0.28407.52 | |||||
| # Visual Studio Version 17 | |||||
| VisualStudioVersion = 17.0.31521.260 | |||||
| MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | ||||
| EndProject | EndProject | ||||
| @@ -40,7 +40,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Analyzers.Tests | |||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Examples", "src\Discord.Net.Examples\Discord.Net.Examples.csproj", "{47820065-3CFB-401C-ACEA-862BD564A404}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Examples", "src\Discord.Net.Examples\Discord.Net.Examples.csproj", "{47820065-3CFB-401C-ACEA-862BD564A404}" | ||||
| EndProject | EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "idn", "samples\idn\idn.csproj", "{4A03840B-9EBE-47E3-89AB-E0914DF21AFB}" | |||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "idn", "samples\idn\idn.csproj", "{4A03840B-9EBE-47E3-89AB-E0914DF21AFB}" | |||||
| EndProject | |||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureTesting", "..\FeatureTesting\FeatureTesting\FeatureTesting.csproj", "{0CC57A32-3AC7-489D-8DF5-C431925E4675}" | |||||
| EndProject | EndProject | ||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| @@ -232,6 +234,18 @@ Global | |||||
| {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x64.Build.0 = Release|Any CPU | {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x64.Build.0 = Release|Any CPU | ||||
| {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.ActiveCfg = Release|Any CPU | {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.ActiveCfg = Release|Any CPU | ||||
| {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.Build.0 = Release|Any CPU | {4A03840B-9EBE-47E3-89AB-E0914DF21AFB}.Release|x86.Build.0 = Release|Any CPU | ||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Debug|x64.ActiveCfg = Debug|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Debug|x64.Build.0 = Debug|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Debug|x86.ActiveCfg = Debug|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Debug|x86.Build.0 = Debug|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Release|x64.ActiveCfg = Release|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Release|x64.Build.0 = Release|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Release|x86.ActiveCfg = Release|Any CPU | |||||
| {0CC57A32-3AC7-489D-8DF5-C431925E4675}.Release|x86.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -8,7 +8,7 @@ | |||||
| <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netstandard2.0;netstandard2.1</TargetFrameworks> | <TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netstandard2.0;netstandard2.1</TargetFrameworks> | ||||
| <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1</TargetFrameworks> | <TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1</TargetFrameworks> | ||||
| <PackageId>Discord.Net.Labs.Core</PackageId> | <PackageId>Discord.Net.Labs.Core</PackageId> | ||||
| <Version>3.0.0-pre</Version> | |||||
| <Version>3.3.1.0</Version> | |||||
| <Product>Discord.Net.Labs.Core</Product> | <Product>Discord.Net.Labs.Core</Product> | ||||
| <RepositoryUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</RepositoryUrl> | <RepositoryUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</RepositoryUrl> | ||||
| <PackageIcon>Temporary.png</PackageIcon> | <PackageIcon>Temporary.png</PackageIcon> | ||||
| @@ -4452,6 +4452,11 @@ | |||||
| Gets or sets the discription of this command. | Gets or sets the discription of this command. | ||||
| </summary> | </summary> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.ApplicationCommandProperties.Type"> | |||||
| <summary> | |||||
| Gets or sets the type for this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.ApplicationCommandProperties.Options"> | <member name="P:Discord.ApplicationCommandProperties.Options"> | ||||
| <summary> | <summary> | ||||
| Gets or sets the options for this command. | Gets or sets the options for this command. | ||||
| @@ -4472,6 +4477,11 @@ | |||||
| Gets the unique id of the parent application. | Gets the unique id of the parent application. | ||||
| </summary> | </summary> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.IApplicationCommand.Type"> | |||||
| <summary> | |||||
| The type of the command | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.IApplicationCommand.Name"> | <member name="P:Discord.IApplicationCommand.Name"> | ||||
| <summary> | <summary> | ||||
| The name of the command. | The name of the command. | ||||
| @@ -5444,6 +5454,73 @@ | |||||
| Will render this option as selected by default. | Will render this option as selected by default. | ||||
| </summary> | </summary> | ||||
| </member> | </member> | ||||
| <member name="T:Discord.MessageCommandBuilder"> | |||||
| <summary> | |||||
| A class used to build slash commands. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="F:Discord.MessageCommandBuilder.MaxNameLength"> | |||||
| <summary> | |||||
| Returns the maximun length a commands name allowed by Discord | |||||
| </summary> | |||||
| </member> | |||||
| <member name="F:Discord.MessageCommandBuilder.MaxDescriptionLength"> | |||||
| <summary> | |||||
| Returns the maximum length of a commands description allowed by Discord. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.MessageCommandBuilder.Name"> | |||||
| <summary> | |||||
| The name of this slash command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.MessageCommandBuilder.Description"> | |||||
| <summary> | |||||
| A 1-100 length description of this slash command | |||||
| </summary> | |||||
| </member> | |||||
| <member name="M:Discord.MessageCommandBuilder.Build"> | |||||
| <summary> | |||||
| Build the current builder into a <see cref="T:Discord.MessageCommandCreationProperties"/> class. | |||||
| </summary> | |||||
| <returns>A <see cref="T:Discord.MessageCommandCreationProperties"/> that can be used to create user commands over rest.</returns> | |||||
| </member> | |||||
| <member name="M:Discord.MessageCommandBuilder.WithName(System.String)"> | |||||
| <summary> | |||||
| Sets the field name. | |||||
| </summary> | |||||
| <param name="name">The value to set the field name to.</param> | |||||
| <returns> | |||||
| The current builder. | |||||
| </returns> | |||||
| </member> | |||||
| <member name="M:Discord.MessageCommandBuilder.WithDescription(System.String)"> | |||||
| <summary> | |||||
| Sets the description of the current command. | |||||
| </summary> | |||||
| <param name="description">The description of this command.</param> | |||||
| <returns>The current builder.</returns> | |||||
| </member> | |||||
| <member name="T:Discord.MessageCommandCreationProperties"> | |||||
| <summary> | |||||
| A class used to create Message commands. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.MessageCommandCreationProperties.Name"> | |||||
| <summary> | |||||
| The name of this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.MessageCommandCreationProperties.Description"> | |||||
| <summary> | |||||
| The discription of this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.MessageCommandCreationProperties.Type"> | |||||
| <summary> | |||||
| Gets or sets the type for this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="T:Discord.SlashCommandBuilder"> | <member name="T:Discord.SlashCommandBuilder"> | ||||
| <summary> | <summary> | ||||
| A class used to build slash commands. | A class used to build slash commands. | ||||
| @@ -5691,6 +5768,11 @@ | |||||
| The discription of this command. | The discription of this command. | ||||
| </summary> | </summary> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.SlashCommandCreationProperties.Type"> | |||||
| <summary> | |||||
| Gets or sets the type for this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.SlashCommandCreationProperties.Options"> | <member name="P:Discord.SlashCommandCreationProperties.Options"> | ||||
| <summary> | <summary> | ||||
| Gets or sets the options for this command. | Gets or sets the options for this command. | ||||
| @@ -5701,6 +5783,73 @@ | |||||
| Whether the command is enabled by default when the app is added to a guild. Default is <see langword="true"/> | Whether the command is enabled by default when the app is added to a guild. Default is <see langword="true"/> | ||||
| </summary> | </summary> | ||||
| </member> | </member> | ||||
| <member name="T:Discord.UserCommandBuilder"> | |||||
| <summary> | |||||
| A class used to build slash commands. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="F:Discord.UserCommandBuilder.MaxNameLength"> | |||||
| <summary> | |||||
| Returns the maximun length a commands name allowed by Discord | |||||
| </summary> | |||||
| </member> | |||||
| <member name="F:Discord.UserCommandBuilder.MaxDescriptionLength"> | |||||
| <summary> | |||||
| Returns the maximum length of a commands description allowed by Discord. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.UserCommandBuilder.Name"> | |||||
| <summary> | |||||
| The name of this slash command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.UserCommandBuilder.Description"> | |||||
| <summary> | |||||
| A 1-100 length description of this slash command | |||||
| </summary> | |||||
| </member> | |||||
| <member name="M:Discord.UserCommandBuilder.Build"> | |||||
| <summary> | |||||
| Build the current builder into a <see cref="T:Discord.UserCommandCreationProperties"/> class. | |||||
| </summary> | |||||
| <returns>A <see cref="T:Discord.UserCommandCreationProperties"/> that can be used to create user commands over rest.</returns> | |||||
| </member> | |||||
| <member name="M:Discord.UserCommandBuilder.WithName(System.String)"> | |||||
| <summary> | |||||
| Sets the field name. | |||||
| </summary> | |||||
| <param name="name">The value to set the field name to.</param> | |||||
| <returns> | |||||
| The current builder. | |||||
| </returns> | |||||
| </member> | |||||
| <member name="M:Discord.UserCommandBuilder.WithDescription(System.String)"> | |||||
| <summary> | |||||
| Sets the description of the current command. | |||||
| </summary> | |||||
| <param name="description">The description of this command.</param> | |||||
| <returns>The current builder.</returns> | |||||
| </member> | |||||
| <member name="T:Discord.UserCommandCreationProperties"> | |||||
| <summary> | |||||
| A class used to create User commands. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.UserCommandCreationProperties.Name"> | |||||
| <summary> | |||||
| The name of this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.UserCommandCreationProperties.Description"> | |||||
| <summary> | |||||
| The discription of this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.UserCommandCreationProperties.Type"> | |||||
| <summary> | |||||
| Gets or sets the type for this command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="T:Discord.IInvite"> | <member name="T:Discord.IInvite"> | ||||
| <summary> | <summary> | ||||
| Represents a generic invite object. | Represents a generic invite object. | ||||
| @@ -20,7 +20,11 @@ namespace Discord | |||||
| /// Gets or sets the discription of this command. | /// Gets or sets the discription of this command. | ||||
| /// </summary> | /// </summary> | ||||
| public Optional<string> Description { get; set; } | public Optional<string> Description { get; set; } | ||||
| /// <summary> | |||||
| /// Gets or sets the type for this command. | |||||
| /// </summary> | |||||
| public Optional<ApplicationCommandType> Type { get; set; } | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets or sets the options for this command. | /// Gets or sets the options for this command. | ||||
| @@ -0,0 +1,15 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord | |||||
| { | |||||
| public enum ApplicationCommandType : byte | |||||
| { | |||||
| Slash = 1, | |||||
| User = 2, | |||||
| Message = 3 | |||||
| } | |||||
| } | |||||
| @@ -16,6 +16,11 @@ namespace Discord | |||||
| /// </summary> | /// </summary> | ||||
| ulong ApplicationId { get; } | ulong ApplicationId { get; } | ||||
| /// <summary> | |||||
| /// The type of the command | |||||
| /// </summary> | |||||
| ApplicationCommandType Type { get; } | |||||
| /// <summary> | /// <summary> | ||||
| /// The name of the command. | /// The name of the command. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -0,0 +1,109 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Text.RegularExpressions; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord | |||||
| { | |||||
| /// <summary> | |||||
| /// A class used to build slash commands. | |||||
| /// </summary> | |||||
| public class MessageCommandBuilder | |||||
| { | |||||
| /// <summary> | |||||
| /// Returns the maximun length a commands name allowed by Discord | |||||
| /// </summary> | |||||
| public const int MaxNameLength = 32; | |||||
| /// <summary> | |||||
| /// Returns the maximum length of a commands description allowed by Discord. | |||||
| /// </summary> | |||||
| public const int MaxDescriptionLength = 0; | |||||
| /// <summary> | |||||
| /// The name of this slash command. | |||||
| /// </summary> | |||||
| public string Name | |||||
| { | |||||
| get | |||||
| { | |||||
| return _name; | |||||
| } | |||||
| set | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(value, nameof(Name)); | |||||
| Preconditions.AtLeast(value.Length, 3, nameof(Name)); | |||||
| Preconditions.AtMost(value.Length, MaxNameLength, nameof(Name)); | |||||
| // Discord updated the docs, this regex prevents special characters like @!$%(... etc, | |||||
| // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | |||||
| if (!Regex.IsMatch(value, @"^[\w -]{3,32}$")) | |||||
| throw new ArgumentException("Command name cannot contain any special characters or whitespaces!"); | |||||
| _name = value; | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// A 1-100 length description of this slash command | |||||
| /// </summary> | |||||
| public string Description | |||||
| { | |||||
| get | |||||
| { | |||||
| return _description; | |||||
| } | |||||
| set | |||||
| { | |||||
| Preconditions.Equals(value, ""); | |||||
| _description = value; | |||||
| } | |||||
| } | |||||
| private string _name { get; set; } | |||||
| private string _description { get; set; } | |||||
| /// <summary> | |||||
| /// Build the current builder into a <see cref="MessageCommandCreationProperties"/> class. | |||||
| /// </summary> | |||||
| /// <returns>A <see cref="MessageCommandCreationProperties"/> that can be used to create user commands over rest.</returns> | |||||
| public MessageCommandCreationProperties Build() | |||||
| { | |||||
| MessageCommandCreationProperties props = new MessageCommandCreationProperties() | |||||
| { | |||||
| Name = this.Name, | |||||
| Description = this.Description, | |||||
| Type=ApplicationCommandType.Message | |||||
| }; | |||||
| return props; | |||||
| } | |||||
| /// <summary> | |||||
| /// Sets the field name. | |||||
| /// </summary> | |||||
| /// <param name="name">The value to set the field name to.</param> | |||||
| /// <returns> | |||||
| /// The current builder. | |||||
| /// </returns> | |||||
| public MessageCommandBuilder WithName(string name) | |||||
| { | |||||
| this.Name = name; | |||||
| return this; | |||||
| } | |||||
| /// <summary> | |||||
| /// Sets the description of the current command. | |||||
| /// </summary> | |||||
| /// <param name="description">The description of this command.</param> | |||||
| /// <returns>The current builder.</returns> | |||||
| public MessageCommandBuilder WithDescription(string description) | |||||
| { | |||||
| this.Description = description; | |||||
| return this; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,30 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord | |||||
| { | |||||
| /// <summary> | |||||
| /// A class used to create Message commands. | |||||
| /// </summary> | |||||
| public class MessageCommandCreationProperties | |||||
| { | |||||
| /// <summary> | |||||
| /// The name of this command. | |||||
| /// </summary> | |||||
| public string Name { get; set; } | |||||
| /// <summary> | |||||
| /// The discription of this command. | |||||
| /// </summary> | |||||
| public string Description { get; set; } | |||||
| /// <summary> | |||||
| /// Gets or sets the type for this command. | |||||
| /// </summary> | |||||
| public ApplicationCommandType Type { get; set; } | |||||
| } | |||||
| } | |||||
| @@ -102,7 +102,8 @@ namespace Discord | |||||
| { | { | ||||
| Name = this.Name, | Name = this.Name, | ||||
| Description = this.Description, | Description = this.Description, | ||||
| DefaultPermission = this.DefaultPermission | |||||
| DefaultPermission = this.DefaultPermission, | |||||
| Type = ApplicationCommandType.Slash | |||||
| }; | }; | ||||
| if (this.Options != null && this.Options.Any()) | if (this.Options != null && this.Options.Any()) | ||||
| @@ -21,6 +21,10 @@ namespace Discord | |||||
| /// </summary> | /// </summary> | ||||
| public string Description { get; set; } | public string Description { get; set; } | ||||
| /// <summary> | |||||
| /// Gets or sets the type for this command. | |||||
| /// </summary> | |||||
| public ApplicationCommandType Type { get; set; } | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets or sets the options for this command. | /// Gets or sets the options for this command. | ||||
| @@ -0,0 +1,109 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Text.RegularExpressions; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord | |||||
| { | |||||
| /// <summary> | |||||
| /// A class used to build slash commands. | |||||
| /// </summary> | |||||
| public class UserCommandBuilder | |||||
| { | |||||
| /// <summary> | |||||
| /// Returns the maximun length a commands name allowed by Discord | |||||
| /// </summary> | |||||
| public const int MaxNameLength = 32; | |||||
| /// <summary> | |||||
| /// Returns the maximum length of a commands description allowed by Discord. | |||||
| /// </summary> | |||||
| public const int MaxDescriptionLength = 0; | |||||
| /// <summary> | |||||
| /// The name of this slash command. | |||||
| /// </summary> | |||||
| public string Name | |||||
| { | |||||
| get | |||||
| { | |||||
| return _name; | |||||
| } | |||||
| set | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(value, nameof(Name)); | |||||
| Preconditions.AtLeast(value.Length, 3, nameof(Name)); | |||||
| Preconditions.AtMost(value.Length, MaxNameLength, nameof(Name)); | |||||
| // Discord updated the docs, this regex prevents special characters like @!$%(... etc, | |||||
| // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand | |||||
| if (!Regex.IsMatch(value, @"^[\w -]{3,32}$")) | |||||
| throw new ArgumentException("Command name cannot contain any special characters or whitespaces!"); | |||||
| _name = value; | |||||
| } | |||||
| } | |||||
| /// <summary> | |||||
| /// A 1-100 length description of this slash command | |||||
| /// </summary> | |||||
| public string Description | |||||
| { | |||||
| get | |||||
| { | |||||
| return _description; | |||||
| } | |||||
| set | |||||
| { | |||||
| Preconditions.Equals(value, ""); | |||||
| _description = value; | |||||
| } | |||||
| } | |||||
| private string _name { get; set; } | |||||
| private string _description { get; set; } | |||||
| /// <summary> | |||||
| /// Build the current builder into a <see cref="UserCommandCreationProperties"/> class. | |||||
| /// </summary> | |||||
| /// <returns>A <see cref="UserCommandCreationProperties"/> that can be used to create user commands over rest.</returns> | |||||
| public UserCommandCreationProperties Build() | |||||
| { | |||||
| UserCommandCreationProperties props = new UserCommandCreationProperties() | |||||
| { | |||||
| Name = this.Name, | |||||
| Description = this.Description, | |||||
| Type=ApplicationCommandType.User | |||||
| }; | |||||
| return props; | |||||
| } | |||||
| /// <summary> | |||||
| /// Sets the field name. | |||||
| /// </summary> | |||||
| /// <param name="name">The value to set the field name to.</param> | |||||
| /// <returns> | |||||
| /// The current builder. | |||||
| /// </returns> | |||||
| public UserCommandBuilder WithName(string name) | |||||
| { | |||||
| this.Name = name; | |||||
| return this; | |||||
| } | |||||
| /// <summary> | |||||
| /// Sets the description of the current command. | |||||
| /// </summary> | |||||
| /// <param name="description">The description of this command.</param> | |||||
| /// <returns>The current builder.</returns> | |||||
| public UserCommandBuilder WithDescription(string description) | |||||
| { | |||||
| this.Description = description; | |||||
| return this; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,30 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord | |||||
| { | |||||
| /// <summary> | |||||
| /// A class used to create User commands. | |||||
| /// </summary> | |||||
| public class UserCommandCreationProperties | |||||
| { | |||||
| /// <summary> | |||||
| /// The name of this command. | |||||
| /// </summary> | |||||
| public string Name { get; set; } | |||||
| /// <summary> | |||||
| /// The discription of this command. | |||||
| /// </summary> | |||||
| public string Description { get; set; } | |||||
| /// <summary> | |||||
| /// Gets or sets the type for this command. | |||||
| /// </summary> | |||||
| public ApplicationCommandType Type { get; set; } | |||||
| } | |||||
| } | |||||
| @@ -13,6 +13,9 @@ namespace Discord.API.Rest | |||||
| [JsonProperty("name")] | [JsonProperty("name")] | ||||
| public string Name { get; set; } | public string Name { get; set; } | ||||
| [JsonProperty("type")] | |||||
| public ApplicationCommandType Type { get; set; } | |||||
| [JsonProperty("description")] | [JsonProperty("description")] | ||||
| public string Description { get; set; } | public string Description { get; set; } | ||||
| @@ -23,11 +26,12 @@ namespace Discord.API.Rest | |||||
| public Optional<bool> DefaultPermission { get; set; } | public Optional<bool> DefaultPermission { get; set; } | ||||
| public CreateApplicationCommandParams() { } | public CreateApplicationCommandParams() { } | ||||
| public CreateApplicationCommandParams(string name, string description, ApplicationCommandOption[] options = null) | |||||
| public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null) | |||||
| { | { | ||||
| this.Name = name; | this.Name = name; | ||||
| this.Description = description; | this.Description = description; | ||||
| this.Options = Optional.Create<ApplicationCommandOption[]>(options); | this.Options = Optional.Create<ApplicationCommandOption[]>(options); | ||||
| this.Type = type; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -15,6 +15,9 @@ namespace Discord.API.Rest | |||||
| [JsonProperty("description")] | [JsonProperty("description")] | ||||
| public Optional<string> Description { get; set; } | public Optional<string> Description { get; set; } | ||||
| [JsonProperty("type")] | |||||
| public Optional<ApplicationCommandType> Type { get; set; } | |||||
| [JsonProperty("options")] | [JsonProperty("options")] | ||||
| public Optional<ApplicationCommandOption[]> Options { get; set; } | public Optional<ApplicationCommandOption[]> Options { get; set; } | ||||
| @@ -3732,6 +3732,9 @@ | |||||
| <member name="P:Discord.Rest.RestApplicationCommand.ApplicationId"> | <member name="P:Discord.Rest.RestApplicationCommand.ApplicationId"> | ||||
| <inheritdoc/> | <inheritdoc/> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.Rest.RestApplicationCommand.Type"> | |||||
| <inheritdoc/> | |||||
| </member> | |||||
| <member name="P:Discord.Rest.RestApplicationCommand.Name"> | <member name="P:Discord.Rest.RestApplicationCommand.Name"> | ||||
| <inheritdoc/> | <inheritdoc/> | ||||
| </member> | </member> | ||||
| @@ -3831,6 +3834,32 @@ | |||||
| The modified command. | The modified command. | ||||
| </returns> | </returns> | ||||
| </member> | </member> | ||||
| <member name="M:Discord.Rest.RestGlobalMessageCommand.DeleteAsync(Discord.RequestOptions)"> | |||||
| <inheritdoc/> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGlobalMessageCommand.ModifyAsync(System.Action{Discord.ApplicationCommandProperties},Discord.RequestOptions)"> | |||||
| <summary> | |||||
| Modifies this <see cref="T:Discord.Rest.RestApplicationCommand"/>. | |||||
| </summary> | |||||
| <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| <param name="options">The options to be used when sending the request.</param> | |||||
| <returns> | |||||
| The modified command. | |||||
| </returns> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGlobalUserCommand.DeleteAsync(Discord.RequestOptions)"> | |||||
| <inheritdoc/> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGlobalUserCommand.ModifyAsync(System.Action{Discord.ApplicationCommandProperties},Discord.RequestOptions)"> | |||||
| <summary> | |||||
| Modifies this <see cref="T:Discord.Rest.RestApplicationCommand"/>. | |||||
| </summary> | |||||
| <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| <param name="options">The options to be used when sending the request.</param> | |||||
| <returns> | |||||
| The modified command. | |||||
| </returns> | |||||
| </member> | |||||
| <member name="T:Discord.Rest.RestGuildCommand"> | <member name="T:Discord.Rest.RestGuildCommand"> | ||||
| <summary> | <summary> | ||||
| Represents a Rest-based guild command. | Represents a Rest-based guild command. | ||||
| @@ -3886,6 +3915,74 @@ | |||||
| <see cref="T:Discord.Rest.RestGuild"/>. | <see cref="T:Discord.Rest.RestGuild"/>. | ||||
| </returns> | </returns> | ||||
| </member> | </member> | ||||
| <member name="T:Discord.Rest.RestGuildMessageCommand"> | |||||
| <summary> | |||||
| Represents a Rest-based guild command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.Rest.RestGuildMessageCommand.GuildId"> | |||||
| <summary> | |||||
| The guild Id where this command originates. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGuildMessageCommand.DeleteAsync(Discord.RequestOptions)"> | |||||
| <inheritdoc/> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGuildMessageCommand.ModifyAsync(System.Action{Discord.ApplicationCommandProperties},Discord.RequestOptions)"> | |||||
| <summary> | |||||
| Modifies this <see cref="T:Discord.Rest.RestApplicationCommand"/>. | |||||
| </summary> | |||||
| <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| <param name="options">The options to be used when sending the request.</param> | |||||
| <returns> | |||||
| The modified command | |||||
| </returns> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGuildMessageCommand.GetGuild(System.Boolean,Discord.RequestOptions)"> | |||||
| <summary> | |||||
| Gets the guild that this slash command resides in. | |||||
| </summary> | |||||
| <param name="withCounts"><see langword="true"/> if you want the approximate member and presence counts for the guild, otherwise <see langword="false"/>.</param> | |||||
| <param name="options">The options to be used when sending the request.</param> | |||||
| <returns> | |||||
| A task that represents the asynchronous get operation. The task result contains a | |||||
| <see cref="T:Discord.Rest.RestGuild"/>. | |||||
| </returns> | |||||
| </member> | |||||
| <member name="T:Discord.Rest.RestGuildUserCommand"> | |||||
| <summary> | |||||
| Represents a Rest-based guild command. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="P:Discord.Rest.RestGuildUserCommand.GuildId"> | |||||
| <summary> | |||||
| The guild Id where this command originates. | |||||
| </summary> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGuildUserCommand.DeleteAsync(Discord.RequestOptions)"> | |||||
| <inheritdoc/> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGuildUserCommand.ModifyAsync(System.Action{Discord.ApplicationCommandProperties},Discord.RequestOptions)"> | |||||
| <summary> | |||||
| Modifies this <see cref="T:Discord.Rest.RestApplicationCommand"/>. | |||||
| </summary> | |||||
| <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| <param name="options">The options to be used when sending the request.</param> | |||||
| <returns> | |||||
| The modified command | |||||
| </returns> | |||||
| </member> | |||||
| <member name="M:Discord.Rest.RestGuildUserCommand.GetGuild(System.Boolean,Discord.RequestOptions)"> | |||||
| <summary> | |||||
| Gets the guild that this slash command resides in. | |||||
| </summary> | |||||
| <param name="withCounts"><see langword="true"/> if you want the approximate member and presence counts for the guild, otherwise <see langword="false"/>.</param> | |||||
| <param name="options">The options to be used when sending the request.</param> | |||||
| <returns> | |||||
| A task that represents the asynchronous get operation. The task result contains a | |||||
| <see cref="T:Discord.Rest.RestGuild"/>. | |||||
| </returns> | |||||
| </member> | |||||
| <member name="P:Discord.Rest.RestInvite.ChannelName"> | <member name="P:Discord.Rest.RestInvite.ChannelName"> | ||||
| <inheritdoc /> | <inheritdoc /> | ||||
| </member> | </member> | ||||
| @@ -235,6 +235,7 @@ namespace Discord.API | |||||
| options.BucketId = bucketId; | options.BucketId = bucketId; | ||||
| string json = payload != null ? SerializeJson(payload) : null; | string json = payload != null ? SerializeJson(payload) : null; | ||||
| Console.WriteLine($"Sending JSON....\n{json}"); | |||||
| var request = new JsonRestRequest(RestClient, method, endpoint, json, options); | var request = new JsonRestRequest(RestClient, method, endpoint, json, options); | ||||
| return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false)); | return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false)); | ||||
| } | } | ||||
| @@ -1082,6 +1083,18 @@ namespace Discord.API | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("PATCH", () => $"applications/{this.CurrentUserId}/commands/{commandId}", command, new BucketIds(), options: options)).ConfigureAwait(false); | return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("PATCH", () => $"applications/{this.CurrentUserId}/commands/{commandId}", command, new BucketIds(), options: options)).ConfigureAwait(false); | ||||
| } | } | ||||
| public async Task<ApplicationCommand> ModifyGlobalApplicationUserCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("PATCH", () => $"applications/{this.CurrentUserId}/commands/{commandId}", command, new BucketIds(), options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand> ModifyGlobalApplicationMessageCommandAsync(ModifyApplicationCommandParams command, ulong commandId, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("PATCH", () => $"applications/{this.CurrentUserId}/commands/{commandId}", command, new BucketIds(), options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task DeleteGlobalApplicationCommandAsync(ulong commandId, RequestOptions options = null) | public async Task DeleteGlobalApplicationCommandAsync(ulong commandId, RequestOptions options = null) | ||||
| { | { | ||||
| options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
| @@ -1095,6 +1108,46 @@ namespace Discord.API | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/commands", commands, new BucketIds(), options: options)).ConfigureAwait(false); | return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/commands", commands, new BucketIds(), options: options)).ConfigureAwait(false); | ||||
| } | } | ||||
| public async Task<ApplicationCommand> CreateGlobalApplicationUserCommandAsync(CreateApplicationCommandParams command, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNull(command, nameof(command)); | |||||
| Preconditions.AtMost(command.Name.Length, 32, nameof(command.Name)); | |||||
| Preconditions.AtLeast(command.Name.Length, 3, nameof(command.Name)); | |||||
| Preconditions.Equals(command.Description, ""); | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("POST", () => $"applications/{this.CurrentUserId}/commands", command, new BucketIds(), options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand> CreateGlobalApplicationMessageCommandAsync(CreateApplicationCommandParams command, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNull(command, nameof(command)); | |||||
| Preconditions.AtMost(command.Name.Length, 32, nameof(command.Name)); | |||||
| Preconditions.AtLeast(command.Name.Length, 3, nameof(command.Name)); | |||||
| Preconditions.Equals(command.Description, ""); | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("POST", () => $"applications/{this.CurrentUserId}/commands", command, new BucketIds(), options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand[]> BulkOverwriteGlobalApplicationUserCommands(CreateApplicationCommandParams[] commands, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/commands", commands, new BucketIds(), options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand[]> BulkOverwriteGlobalApplicationMessageCommands(CreateApplicationCommandParams[] commands, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/commands", commands, new BucketIds(), options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand[]> GetGuildApplicationCommandsAsync(ulong guildId, RequestOptions options = null) | public async Task<ApplicationCommand[]> GetGuildApplicationCommandsAsync(ulong guildId, RequestOptions options = null) | ||||
| { | { | ||||
| @@ -1163,6 +1216,87 @@ namespace Discord.API | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands", commands, bucket, options: options)).ConfigureAwait(false); | return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands", commands, bucket, options: options)).ConfigureAwait(false); | ||||
| } | } | ||||
| public async Task<ApplicationCommand> CreateGuildApplicationUserCommandAsync(CreateApplicationCommandParams command, ulong guildId, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| var bucket = new BucketIds(guildId: guildId); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("POST", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands", command, bucket, options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand> ModifyGuildApplicationUserCommandAsync(ModifyApplicationCommandParams command, ulong guildId, ulong commandId, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| var bucket = new BucketIds(guildId: guildId); | |||||
| try | |||||
| { | |||||
| return await SendJsonAsync<ApplicationCommand>("PATCH", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands/{commandId}", command, bucket, options: options).ConfigureAwait(false); | |||||
| } | |||||
| catch (HttpException x) | |||||
| { | |||||
| if (x.HttpCode == HttpStatusCode.BadRequest) | |||||
| { | |||||
| var json = (x.Request as JsonRestRequest).Json; | |||||
| throw new ApplicationCommandException(json, x); | |||||
| } | |||||
| // Re-throw the http exception | |||||
| throw; | |||||
| } | |||||
| } | |||||
| public async Task<ApplicationCommand[]> BulkOverwriteGuildApplicationUserCommands(ulong guildId, CreateApplicationCommandParams[] commands, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| var bucket = new BucketIds(guildId: guildId); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands", commands, bucket, options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand> CreateGuildApplicationMessageCommandAsync(CreateApplicationCommandParams command, ulong guildId, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| var bucket = new BucketIds(guildId: guildId); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand>("POST", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands", command, bucket, options: options)).ConfigureAwait(false); | |||||
| } | |||||
| public async Task<ApplicationCommand> ModifyGuildApplicationMessageCommandAsync(ModifyApplicationCommandParams command, ulong guildId, ulong commandId, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| var bucket = new BucketIds(guildId: guildId); | |||||
| try | |||||
| { | |||||
| return await SendJsonAsync<ApplicationCommand>("PATCH", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands/{commandId}", command, bucket, options: options).ConfigureAwait(false); | |||||
| } | |||||
| catch (HttpException x) | |||||
| { | |||||
| if (x.HttpCode == HttpStatusCode.BadRequest) | |||||
| { | |||||
| var json = (x.Request as JsonRestRequest).Json; | |||||
| throw new ApplicationCommandException(json, x); | |||||
| } | |||||
| // Re-throw the http exception | |||||
| throw; | |||||
| } | |||||
| } | |||||
| public async Task<ApplicationCommand[]> BulkOverwriteGuildApplicationMessageCommands(ulong guildId, CreateApplicationCommandParams[] commands, RequestOptions options = null) | |||||
| { | |||||
| options = RequestOptions.CreateOrClone(options); | |||||
| var bucket = new BucketIds(guildId: guildId); | |||||
| return await TrySendApplicationCommand(SendJsonAsync<ApplicationCommand[]>("PUT", () => $"applications/{this.CurrentUserId}/guilds/{guildId}/commands", commands, bucket, options: options)).ConfigureAwait(false); | |||||
| } | |||||
| //Interaction Responses | //Interaction Responses | ||||
| public async Task CreateInteractionResponse(InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) | public async Task CreateInteractionResponse(InteractionResponse response, ulong interactionId, string interactionToken, RequestOptions options = null) | ||||
| { | { | ||||
| @@ -1,3 +1,4 @@ | |||||
| //using Discord.Rest.Entities.Interactions; | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
| @@ -111,10 +112,26 @@ namespace Discord.Rest | |||||
| => InteractionHelper.CreateGlobalCommand(this, properties, options); | => InteractionHelper.CreateGlobalCommand(this, properties, options); | ||||
| public Task<RestGlobalCommand> CreateGlobalCommand(Action<SlashCommandCreationProperties> func, RequestOptions options = null) | public Task<RestGlobalCommand> CreateGlobalCommand(Action<SlashCommandCreationProperties> func, RequestOptions options = null) | ||||
| => InteractionHelper.CreateGlobalCommand(this, func, options); | => InteractionHelper.CreateGlobalCommand(this, func, options); | ||||
| public Task<RestGlobalUserCommand> CreateGlobalUserCommand(UserCommandCreationProperties properties, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGlobalUserCommand(this, properties, options); | |||||
| public Task<RestGlobalUserCommand> CreateGlobalUserCommand(Action<UserCommandCreationProperties> func, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGlobalUserCommand(this, func, options); | |||||
| public Task<RestGlobalMessageCommand> CreateGlobalMessageCommand(MessageCommandCreationProperties properties, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGlobalMessageCommand(this, properties, options); | |||||
| public Task<RestGlobalMessageCommand> CreateGlobalMessageCommand(Action<MessageCommandCreationProperties> func, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGlobalMessageCommand(this, func, options); | |||||
| public Task<RestGuildCommand> CreateGuildCommand(SlashCommandCreationProperties properties, ulong guildId, RequestOptions options = null) | public Task<RestGuildCommand> CreateGuildCommand(SlashCommandCreationProperties properties, ulong guildId, RequestOptions options = null) | ||||
| => InteractionHelper.CreateGuildCommand(this, guildId, properties, options); | => InteractionHelper.CreateGuildCommand(this, guildId, properties, options); | ||||
| public Task<RestGuildCommand> CreateGuildCommand(Action<SlashCommandCreationProperties> func, ulong guildId, RequestOptions options = null) | public Task<RestGuildCommand> CreateGuildCommand(Action<SlashCommandCreationProperties> func, ulong guildId, RequestOptions options = null) | ||||
| => InteractionHelper.CreateGuildCommand(this, guildId, func, options); | => InteractionHelper.CreateGuildCommand(this, guildId, func, options); | ||||
| public Task<RestGuildUserCommand> CreateGuildUserCommand(UserCommandCreationProperties properties, ulong guildId, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGuildUserCommand(this, guildId, properties, options); | |||||
| public Task<RestGuildUserCommand> CreateGuildUserCommand(Action<UserCommandCreationProperties> func, ulong guildId, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGuildUserCommand(this, guildId, func, options); | |||||
| public Task<RestGuildMessageCommand> CreateGuildMessageCommand(MessageCommandCreationProperties properties, ulong guildId, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGuildMessageCommand(this, guildId, properties, options); | |||||
| public Task<RestGuildMessageCommand> CreateGuildMessageCommand(Action<MessageCommandCreationProperties> func, ulong guildId, RequestOptions options = null) | |||||
| => InteractionHelper.CreateGuildMessageCommand(this, guildId, func, options); | |||||
| public Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommands(RequestOptions options = null) | public Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommands(RequestOptions options = null) | ||||
| => ClientHelper.GetGlobalApplicationCommands(this, options); | => ClientHelper.GetGlobalApplicationCommands(this, options); | ||||
| public Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommands(ulong guildId, RequestOptions options = null) | public Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommands(ulong guildId, RequestOptions options = null) | ||||
| @@ -1,6 +1,7 @@ | |||||
| using Discord.API; | using Discord.API; | ||||
| using Discord.API.Rest; | using Discord.API.Rest; | ||||
| using Discord.Net; | using Discord.Net; | ||||
| //using Discord.Rest.Entities.Interactions; | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | using System.Linq; | ||||
| @@ -63,6 +64,7 @@ namespace Discord.Rest | |||||
| { | { | ||||
| Name = arg.Name, | Name = arg.Name, | ||||
| Description = arg.Description, | Description = arg.Description, | ||||
| Type= arg.Type, | |||||
| Options = arg.Options.IsSpecified | Options = arg.Options.IsSpecified | ||||
| ? arg.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ? arg.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ||||
| : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | ||||
| @@ -94,6 +96,7 @@ namespace Discord.Rest | |||||
| { | { | ||||
| Name = arg.Name, | Name = arg.Name, | ||||
| Description = arg.Description, | Description = arg.Description, | ||||
| Type = arg.Type, | |||||
| Options = arg.Options.IsSpecified | Options = arg.Options.IsSpecified | ||||
| ? arg.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ? arg.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ||||
| : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | ||||
| @@ -129,6 +132,7 @@ namespace Discord.Rest | |||||
| { | { | ||||
| Name = arg.Name, | Name = arg.Name, | ||||
| Description = arg.Description, | Description = arg.Description, | ||||
| Type = arg.Type, | |||||
| Options = arg.Options.IsSpecified | Options = arg.Options.IsSpecified | ||||
| ? arg.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ? arg.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ||||
| : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | ||||
| @@ -173,6 +177,7 @@ namespace Discord.Rest | |||||
| { | { | ||||
| Name = args.Name, | Name = args.Name, | ||||
| Description = args.Description, | Description = args.Description, | ||||
| Type = args.Type, | |||||
| Options = args.Options.IsSpecified | Options = args.Options.IsSpecified | ||||
| ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ||||
| : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | ||||
| @@ -195,6 +200,174 @@ namespace Discord.Rest | |||||
| await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false); | await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task<RestGlobalUserCommand> CreateGlobalUserCommand(BaseDiscordClient client, Action<UserCommandCreationProperties> func, RequestOptions options = null) | |||||
| { | |||||
| var args = new UserCommandCreationProperties(); | |||||
| func(args); | |||||
| return await CreateGlobalUserCommand(client, args, options).ConfigureAwait(false); | |||||
| } | |||||
| public static async Task<RestGlobalUserCommand> CreateGlobalUserCommand(BaseDiscordClient client, UserCommandCreationProperties arg, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.Equals(arg.Description, ""); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| var cmd = await client.ApiClient.CreateGlobalApplicationUserCommandAsync(model, options).ConfigureAwait(false); | |||||
| return RestGlobalUserCommand.Create(client, cmd); | |||||
| } | |||||
| public static async Task<RestGlobalMessageCommand> CreateGlobalMessageCommand(BaseDiscordClient client, Action<MessageCommandCreationProperties> func, RequestOptions options = null) | |||||
| { | |||||
| var args = new MessageCommandCreationProperties(); | |||||
| func(args); | |||||
| return await CreateGlobalMessageCommand(client, args, options).ConfigureAwait(false); | |||||
| } | |||||
| public static async Task<RestGlobalMessageCommand> CreateGlobalMessageCommand(BaseDiscordClient client, MessageCommandCreationProperties arg, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.Equals(arg.Description, ""); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| var cmd = await client.ApiClient.CreateGlobalApplicationMessageCommandAsync(model, options).ConfigureAwait(false); | |||||
| return RestGlobalMessageCommand.Create(client, cmd); | |||||
| } | |||||
| public static async Task<IReadOnlyCollection<RestGlobalUserCommand>> BulkOverwriteGlobalUserCommands(BaseDiscordClient client, UserCommandCreationProperties[] args, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNull(args, nameof(args)); | |||||
| List<CreateApplicationCommandParams> models = new List<CreateApplicationCommandParams>(); | |||||
| foreach (var arg in args) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.NotNullOrEmpty(arg.Description, nameof(arg.Description)); | |||||
| Preconditions.Equals(arg.Type, ApplicationCommandType.User); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| models.Add(model); | |||||
| } | |||||
| var apiModels = await client.ApiClient.BulkOverwriteGlobalApplicationUserCommands(models.ToArray(), options); | |||||
| return apiModels.Select(x => RestGlobalUserCommand.Create(client, x)).ToArray(); | |||||
| } | |||||
| public static async Task<RestGlobalUserCommand> ModifyGlobalUserCommand(BaseDiscordClient client, RestGlobalUserCommand command, | |||||
| Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| { | |||||
| ApplicationCommandProperties args = new ApplicationCommandProperties(); | |||||
| func(args); | |||||
| if (args.Name.IsSpecified) | |||||
| { | |||||
| Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); | |||||
| Preconditions.AtLeast(args.Name.Value.Length, 3, nameof(args.Name)); | |||||
| } | |||||
| if (args.Description.IsSpecified) | |||||
| { | |||||
| Preconditions.Equals(args.Description.Value, ""); | |||||
| } | |||||
| var model = new Discord.API.Rest.ModifyApplicationCommandParams() | |||||
| { | |||||
| Name = args.Name, | |||||
| Description = args.Description | |||||
| }; | |||||
| var msg = await client.ApiClient.ModifyGlobalApplicationUserCommandAsync(model, command.Id, options).ConfigureAwait(false); | |||||
| command.Update(msg); | |||||
| return command; | |||||
| } | |||||
| public static async Task DeleteGlobalUserCommand(BaseDiscordClient client, RestGlobalUserCommand 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); | |||||
| } | |||||
| public static async Task<IReadOnlyCollection<RestGlobalMessageCommand>> BulkOverwriteGlobalMessageCommands(BaseDiscordClient client, MessageCommandCreationProperties[] args, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNull(args, nameof(args)); | |||||
| List<CreateApplicationCommandParams> models = new List<CreateApplicationCommandParams>(); | |||||
| foreach (var arg in args) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.NotNullOrEmpty(arg.Description, nameof(arg.Description)); | |||||
| Preconditions.Equals(arg.Type, ApplicationCommandType.Message); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| models.Add(model); | |||||
| } | |||||
| var apiModels = await client.ApiClient.BulkOverwriteGlobalApplicationMessageCommands(models.ToArray(), options); | |||||
| return apiModels.Select(x => RestGlobalMessageCommand.Create(client, x)).ToArray(); | |||||
| } | |||||
| public static async Task<RestGlobalMessageCommand> ModifyGlobalMessageCommand(BaseDiscordClient client, RestGlobalMessageCommand command, | |||||
| Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| { | |||||
| ApplicationCommandProperties args = new ApplicationCommandProperties(); | |||||
| func(args); | |||||
| if (args.Name.IsSpecified) | |||||
| { | |||||
| Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); | |||||
| Preconditions.AtLeast(args.Name.Value.Length, 3, nameof(args.Name)); | |||||
| } | |||||
| if (args.Description.IsSpecified) | |||||
| { | |||||
| Preconditions.Equals(args.Description.Value, ""); | |||||
| } | |||||
| var model = new Discord.API.Rest.ModifyApplicationCommandParams() | |||||
| { | |||||
| Name = args.Name, | |||||
| Description = args.Description | |||||
| }; | |||||
| var msg = await client.ApiClient.ModifyGlobalApplicationMessageCommandAsync(model, command.Id, options).ConfigureAwait(false); | |||||
| command.Update(msg); | |||||
| return command; | |||||
| } | |||||
| public static async Task DeleteGlobalMessageCommand(BaseDiscordClient client, RestGlobalMessageCommand 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); | |||||
| } | |||||
| // Guild Commands | // Guild Commands | ||||
| public static async Task<RestGuildCommand> CreateGuildCommand(BaseDiscordClient client, ulong guildId, | public static async Task<RestGuildCommand> CreateGuildCommand(BaseDiscordClient client, ulong guildId, | ||||
| Action<SlashCommandCreationProperties> func, RequestOptions options = null) | Action<SlashCommandCreationProperties> func, RequestOptions options = null) | ||||
| @@ -231,6 +404,7 @@ namespace Discord.Rest | |||||
| { | { | ||||
| Name = args.Name, | Name = args.Name, | ||||
| Description = args.Description, | Description = args.Description, | ||||
| Type = args.Type, | |||||
| Options = args.Options.IsSpecified | Options = args.Options.IsSpecified | ||||
| ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ||||
| : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | ||||
| @@ -269,6 +443,7 @@ namespace Discord.Rest | |||||
| { | { | ||||
| Name = args.Name, | Name = args.Name, | ||||
| Description = args.Description, | Description = args.Description, | ||||
| Type = args.Type, | |||||
| Options = args.Options.IsSpecified | Options = args.Options.IsSpecified | ||||
| ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() | ||||
| : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified, | ||||
| @@ -290,6 +465,177 @@ namespace Discord.Rest | |||||
| await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false); | await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task<RestGuildUserCommand> CreateGuildUserCommand(BaseDiscordClient client, ulong guildId, Action<UserCommandCreationProperties> func, RequestOptions options = null) | |||||
| { | |||||
| var args = new UserCommandCreationProperties(); | |||||
| func(args); | |||||
| return await CreateGuildUserCommand(client, guildId, args, options).ConfigureAwait(false); | |||||
| } | |||||
| public static async Task<RestGuildUserCommand> CreateGuildUserCommand(BaseDiscordClient client, ulong guildId, UserCommandCreationProperties arg, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.Equals(arg.Description, ""); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| var cmd = await client.ApiClient.CreateGuildApplicationUserCommandAsync(model, guildId, options).ConfigureAwait(false); | |||||
| return RestGuildUserCommand.Create(client, cmd, guildId); | |||||
| } | |||||
| public static async Task<RestGuildMessageCommand> CreateGuildMessageCommand(BaseDiscordClient client, ulong guildId, Action<MessageCommandCreationProperties> func, RequestOptions options = null) | |||||
| { | |||||
| var args = new MessageCommandCreationProperties(); | |||||
| func(args); | |||||
| return await CreateGuildMessageCommand(client, guildId, args, options).ConfigureAwait(false); | |||||
| } | |||||
| public static async Task<RestGuildMessageCommand> CreateGuildMessageCommand(BaseDiscordClient client, ulong guildId, MessageCommandCreationProperties arg, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.Equals(arg.Description, ""); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| var cmd = await client.ApiClient.CreateGuildApplicationMessageCommandAsync(model, guildId, options).ConfigureAwait(false); | |||||
| return RestGuildMessageCommand.Create(client, cmd, guildId); | |||||
| } | |||||
| public static async Task<IReadOnlyCollection<RestGuildUserCommand>> BulkOverwriteGuildUserCommands(BaseDiscordClient client, ulong guildId, UserCommandCreationProperties[] args, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNull(args, nameof(args)); | |||||
| List<CreateApplicationCommandParams> models = new List<CreateApplicationCommandParams>(); | |||||
| foreach (var arg in args) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.NotNullOrEmpty(arg.Description, nameof(arg.Description)); | |||||
| Preconditions.Equals(arg.Type, ApplicationCommandType.User); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| models.Add(model); | |||||
| } | |||||
| var apiModels = await client.ApiClient.BulkOverwriteGuildApplicationUserCommands(guildId, models.ToArray(), options); | |||||
| return apiModels.Select(x => RestGuildUserCommand.Create(client, x, guildId)).ToArray(); | |||||
| } | |||||
| public static async Task<RestGuildUserCommand> ModifyGuildUserCommand(BaseDiscordClient client, RestGuildUserCommand command, | |||||
| Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| { | |||||
| ApplicationCommandProperties args = new ApplicationCommandProperties(); | |||||
| func(args); | |||||
| if (args.Name.IsSpecified) | |||||
| { | |||||
| Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); | |||||
| Preconditions.AtLeast(args.Name.Value.Length, 3, nameof(args.Name)); | |||||
| } | |||||
| if (args.Description.IsSpecified) | |||||
| { | |||||
| Preconditions.Equals(args.Description.Value, ""); | |||||
| } | |||||
| var model = new Discord.API.Rest.ModifyApplicationCommandParams() | |||||
| { | |||||
| Name = args.Name, | |||||
| Description = args.Description, | |||||
| Type=args.Type | |||||
| }; | |||||
| var msg = await client.ApiClient.ModifyGuildApplicationUserCommandAsync(model, command.GuildId, command.Id, options).ConfigureAwait(false); | |||||
| command.Update(msg); | |||||
| return command; | |||||
| } | |||||
| public static async Task DeleteGuildUserCommand(BaseDiscordClient client, ulong guildId, RestGuildUserCommand 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); | |||||
| } | |||||
| public static async Task<IReadOnlyCollection<RestGuildMessageCommand>> BulkOverwriteGuildMessageCommands(BaseDiscordClient client, ulong guildId, MessageCommandCreationProperties[] args, RequestOptions options = null) | |||||
| { | |||||
| Preconditions.NotNull(args, nameof(args)); | |||||
| List<CreateApplicationCommandParams> models = new List<CreateApplicationCommandParams>(); | |||||
| foreach (var arg in args) | |||||
| { | |||||
| Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); | |||||
| Preconditions.NotNullOrEmpty(arg.Description, nameof(arg.Description)); | |||||
| Preconditions.Equals(arg.Type, ApplicationCommandType.Message); | |||||
| var model = new CreateApplicationCommandParams() | |||||
| { | |||||
| Name = arg.Name, | |||||
| Description = arg.Description, | |||||
| Type = arg.Type | |||||
| }; | |||||
| models.Add(model); | |||||
| } | |||||
| var apiModels = await client.ApiClient.BulkOverwriteGuildApplicationMessageCommands(guildId, models.ToArray(), options); | |||||
| return apiModels.Select(x => RestGuildMessageCommand.Create(client, x, guildId)).ToArray(); | |||||
| } | |||||
| public static async Task<RestGuildMessageCommand> ModifyGuildMessageCommand(BaseDiscordClient client, RestGuildMessageCommand command, | |||||
| Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| { | |||||
| ApplicationCommandProperties args = new ApplicationCommandProperties(); | |||||
| func(args); | |||||
| if (args.Name.IsSpecified) | |||||
| { | |||||
| Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); | |||||
| Preconditions.AtLeast(args.Name.Value.Length, 3, nameof(args.Name)); | |||||
| } | |||||
| if (args.Description.IsSpecified) | |||||
| { | |||||
| Preconditions.Equals(args.Description.Value, ""); | |||||
| } | |||||
| var model = new Discord.API.Rest.ModifyApplicationCommandParams() | |||||
| { | |||||
| Name = args.Name, | |||||
| Description = args.Description, | |||||
| Type = args.Type | |||||
| }; | |||||
| var msg = await client.ApiClient.ModifyGuildApplicationMessageCommandAsync(model, command.GuildId, command.Id, options).ConfigureAwait(false); | |||||
| command.Update(msg); | |||||
| return command; | |||||
| } | |||||
| public static async Task DeleteGuildMessageCommand(BaseDiscordClient client, ulong guildId, RestGuildMessageCommand 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); | |||||
| } | |||||
| public static async Task<Discord.API.Message> ModifyFollowupMessage(BaseDiscordClient client, RestFollowupMessage message, Action<MessageProperties> func, | public static async Task<Discord.API.Message> ModifyFollowupMessage(BaseDiscordClient client, RestFollowupMessage message, Action<MessageProperties> func, | ||||
| RequestOptions options = null) | RequestOptions options = null) | ||||
| { | { | ||||
| @@ -16,6 +16,9 @@ namespace Discord.Rest | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public ulong ApplicationId { get; private set; } | public ulong ApplicationId { get; private set; } | ||||
| /// <inheritdoc/> | |||||
| public ApplicationCommandType Type { get; private set; } | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public string Name { get; private set; } | public string Name { get; private set; } | ||||
| @@ -47,13 +50,30 @@ namespace Discord.Rest | |||||
| internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, RestApplicationCommandType type, ulong guildId = 0) | internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, RestApplicationCommandType type, ulong guildId = 0) | ||||
| { | { | ||||
| if (type == RestApplicationCommandType.GlobalCommand) | |||||
| return RestGlobalCommand.Create(client, model); | |||||
| if (type == RestApplicationCommandType.GuildCommand) | |||||
| return RestGuildCommand.Create(client, model, guildId); | |||||
| return null; | |||||
| switch (type) | |||||
| { | |||||
| case RestApplicationCommandType.GlobalCommand: | |||||
| return RestGlobalCommand.Create(client, model); | |||||
| break; | |||||
| case RestApplicationCommandType.GlobalUserCommand: | |||||
| return RestGlobalUserCommand.Create(client, model); | |||||
| break; | |||||
| case RestApplicationCommandType.GlobalMessageCommand: | |||||
| return RestGlobalMessageCommand.Create(client, model); | |||||
| break; | |||||
| case RestApplicationCommandType.GuildCommand: | |||||
| return RestGuildCommand.Create(client, model, guildId); | |||||
| break; | |||||
| case RestApplicationCommandType.GuildUserCommand: | |||||
| return RestGuildUserCommand.Create(client, model, guildId); | |||||
| break; | |||||
| case RestApplicationCommandType.GuildMessageCommand: | |||||
| return RestGuildMessageCommand.Create(client, model, guildId); | |||||
| break; | |||||
| default: | |||||
| return null; | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| internal virtual void Update(Model model) | internal virtual void Update(Model model) | ||||
| @@ -15,10 +15,14 @@ namespace Discord.Rest | |||||
| /// Specifies that this command is a Global command. | /// Specifies that this command is a Global command. | ||||
| /// </summary> | /// </summary> | ||||
| GlobalCommand, | GlobalCommand, | ||||
| GlobalUserCommand, | |||||
| GlobalMessageCommand, | |||||
| /// <summary> | /// <summary> | ||||
| /// Specifies that this command is a Guild specific command. | /// Specifies that this command is a Guild specific command. | ||||
| /// </summary> | /// </summary> | ||||
| GuildCommand | |||||
| GuildCommand, | |||||
| GuildUserCommand, | |||||
| GuildMessageCommand | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,41 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Reflection; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Model = Discord.API.ApplicationCommand; | |||||
| namespace Discord.Rest | |||||
| { | |||||
| public class RestGlobalMessageCommand : RestApplicationCommand | |||||
| { | |||||
| internal RestGlobalMessageCommand(BaseDiscordClient client, ulong id) | |||||
| : base(client, id) | |||||
| { | |||||
| this.CommandType = RestApplicationCommandType.GlobalMessageCommand; | |||||
| } | |||||
| internal static RestGlobalMessageCommand Create(BaseDiscordClient client, Model model) | |||||
| { | |||||
| var entity = new RestGlobalMessageCommand(client, model.Id); | |||||
| entity.Update(model); | |||||
| return entity; | |||||
| } | |||||
| /// <inheritdoc/> | |||||
| public override async Task DeleteAsync(RequestOptions options = null) | |||||
| => await InteractionHelper.DeleteGlobalMessageCommand(Discord, this).ConfigureAwait(false); | |||||
| /// <summary> | |||||
| /// Modifies this <see cref="RestApplicationCommand"/>. | |||||
| /// </summary> | |||||
| /// <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// The modified command. | |||||
| /// </returns> | |||||
| public async Task<RestGlobalMessageCommand> ModifyAsync(Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| => await InteractionHelper.ModifyGlobalMessageCommand(Discord, this, func, options).ConfigureAwait(false); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,41 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Reflection; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Model = Discord.API.ApplicationCommand; | |||||
| namespace Discord.Rest | |||||
| { | |||||
| public class RestGlobalUserCommand : RestApplicationCommand | |||||
| { | |||||
| internal RestGlobalUserCommand(BaseDiscordClient client, ulong id) | |||||
| : base(client, id) | |||||
| { | |||||
| this.CommandType = RestApplicationCommandType.GlobalUserCommand; | |||||
| } | |||||
| internal static RestGlobalUserCommand Create(BaseDiscordClient client, Model model) | |||||
| { | |||||
| var entity = new RestGlobalUserCommand(client, model.Id); | |||||
| entity.Update(model); | |||||
| return entity; | |||||
| } | |||||
| /// <inheritdoc/> | |||||
| public override async Task DeleteAsync(RequestOptions options = null) | |||||
| => await InteractionHelper.DeleteGlobalUserCommand(Discord, this).ConfigureAwait(false); | |||||
| /// <summary> | |||||
| /// Modifies this <see cref="RestApplicationCommand"/>. | |||||
| /// </summary> | |||||
| /// <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// The modified command. | |||||
| /// </returns> | |||||
| public async Task<RestGlobalUserCommand> ModifyAsync(Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| => await InteractionHelper.ModifyGlobalUserCommand(Discord, this, func, options).ConfigureAwait(false); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,61 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Model = Discord.API.ApplicationCommand; | |||||
| namespace Discord.Rest | |||||
| { | |||||
| /// <summary> | |||||
| /// Represents a Rest-based guild command. | |||||
| /// </summary> | |||||
| public class RestGuildMessageCommand : RestApplicationCommand | |||||
| { | |||||
| /// <summary> | |||||
| /// The guild Id where this command originates. | |||||
| /// </summary> | |||||
| public ulong GuildId { get; private set; } | |||||
| internal RestGuildMessageCommand(BaseDiscordClient client, ulong id, ulong guildId) | |||||
| : base(client, id) | |||||
| { | |||||
| this.CommandType = RestApplicationCommandType.GuildMessageCommand; | |||||
| this.GuildId = guildId; | |||||
| } | |||||
| internal static RestGuildMessageCommand Create(BaseDiscordClient client, Model model, ulong guildId) | |||||
| { | |||||
| var entity = new RestGuildMessageCommand(client, model.Id, guildId); | |||||
| entity.Update(model); | |||||
| return entity; | |||||
| } | |||||
| /// <inheritdoc/> | |||||
| public override async Task DeleteAsync(RequestOptions options = null) | |||||
| => await InteractionHelper.DeleteGuildMessageCommand(Discord, GuildId, this).ConfigureAwait(false); | |||||
| /// <summary> | |||||
| /// Modifies this <see cref="RestApplicationCommand"/>. | |||||
| /// </summary> | |||||
| /// <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// The modified command | |||||
| /// </returns> | |||||
| public async Task<RestGuildMessageCommand> ModifyAsync(Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| => await InteractionHelper.ModifyGuildMessageCommand(Discord, this, func, options).ConfigureAwait(false); | |||||
| /// <summary> | |||||
| /// Gets the guild that this slash command resides in. | |||||
| /// </summary> | |||||
| /// <param name="withCounts"><see langword="true"/> if you want the approximate member and presence counts for the guild, otherwise <see langword="false"/>.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// A task that represents the asynchronous get operation. The task result contains a | |||||
| /// <see cref="RestGuild"/>. | |||||
| /// </returns> | |||||
| public Task<RestGuild> GetGuild(bool withCounts = false, RequestOptions options = null) | |||||
| => ClientHelper.GetGuildAsync(this.Discord, this.GuildId, withCounts, options); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,61 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using Model = Discord.API.ApplicationCommand; | |||||
| namespace Discord.Rest | |||||
| { | |||||
| /// <summary> | |||||
| /// Represents a Rest-based guild command. | |||||
| /// </summary> | |||||
| public class RestGuildUserCommand : RestApplicationCommand | |||||
| { | |||||
| /// <summary> | |||||
| /// The guild Id where this command originates. | |||||
| /// </summary> | |||||
| public ulong GuildId { get; private set; } | |||||
| internal RestGuildUserCommand(BaseDiscordClient client, ulong id, ulong guildId) | |||||
| : base(client, id) | |||||
| { | |||||
| this.CommandType = RestApplicationCommandType.GuildUserCommand; | |||||
| this.GuildId = guildId; | |||||
| } | |||||
| internal static RestGuildUserCommand Create(BaseDiscordClient client, Model model, ulong guildId) | |||||
| { | |||||
| var entity = new RestGuildUserCommand(client, model.Id, guildId); | |||||
| entity.Update(model); | |||||
| return entity; | |||||
| } | |||||
| /// <inheritdoc/> | |||||
| public override async Task DeleteAsync(RequestOptions options = null) | |||||
| => await InteractionHelper.DeleteGuildUserCommand(Discord, GuildId, this).ConfigureAwait(false); | |||||
| /// <summary> | |||||
| /// Modifies this <see cref="RestApplicationCommand"/>. | |||||
| /// </summary> | |||||
| /// <param name="func">The delegate containing the properties to modify the command with.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// The modified command | |||||
| /// </returns> | |||||
| public async Task<RestGuildUserCommand> ModifyAsync(Action<ApplicationCommandProperties> func, RequestOptions options = null) | |||||
| => await InteractionHelper.ModifyGuildUserCommand(Discord, this, func, options).ConfigureAwait(false); | |||||
| /// <summary> | |||||
| /// Gets the guild that this slash command resides in. | |||||
| /// </summary> | |||||
| /// <param name="withCounts"><see langword="true"/> if you want the approximate member and presence counts for the guild, otherwise <see langword="false"/>.</param> | |||||
| /// <param name="options">The options to be used when sending the request.</param> | |||||
| /// <returns> | |||||
| /// A task that represents the asynchronous get operation. The task result contains a | |||||
| /// <see cref="RestGuild"/>. | |||||
| /// </returns> | |||||
| public Task<RestGuild> GetGuild(bool withCounts = false, RequestOptions options = null) | |||||
| => ClientHelper.GetGuildAsync(this.Discord, this.GuildId, withCounts, options); | |||||
| } | |||||
| } | |||||
| @@ -3668,6 +3668,9 @@ | |||||
| <member name="P:Discord.WebSocket.SocketApplicationCommand.Name"> | <member name="P:Discord.WebSocket.SocketApplicationCommand.Name"> | ||||
| <inheritdoc/> | <inheritdoc/> | ||||
| </member> | </member> | ||||
| <member name="P:Discord.WebSocket.SocketApplicationCommand.Type"> | |||||
| <inheritdoc/> | |||||
| </member> | |||||
| <member name="P:Discord.WebSocket.SocketApplicationCommand.Description"> | <member name="P:Discord.WebSocket.SocketApplicationCommand.Description"> | ||||
| <inheritdoc/> | <inheritdoc/> | ||||
| </member> | </member> | ||||
| @@ -20,6 +20,9 @@ namespace Discord.WebSocket | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public string Name { get; private set; } | public string Name { get; private set; } | ||||
| /// <inheritdoc/> | |||||
| public ApplicationCommandType Type { get; private set; } | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public string Description { get; private set; } | public string Description { get; private set; } | ||||