From 56b1a930e7c62dc1497f4b3d6023a20e4c8d143c Mon Sep 17 00:00:00 2001 From: Misha133 <61027276+Misha-133@users.noreply.github.com> Date: Tue, 20 Dec 2022 01:00:56 +0300 Subject: [PATCH] [Feature] Age restricted (NSFW) application commands support (#2531) * add `nsfw` to data model & internal methods; add missing property * add `nsfw` prop to command builders * add `NsfwCommandAttribute` to Interaction Framework * working state * docs? --- docs/guides/int_framework/permissions.md | 5 ++++ .../samples/permissions/nsfw-permissions.cs | 6 +++++ .../ApplicationCommandProperties.cs | 5 ++++ .../ContextMenus/MessageCommandBuilder.cs | 21 ++++++++++++++-- .../ContextMenus/UserCommandBuilder.cs | 21 ++++++++++++++-- .../Interactions/IApplicationCommand.cs | 5 ++++ .../SlashCommands/SlashCommandBuilder.cs | 21 ++++++++++++++-- .../Attributes/NsfwCommandAttribute.cs | 25 +++++++++++++++++++ .../Commands/ContextCommandBuilder.cs | 18 +++++++++++++ .../Builders/Commands/SlashCommandBuilder.cs | 18 +++++++++++++ .../Builders/ModuleBuilder.cs | 18 +++++++++++++ .../Builders/ModuleClassBuilder.cs | 9 +++++++ .../ContextCommands/ContextCommandInfo.cs | 4 +++ .../Info/Commands/SlashCommandInfo.cs | 4 +++ .../Info/IApplicationCommandInfo.cs | 5 ++++ .../Info/ModuleInfo.cs | 6 +++++ .../Utilities/ApplicationCommandRestUtil.cs | 9 ++++++- .../API/Common/ApplicationCommand.cs | 3 +++ .../Rest/CreateApplicationCommandParams.cs | 6 ++++- .../Rest/ModifyApplicationCommandParams.cs | 6 +++++ .../Interactions/InteractionHelper.cs | 22 ++++++++++------ .../Interactions/RestApplicationCommand.cs | 4 +++ .../SocketApplicationCommand.cs | 4 +++ 23 files changed, 230 insertions(+), 15 deletions(-) create mode 100644 docs/guides/int_framework/samples/permissions/nsfw-permissions.cs create mode 100644 src/Discord.Net.Interactions/Attributes/NsfwCommandAttribute.cs diff --git a/docs/guides/int_framework/permissions.md b/docs/guides/int_framework/permissions.md index e35bb162d..f02c50ebb 100644 --- a/docs/guides/int_framework/permissions.md +++ b/docs/guides/int_framework/permissions.md @@ -55,5 +55,10 @@ The amount of nesting you can do is realistically endless. > If the nested class is marked with `Group`, as required for setting up subcommands, this example will not work. > As mentioned before, subcommands cannot have seperate permissions from the top level command. +### NSFW Commands +Commands can be limited to only age restricted channels and DMs: + +[!code-csharp[Nsfw-Permissions](samples/permissions/nsfw-permissions.cs)] + [permissions]: xref:Discord.GuildPermission diff --git a/docs/guides/int_framework/samples/permissions/nsfw-permissions.cs b/docs/guides/int_framework/samples/permissions/nsfw-permissions.cs new file mode 100644 index 000000000..21f93b54d --- /dev/null +++ b/docs/guides/int_framework/samples/permissions/nsfw-permissions.cs @@ -0,0 +1,6 @@ +[NsfwCommand(true)] +[SlashCommand("beautiful-code", "Get an image of perfect code")] +public async Task BeautifulCodeAsync(...) +{ + ... +} \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs index 0c1c628cd..78182c404 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs @@ -83,6 +83,11 @@ namespace Discord /// public Optional IsDMEnabled { get; set; } + /// + /// Gets or sets whether or not this command is age restricted. + /// + public Optional IsNsfw { get; set; } + /// /// Gets or sets the default permissions required by a user to execute this application command. /// diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandBuilder.cs index 613e30376..b7037cc63 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/MessageCommandBuilder.cs @@ -46,6 +46,11 @@ namespace Discord /// public bool IsDMEnabled { get; set; } = true; + /// + /// Gets or sets whether or not this command is age restricted. + /// + public bool IsNsfw{ get; set; } = false; + /// /// Gets or sets the default permission required to use this slash command. /// @@ -68,7 +73,8 @@ namespace Discord IsDefaultPermission = IsDefaultPermission, IsDMEnabled = IsDMEnabled, DefaultMemberPermissions = DefaultMemberPermissions ?? Optional.Unspecified, - NameLocalizations = NameLocalizations + NameLocalizations = NameLocalizations, + IsNsfw = IsNsfw, }; return props; @@ -123,7 +129,7 @@ namespace Discord } /// - /// Sets whether or not this command can be used in dms + /// Sets whether or not this command can be used in dms. /// /// if the command is available in dms, otherwise . /// The current builder. @@ -133,6 +139,17 @@ namespace Discord return this; } + /// + /// Sets whether or not this command is age restricted. + /// + /// if the command is age restricted, otherwise . + /// The current builder. + public MessageCommandBuilder WithNsfw(bool permission) + { + IsNsfw = permission; + return this; + } + /// /// Adds a new entry to the collection. /// diff --git a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandBuilder.cs index 8ac524582..85efc4938 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ContextMenus/UserCommandBuilder.cs @@ -46,6 +46,11 @@ namespace Discord /// public bool IsDMEnabled { get; set; } = true; + /// + /// Gets or sets whether or not this command is age restricted. + /// + public bool IsNsfw { get; set; } = false; + /// /// Gets or sets the default permission required to use this slash command. /// @@ -66,7 +71,8 @@ namespace Discord IsDefaultPermission = IsDefaultPermission, IsDMEnabled = IsDMEnabled, DefaultMemberPermissions = DefaultMemberPermissions ?? Optional.Unspecified, - NameLocalizations = NameLocalizations + NameLocalizations = NameLocalizations, + IsNsfw = IsNsfw, }; return props; @@ -121,7 +127,7 @@ namespace Discord } /// - /// Sets whether or not this command can be used in dms + /// Sets whether or not this command can be used in dms. /// /// if the command is available in dms, otherwise . /// The current builder. @@ -131,6 +137,17 @@ namespace Discord return this; } + /// + /// Sets whether or not this command is age restricted. + /// + /// if the command is age restricted, otherwise . + /// The current builder. + public UserCommandBuilder WithNsfw(bool permission) + { + IsNsfw = permission; + return this; + } + /// /// Adds a new entry to the collection. /// diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs index 6f9ce7a45..afab93500 100644 --- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs +++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs @@ -42,6 +42,11 @@ namespace Discord /// bool IsEnabledInDm { get; } + /// + /// Indicates whether the command is age restricted. + /// + bool IsNsfw { get; } + /// /// Set of default required to invoke the command. /// diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs index 03fb24c8b..b0b8e9600 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs @@ -84,6 +84,11 @@ namespace Discord /// Gets or sets whether or not this command can be used in DMs. /// public bool IsDMEnabled { get; set; } = true; + + /// + /// Gets or sets whether or not this command is age restricted. + /// + public bool IsNsfw { get; set; } = false; /// /// Gets or sets the default permission required to use this slash command. @@ -110,7 +115,8 @@ namespace Discord NameLocalizations = _nameLocalizations, DescriptionLocalizations = _descriptionLocalizations, IsDMEnabled = IsDMEnabled, - DefaultMemberPermissions = DefaultMemberPermissions ?? Optional.Unspecified + DefaultMemberPermissions = DefaultMemberPermissions ?? Optional.Unspecified, + IsNsfw = IsNsfw, }; if (Options != null && Options.Any()) @@ -161,7 +167,7 @@ namespace Discord } /// - /// Sets whether or not this command can be used in dms + /// Sets whether or not this command can be used in dms. /// /// if the command is available in dms, otherwise . /// The current builder. @@ -171,6 +177,17 @@ namespace Discord return this; } + /// + /// Sets whether or not this command is age restricted. + /// + /// if the command is age restricted, otherwise . + /// The current builder. + public SlashCommandBuilder WithNsfw(bool permission) + { + IsNsfw = permission; + return this; + } + /// /// Sets the default member permissions required to use this application command. /// diff --git a/src/Discord.Net.Interactions/Attributes/NsfwCommandAttribute.cs b/src/Discord.Net.Interactions/Attributes/NsfwCommandAttribute.cs new file mode 100644 index 000000000..b218edb9b --- /dev/null +++ b/src/Discord.Net.Interactions/Attributes/NsfwCommandAttribute.cs @@ -0,0 +1,25 @@ +using System; + +namespace Discord.Interactions +{ + /// + /// Sets the property of an application command or module. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public class NsfwCommandAttribute : Attribute + { + /// + /// Gets whether or not this command is age restricted. + /// + public bool IsNsfw { get; } + + /// + /// Sets the property of an application command or module. + /// + /// Whether or not this command is age restricted. + public NsfwCommandAttribute(bool isNsfw) + { + IsNsfw = isNsfw; + } + } +} diff --git a/src/Discord.Net.Interactions/Builders/Commands/ContextCommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/ContextCommandBuilder.cs index be0e5eb70..ce6d8b504 100644 --- a/src/Discord.Net.Interactions/Builders/Commands/ContextCommandBuilder.cs +++ b/src/Discord.Net.Interactions/Builders/Commands/ContextCommandBuilder.cs @@ -25,6 +25,11 @@ namespace Discord.Interactions.Builders /// public bool IsEnabledInDm { get; set; } = true; + /// + /// Gets whether this command is age restricted. + /// + public bool IsNsfw { get; set; } = false; + /// /// Gets the default permissions needed for executing this command. /// @@ -95,6 +100,19 @@ namespace Discord.Interactions.Builders return this; } + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public ContextCommandBuilder SetNsfw(bool isNsfw) + { + IsNsfw = isNsfw; + return this; + } + /// /// Sets . /// diff --git a/src/Discord.Net.Interactions/Builders/Commands/SlashCommandBuilder.cs b/src/Discord.Net.Interactions/Builders/Commands/SlashCommandBuilder.cs index c21fd5ae8..ead6db3cf 100644 --- a/src/Discord.Net.Interactions/Builders/Commands/SlashCommandBuilder.cs +++ b/src/Discord.Net.Interactions/Builders/Commands/SlashCommandBuilder.cs @@ -25,6 +25,11 @@ namespace Discord.Interactions.Builders /// public bool IsEnabledInDm { get; set; } = true; + /// + /// Gets whether this command is age restricted. + /// + public bool IsNsfw { get; set; } = false; + /// /// Gets the default permissions needed for executing this command. /// @@ -95,6 +100,19 @@ namespace Discord.Interactions.Builders return this; } + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public SlashCommandBuilder SetNsfw(bool isNsfw) + { + IsNsfw = isNsfw; + return this; + } + /// /// Sets . /// diff --git a/src/Discord.Net.Interactions/Builders/ModuleBuilder.cs b/src/Discord.Net.Interactions/Builders/ModuleBuilder.cs index 0eb91ee6a..7da7624cd 100644 --- a/src/Discord.Net.Interactions/Builders/ModuleBuilder.cs +++ b/src/Discord.Net.Interactions/Builders/ModuleBuilder.cs @@ -59,6 +59,11 @@ namespace Discord.Interactions.Builders /// public bool IsEnabledInDm { get; set; } = true; + /// + /// Gets whether this command is age restricted. + /// + public bool IsNsfw { get; set; } = false; + /// /// Gets the default permissions needed for executing this command. /// @@ -190,6 +195,19 @@ namespace Discord.Interactions.Builders return this; } + /// + /// Sets . + /// + /// New value of the . + /// + /// The builder instance. + /// + public ModuleBuilder SetNsfw(bool isNsfw) + { + IsNsfw = isNsfw; + return this; + } + /// /// Sets . /// diff --git a/src/Discord.Net.Interactions/Builders/ModuleClassBuilder.cs b/src/Discord.Net.Interactions/Builders/ModuleClassBuilder.cs index 82acd800d..3f0504e44 100644 --- a/src/Discord.Net.Interactions/Builders/ModuleClassBuilder.cs +++ b/src/Discord.Net.Interactions/Builders/ModuleClassBuilder.cs @@ -101,6 +101,9 @@ namespace Discord.Interactions.Builders case DontAutoRegisterAttribute dontAutoRegister: builder.DontAutoRegister = true; break; + case NsfwCommandAttribute nsfwCommand: + builder.SetNsfw(nsfwCommand.IsNsfw); + break; default: builder.AddAttributes(attribute); break; @@ -192,6 +195,9 @@ namespace Discord.Interactions.Builders case PreconditionAttribute precondition: builder.WithPreconditions(precondition); break; + case NsfwCommandAttribute nsfwCommand: + builder.SetNsfw(nsfwCommand.IsNsfw); + break; default: builder.WithAttributes(attribute); break; @@ -244,6 +250,9 @@ namespace Discord.Interactions.Builders case PreconditionAttribute precondition: builder.WithPreconditions(precondition); break; + case NsfwCommandAttribute nsfwCommand: + builder.SetNsfw(nsfwCommand.IsNsfw); + break; default: builder.WithAttributes(attribute); break; diff --git a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs index 33b82b127..61f79453c 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs @@ -20,6 +20,9 @@ namespace Discord.Interactions /// public bool IsEnabledInDm { get; } + /// + public bool IsNsfw { get; } + /// public GuildPermission? DefaultMemberPermissions { get; } @@ -37,6 +40,7 @@ namespace Discord.Interactions { CommandType = builder.CommandType; DefaultPermission = builder.DefaultPermission; + IsNsfw = builder.IsNsfw; IsEnabledInDm = builder.IsEnabledInDm; DefaultMemberPermissions = builder.DefaultMemberPermissions; Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); diff --git a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs index 634fd9643..ee3939702 100644 --- a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs @@ -29,6 +29,9 @@ namespace Discord.Interactions /// public bool IsEnabledInDm { get; } + /// + public bool IsNsfw { get; } + /// public GuildPermission? DefaultMemberPermissions { get; } @@ -48,6 +51,7 @@ namespace Discord.Interactions Description = builder.Description; DefaultPermission = builder.DefaultPermission; IsEnabledInDm = builder.IsEnabledInDm; + IsNsfw = builder.IsNsfw; DefaultMemberPermissions = builder.DefaultMemberPermissions; Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); FlattenedParameters = FlattenParameters(Parameters).ToImmutableArray(); diff --git a/src/Discord.Net.Interactions/Info/IApplicationCommandInfo.cs b/src/Discord.Net.Interactions/Info/IApplicationCommandInfo.cs index dd1b97899..d5bcdd3a3 100644 --- a/src/Discord.Net.Interactions/Info/IApplicationCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/IApplicationCommandInfo.cs @@ -28,6 +28,11 @@ namespace Discord.Interactions /// public bool IsEnabledInDm { get; } + /// + /// Gets whether this command can is age restricted. + /// + public bool IsNsfw { get; } + /// /// Gets the default permissions needed for executing this command. /// diff --git a/src/Discord.Net.Interactions/Info/ModuleInfo.cs b/src/Discord.Net.Interactions/Info/ModuleInfo.cs index 4f40f1607..5c4cac587 100644 --- a/src/Discord.Net.Interactions/Info/ModuleInfo.cs +++ b/src/Discord.Net.Interactions/Info/ModuleInfo.cs @@ -49,6 +49,11 @@ namespace Discord.Interactions /// public bool IsEnabledInDm { get; } + /// + /// Gets whether this command is age restricted. + /// + public bool IsNsfw { get; } + /// /// Gets the default permissions needed for executing this command. /// @@ -121,6 +126,7 @@ namespace Discord.Interactions Description = builder.Description; Parent = parent; DefaultPermission = builder.DefaultPermission; + IsNsfw = builder.IsNsfw; IsEnabledInDm = builder.IsEnabledInDm; DefaultMemberPermissions = BuildDefaultMemberPermissions(builder); SlashCommands = BuildSlashCommands(builder).ToImmutableArray(); diff --git a/src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs b/src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs index 9b507f1bb..dc98d4e43 100644 --- a/src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs +++ b/src/Discord.Net.Interactions/Utilities/ApplicationCommandRestUtil.cs @@ -54,6 +54,7 @@ namespace Discord.Interactions Description = commandInfo.Description, IsDefaultPermission = commandInfo.DefaultPermission, IsDMEnabled = commandInfo.IsEnabledInDm, + IsNsfw = commandInfo.IsNsfw, DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), }.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary.Empty) .WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary.Empty) @@ -97,7 +98,8 @@ namespace Discord.Interactions Name = commandInfo.Name, IsDefaultPermission = commandInfo.DefaultPermission, DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), - IsDMEnabled = commandInfo.IsEnabledInDm + IsDMEnabled = commandInfo.IsEnabledInDm, + IsNsfw = commandInfo.IsNsfw, } .WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary.Empty) .Build(), @@ -106,6 +108,7 @@ namespace Discord.Interactions Name = commandInfo.Name, IsDefaultPermission = commandInfo.DefaultPermission, DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), + IsNsfw = commandInfo.IsNsfw, IsDMEnabled = commandInfo.IsEnabledInDm } .WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary.Empty) @@ -162,6 +165,7 @@ namespace Discord.Interactions Description = moduleInfo.Description, IsDefaultPermission = moduleInfo.DefaultPermission, IsDMEnabled = moduleInfo.IsEnabledInDm, + IsNsfw = moduleInfo.IsNsfw, DefaultMemberPermissions = moduleInfo.DefaultMemberPermissions } .WithNameLocalizations(localizationManager?.GetAllNames(modulePath, LocalizationTarget.Group) ?? ImmutableDictionary.Empty) @@ -225,6 +229,7 @@ namespace Discord.Interactions IsDefaultPermission = command.IsDefaultPermission, DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, IsDMEnabled = command.IsEnabledInDm, + IsNsfw = command.IsNsfw, Options = command.Options?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional>.Unspecified, NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary.Empty, DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary.Empty, @@ -234,6 +239,7 @@ namespace Discord.Interactions Name = command.Name, IsDefaultPermission = command.IsDefaultPermission, DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, + IsNsfw = command.IsNsfw, IsDMEnabled = command.IsEnabledInDm, NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary.Empty, DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary.Empty @@ -243,6 +249,7 @@ namespace Discord.Interactions Name = command.Name, IsDefaultPermission = command.IsDefaultPermission, DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, + IsNsfw = command.IsNsfw, IsDMEnabled = command.IsEnabledInDm, NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary.Empty, DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary.Empty diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs index e46369277..6e434d466 100644 --- a/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs @@ -44,5 +44,8 @@ namespace Discord.API [JsonProperty("default_member_permissions")] public Optional DefaultMemberPermission { get; set; } + + [JsonProperty("nsfw")] + public Optional Nsfw { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs b/src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs index 2257d4b97..36ea0270a 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateApplicationCommandParams.cs @@ -35,9 +35,12 @@ namespace Discord.API.Rest [JsonProperty("default_member_permissions")] public Optional DefaultMemberPermission { get; set; } + [JsonProperty("nsfw")] + public Optional Nsfw { get; set; } + public CreateApplicationCommandParams() { } public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null, - IDictionary nameLocalizations = null, IDictionary descriptionLocalizations = null) + IDictionary nameLocalizations = null, IDictionary descriptionLocalizations = null, bool nsfw = false) { Name = name; Description = description; @@ -45,6 +48,7 @@ namespace Discord.API.Rest Type = type; NameLocalizations = nameLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional>.Unspecified; DescriptionLocalizations = descriptionLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional>.Unspecified; + Nsfw = nsfw; } } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs index f49a3f33d..222e16b84 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyApplicationCommandParams.cs @@ -17,6 +17,12 @@ namespace Discord.API.Rest [JsonProperty("default_permission")] public Optional DefaultPermission { get; set; } + [JsonProperty("nsfw")] + public Optional Nsfw { get; set; } + + [JsonProperty("default_member_permissions")] + public Optional DefaultMemberPermission { get; set; } + [JsonProperty("name_localizations")] public Optional> NameLocalizations { get; set; } diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs index deca00b72..a118ca8c3 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs @@ -107,7 +107,8 @@ namespace Discord.Rest // TODO: better conversion to nullable optionals DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), - DmPermission = arg.IsDMEnabled.ToNullable() + DmPermission = arg.IsDMEnabled.ToNullable(), + Nsfw = arg.IsNsfw.GetValueOrDefault(false), }; if (arg is SlashCommandProperties slashProps) @@ -147,8 +148,9 @@ namespace Discord.Rest // TODO: better conversion to nullable optionals DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), - DmPermission = arg.IsDMEnabled.ToNullable() - }; + DmPermission = arg.IsDMEnabled.ToNullable(), + Nsfw = arg.IsNsfw.GetValueOrDefault(false) + }; if (arg is SlashCommandProperties slashProps) { @@ -190,7 +192,8 @@ namespace Discord.Rest // TODO: better conversion to nullable optionals DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), - DmPermission = arg.IsDMEnabled.ToNullable() + DmPermission = arg.IsDMEnabled.ToNullable(), + Nsfw = arg.IsNsfw.GetValueOrDefault(false) }; if (arg is SlashCommandProperties slashProps) @@ -252,7 +255,9 @@ namespace Discord.Rest ? args.IsDefaultPermission.Value : Optional.Unspecified, NameLocalizations = args.NameLocalizations?.ToDictionary(), - DescriptionLocalizations = args.DescriptionLocalizations?.ToDictionary() + DescriptionLocalizations = args.DescriptionLocalizations?.ToDictionary(), + Nsfw = args.IsNsfw.GetValueOrDefault(false), + DefaultMemberPermission = args.DefaultMemberPermissions.ToNullable() }; if (args is SlashCommandProperties slashProps) @@ -312,7 +317,8 @@ namespace Discord.Rest // TODO: better conversion to nullable optionals DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), - DmPermission = arg.IsDMEnabled.ToNullable() + DmPermission = arg.IsDMEnabled.ToNullable(), + Nsfw = arg.IsNsfw.GetValueOrDefault(false) }; if (arg is SlashCommandProperties slashProps) @@ -347,7 +353,9 @@ namespace Discord.Rest ? arg.IsDefaultPermission.Value : Optional.Unspecified, NameLocalizations = arg.NameLocalizations?.ToDictionary(), - DescriptionLocalizations = arg.DescriptionLocalizations?.ToDictionary() + DescriptionLocalizations = arg.DescriptionLocalizations?.ToDictionary(), + Nsfw = arg.IsNsfw.GetValueOrDefault(false), + DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable() }; if (arg is SlashCommandProperties slashProps) diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs index 468d10712..ed22712e7 100644 --- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs +++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs @@ -30,6 +30,9 @@ namespace Discord.Rest /// public bool IsEnabledInDm { get; private set; } + /// + public bool IsNsfw { get; private set; } + /// public GuildPermissions DefaultMemberPermissions { get; private set; } @@ -101,6 +104,7 @@ namespace Discord.Rest IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true); DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0)); + IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false); } /// diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs index b0ddd0012..cdefd3260 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs @@ -39,6 +39,9 @@ namespace Discord.WebSocket /// public bool IsEnabledInDm { get; private set; } + /// + public bool IsNsfw { get; private set; } + /// public GuildPermissions DefaultMemberPermissions { get; private set; } @@ -130,6 +133,7 @@ namespace Discord.WebSocket IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true); DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0)); + IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false); } ///