| @@ -0,0 +1,25 @@ | |||||
| using System; | |||||
| namespace Discord.Interactions | |||||
| { | |||||
| /// <summary> | |||||
| /// Sets the <see cref="IApplicationCommandInfo.IsNsfw"/> property of an application command or module. | |||||
| /// </summary> | |||||
| [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | |||||
| public class NsfwCommandAttribute : Attribute | |||||
| { | |||||
| /// <summary> | |||||
| /// Gets whether or not this command is age restricted. | |||||
| /// </summary> | |||||
| public bool IsNsfw { get; } | |||||
| /// <summary> | |||||
| /// Sets the <see cref="IApplicationCommandInfo.IsNsfw"/> property of an application command or module. | |||||
| /// </summary> | |||||
| /// <param name="isNsfw">Whether or not this command is age restricted.</param> | |||||
| public NsfwCommandAttribute(bool isNsfw) | |||||
| { | |||||
| IsNsfw = isNsfw; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -25,6 +25,11 @@ namespace Discord.Interactions.Builders | |||||
| /// </summary> | /// </summary> | ||||
| public bool IsEnabledInDm { get; set; } = true; | public bool IsEnabledInDm { get; set; } = true; | ||||
| /// <summary> | |||||
| /// Gets whether this command is age restricted. | |||||
| /// </summary> | |||||
| public bool IsNsfw { get; set; } = false; | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets the default permissions needed for executing this command. | /// Gets the default permissions needed for executing this command. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -95,6 +100,19 @@ namespace Discord.Interactions.Builders | |||||
| return this; | return this; | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Sets <see cref="IsNsfw"/>. | |||||
| /// </summary> | |||||
| /// <param name="isNsfw">New value of the <see cref="IsNsfw"/>.</param> | |||||
| /// <returns> | |||||
| /// The builder instance. | |||||
| /// </returns> | |||||
| public ContextCommandBuilder SetNsfw(bool isNsfw) | |||||
| { | |||||
| IsNsfw = isNsfw; | |||||
| return this; | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Sets <see cref="DefaultMemberPermissions"/>. | /// Sets <see cref="DefaultMemberPermissions"/>. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -25,6 +25,11 @@ namespace Discord.Interactions.Builders | |||||
| /// </summary> | /// </summary> | ||||
| public bool IsEnabledInDm { get; set; } = true; | public bool IsEnabledInDm { get; set; } = true; | ||||
| /// <summary> | |||||
| /// Gets whether this command is age restricted. | |||||
| /// </summary> | |||||
| public bool IsNsfw { get; set; } = false; | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets the default permissions needed for executing this command. | /// Gets the default permissions needed for executing this command. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -95,6 +100,19 @@ namespace Discord.Interactions.Builders | |||||
| return this; | return this; | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Sets <see cref="IsNsfw"/>. | |||||
| /// </summary> | |||||
| /// <param name="isNsfw">New value of the <see cref="IsNsfw"/>.</param> | |||||
| /// <returns> | |||||
| /// The builder instance. | |||||
| /// </returns> | |||||
| public SlashCommandBuilder SetNsfw(bool isNsfw) | |||||
| { | |||||
| IsNsfw = isNsfw; | |||||
| return this; | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Sets <see cref="DefaultMemberPermissions"/>. | /// Sets <see cref="DefaultMemberPermissions"/>. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -59,6 +59,11 @@ namespace Discord.Interactions.Builders | |||||
| /// </summary> | /// </summary> | ||||
| public bool IsEnabledInDm { get; set; } = true; | public bool IsEnabledInDm { get; set; } = true; | ||||
| /// <summary> | |||||
| /// Gets whether this command is age restricted. | |||||
| /// </summary> | |||||
| public bool IsNsfw { get; set; } = false; | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets the default permissions needed for executing this command. | /// Gets the default permissions needed for executing this command. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -101,6 +101,9 @@ namespace Discord.Interactions.Builders | |||||
| case DontAutoRegisterAttribute dontAutoRegister: | case DontAutoRegisterAttribute dontAutoRegister: | ||||
| builder.DontAutoRegister = true; | builder.DontAutoRegister = true; | ||||
| break; | break; | ||||
| case NsfwCommandAttribute nsfwCommand: | |||||
| builder.IsNsfw = nsfwCommand.IsNsfw; | |||||
| break; | |||||
| default: | default: | ||||
| builder.AddAttributes(attribute); | builder.AddAttributes(attribute); | ||||
| break; | break; | ||||
| @@ -192,6 +195,9 @@ namespace Discord.Interactions.Builders | |||||
| case PreconditionAttribute precondition: | case PreconditionAttribute precondition: | ||||
| builder.WithPreconditions(precondition); | builder.WithPreconditions(precondition); | ||||
| break; | break; | ||||
| case NsfwCommandAttribute nsfwCommand: | |||||
| builder.SetNsfw(nsfwCommand.IsNsfw); | |||||
| break; | |||||
| default: | default: | ||||
| builder.WithAttributes(attribute); | builder.WithAttributes(attribute); | ||||
| break; | break; | ||||
| @@ -244,6 +250,9 @@ namespace Discord.Interactions.Builders | |||||
| case PreconditionAttribute precondition: | case PreconditionAttribute precondition: | ||||
| builder.WithPreconditions(precondition); | builder.WithPreconditions(precondition); | ||||
| break; | break; | ||||
| case NsfwCommandAttribute nsfwCommand: | |||||
| builder.SetNsfw(nsfwCommand.IsNsfw); | |||||
| break; | |||||
| default: | default: | ||||
| builder.WithAttributes(attribute); | builder.WithAttributes(attribute); | ||||
| break; | break; | ||||
| @@ -20,6 +20,9 @@ namespace Discord.Interactions | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public bool IsEnabledInDm { get; } | public bool IsEnabledInDm { get; } | ||||
| /// <inheritdoc/> | |||||
| public bool IsNsfw { get; } | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public GuildPermission? DefaultMemberPermissions { get; } | public GuildPermission? DefaultMemberPermissions { get; } | ||||
| @@ -37,6 +40,7 @@ namespace Discord.Interactions | |||||
| { | { | ||||
| CommandType = builder.CommandType; | CommandType = builder.CommandType; | ||||
| DefaultPermission = builder.DefaultPermission; | DefaultPermission = builder.DefaultPermission; | ||||
| IsNsfw = builder.IsNsfw; | |||||
| IsEnabledInDm = builder.IsEnabledInDm; | IsEnabledInDm = builder.IsEnabledInDm; | ||||
| DefaultMemberPermissions = builder.DefaultMemberPermissions; | DefaultMemberPermissions = builder.DefaultMemberPermissions; | ||||
| Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | ||||
| @@ -29,6 +29,9 @@ namespace Discord.Interactions | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public bool IsEnabledInDm { get; } | public bool IsEnabledInDm { get; } | ||||
| /// <inheritdoc/> | |||||
| public bool IsNsfw { get; } | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| public GuildPermission? DefaultMemberPermissions { get; } | public GuildPermission? DefaultMemberPermissions { get; } | ||||
| @@ -48,6 +51,7 @@ namespace Discord.Interactions | |||||
| Description = builder.Description; | Description = builder.Description; | ||||
| DefaultPermission = builder.DefaultPermission; | DefaultPermission = builder.DefaultPermission; | ||||
| IsEnabledInDm = builder.IsEnabledInDm; | IsEnabledInDm = builder.IsEnabledInDm; | ||||
| IsNsfw = builder.IsNsfw; | |||||
| DefaultMemberPermissions = builder.DefaultMemberPermissions; | DefaultMemberPermissions = builder.DefaultMemberPermissions; | ||||
| Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | ||||
| FlattenedParameters = FlattenParameters(Parameters).ToImmutableArray(); | FlattenedParameters = FlattenParameters(Parameters).ToImmutableArray(); | ||||
| @@ -28,6 +28,11 @@ namespace Discord.Interactions | |||||
| /// </summary> | /// </summary> | ||||
| public bool IsEnabledInDm { get; } | public bool IsEnabledInDm { get; } | ||||
| /// <summary> | |||||
| /// Gets whether this command can is age restricted. | |||||
| /// </summary> | |||||
| public bool IsNsfw { get; } | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets the default permissions needed for executing this command. | /// Gets the default permissions needed for executing this command. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -49,6 +49,11 @@ namespace Discord.Interactions | |||||
| /// </summary> | /// </summary> | ||||
| public bool IsEnabledInDm { get; } | public bool IsEnabledInDm { get; } | ||||
| /// <summary> | |||||
| /// Gets whether this command is age restricted. | |||||
| /// </summary> | |||||
| public bool IsNsfw { get; } | |||||
| /// <summary> | /// <summary> | ||||
| /// Gets the default permissions needed for executing this command. | /// Gets the default permissions needed for executing this command. | ||||
| /// </summary> | /// </summary> | ||||
| @@ -121,6 +126,7 @@ namespace Discord.Interactions | |||||
| Description = builder.Description; | Description = builder.Description; | ||||
| Parent = parent; | Parent = parent; | ||||
| DefaultPermission = builder.DefaultPermission; | DefaultPermission = builder.DefaultPermission; | ||||
| IsNsfw = builder.IsNsfw; | |||||
| IsEnabledInDm = builder.IsEnabledInDm; | IsEnabledInDm = builder.IsEnabledInDm; | ||||
| DefaultMemberPermissions = BuildDefaultMemberPermissions(builder); | DefaultMemberPermissions = BuildDefaultMemberPermissions(builder); | ||||
| SlashCommands = BuildSlashCommands(builder).ToImmutableArray(); | SlashCommands = BuildSlashCommands(builder).ToImmutableArray(); | ||||
| @@ -54,6 +54,7 @@ namespace Discord.Interactions | |||||
| Description = commandInfo.Description, | Description = commandInfo.Description, | ||||
| IsDefaultPermission = commandInfo.DefaultPermission, | IsDefaultPermission = commandInfo.DefaultPermission, | ||||
| IsDMEnabled = commandInfo.IsEnabledInDm, | IsDMEnabled = commandInfo.IsEnabledInDm, | ||||
| IsNsfw = commandInfo.IsNsfw, | |||||
| DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), | DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), | ||||
| }.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty) | }.WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty) | ||||
| .WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty) | .WithDescriptionLocalizations(localizationManager?.GetAllDescriptions(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty) | ||||
| @@ -97,7 +98,8 @@ namespace Discord.Interactions | |||||
| Name = commandInfo.Name, | Name = commandInfo.Name, | ||||
| IsDefaultPermission = commandInfo.DefaultPermission, | IsDefaultPermission = commandInfo.DefaultPermission, | ||||
| DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), | 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<string, string>.Empty) | .WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty) | ||||
| .Build(), | .Build(), | ||||
| @@ -106,6 +108,7 @@ namespace Discord.Interactions | |||||
| Name = commandInfo.Name, | Name = commandInfo.Name, | ||||
| IsDefaultPermission = commandInfo.DefaultPermission, | IsDefaultPermission = commandInfo.DefaultPermission, | ||||
| DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), | DefaultMemberPermissions = ((commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0)).SanitizeGuildPermissions(), | ||||
| IsNsfw = commandInfo.IsNsfw, | |||||
| IsDMEnabled = commandInfo.IsEnabledInDm | IsDMEnabled = commandInfo.IsEnabledInDm | ||||
| } | } | ||||
| .WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty) | .WithNameLocalizations(localizationManager?.GetAllNames(commandPath, LocalizationTarget.Command) ?? ImmutableDictionary<string, string>.Empty) | ||||
| @@ -225,6 +228,7 @@ namespace Discord.Interactions | |||||
| IsDefaultPermission = command.IsDefaultPermission, | IsDefaultPermission = command.IsDefaultPermission, | ||||
| DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, | DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, | ||||
| IsDMEnabled = command.IsEnabledInDm, | IsDMEnabled = command.IsEnabledInDm, | ||||
| IsNsfw = command.IsNsfw, | |||||
| Options = command.Options?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional<List<ApplicationCommandOptionProperties>>.Unspecified, | Options = command.Options?.Select(x => x.ToApplicationCommandOptionProps())?.ToList() ?? Optional<List<ApplicationCommandOptionProperties>>.Unspecified, | ||||
| NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | ||||
| DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | ||||
| @@ -234,6 +238,7 @@ namespace Discord.Interactions | |||||
| Name = command.Name, | Name = command.Name, | ||||
| IsDefaultPermission = command.IsDefaultPermission, | IsDefaultPermission = command.IsDefaultPermission, | ||||
| DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, | DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, | ||||
| IsNsfw = command.IsNsfw, | |||||
| IsDMEnabled = command.IsEnabledInDm, | IsDMEnabled = command.IsEnabledInDm, | ||||
| NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | ||||
| DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty | DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty | ||||
| @@ -243,6 +248,7 @@ namespace Discord.Interactions | |||||
| Name = command.Name, | Name = command.Name, | ||||
| IsDefaultPermission = command.IsDefaultPermission, | IsDefaultPermission = command.IsDefaultPermission, | ||||
| DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, | DefaultMemberPermissions = (GuildPermission)command.DefaultMemberPermissions.RawValue, | ||||
| IsNsfw = command.IsNsfw, | |||||
| IsDMEnabled = command.IsEnabledInDm, | IsDMEnabled = command.IsEnabledInDm, | ||||
| NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | NameLocalizations = command.NameLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty, | ||||
| DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty | DescriptionLocalizations = command.DescriptionLocalizations?.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty | ||||