[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?
This commit is contained in:
@@ -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.
|
> 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.
|
> 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
|
[permissions]: xref:Discord.GuildPermission
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[NsfwCommand(true)]
|
||||||
|
[SlashCommand("beautiful-code", "Get an image of perfect code")]
|
||||||
|
public async Task BeautifulCodeAsync(...)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
@@ -83,6 +83,11 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Optional<bool> IsDMEnabled { get; set; }
|
public Optional<bool> IsDMEnabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether or not this command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
public Optional<bool> IsNsfw { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default permissions required by a user to execute this application command.
|
/// Gets or sets the default permissions required by a user to execute this application command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDMEnabled { get; set; } = true;
|
public bool IsDMEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether or not this command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsNsfw{ get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default permission required to use this slash command.
|
/// Gets or sets the default permission required to use this slash command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -68,7 +73,8 @@ namespace Discord
|
|||||||
IsDefaultPermission = IsDefaultPermission,
|
IsDefaultPermission = IsDefaultPermission,
|
||||||
IsDMEnabled = IsDMEnabled,
|
IsDMEnabled = IsDMEnabled,
|
||||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||||
NameLocalizations = NameLocalizations
|
NameLocalizations = NameLocalizations,
|
||||||
|
IsNsfw = IsNsfw,
|
||||||
};
|
};
|
||||||
|
|
||||||
return props;
|
return props;
|
||||||
@@ -123,7 +129,7 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets whether or not this command can be used in dms
|
/// Sets whether or not this command can be used in dms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
@@ -133,6 +139,17 @@ namespace Discord
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets whether or not this command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="permission"><see langword="true"/> if the command is age restricted, otherwise <see langword="false"/>.</param>
|
||||||
|
/// <returns>The current builder.</returns>
|
||||||
|
public MessageCommandBuilder WithNsfw(bool permission)
|
||||||
|
{
|
||||||
|
IsNsfw = permission;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new entry to the <see cref="NameLocalizations"/> collection.
|
/// Adds a new entry to the <see cref="NameLocalizations"/> collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ namespace Discord
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDMEnabled { get; set; } = true;
|
public bool IsDMEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether or not this command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsNsfw { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default permission required to use this slash command.
|
/// Gets or sets the default permission required to use this slash command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -66,7 +71,8 @@ namespace Discord
|
|||||||
IsDefaultPermission = IsDefaultPermission,
|
IsDefaultPermission = IsDefaultPermission,
|
||||||
IsDMEnabled = IsDMEnabled,
|
IsDMEnabled = IsDMEnabled,
|
||||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||||
NameLocalizations = NameLocalizations
|
NameLocalizations = NameLocalizations,
|
||||||
|
IsNsfw = IsNsfw,
|
||||||
};
|
};
|
||||||
|
|
||||||
return props;
|
return props;
|
||||||
@@ -121,7 +127,7 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets whether or not this command can be used in dms
|
/// Sets whether or not this command can be used in dms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
@@ -131,6 +137,17 @@ namespace Discord
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets whether or not this command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="permission"><see langword="true"/> if the command is age restricted, otherwise <see langword="false"/>.</param>
|
||||||
|
/// <returns>The current builder.</returns>
|
||||||
|
public UserCommandBuilder WithNsfw(bool permission)
|
||||||
|
{
|
||||||
|
IsNsfw = permission;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new entry to the <see cref="NameLocalizations"/> collection.
|
/// Adds a new entry to the <see cref="NameLocalizations"/> collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ namespace Discord
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
bool IsEnabledInDm { get; }
|
bool IsEnabledInDm { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
bool IsNsfw { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set of default <see cref="GuildPermission"/> required to invoke the command.
|
/// Set of default <see cref="GuildPermission"/> required to invoke the command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ namespace Discord
|
|||||||
/// Gets or sets whether or not this command can be used in DMs.
|
/// Gets or sets whether or not this command can be used in DMs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDMEnabled { get; set; } = true;
|
public bool IsDMEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether or not this command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsNsfw { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the default permission required to use this slash command.
|
/// Gets or sets the default permission required to use this slash command.
|
||||||
@@ -110,7 +115,8 @@ namespace Discord
|
|||||||
NameLocalizations = _nameLocalizations,
|
NameLocalizations = _nameLocalizations,
|
||||||
DescriptionLocalizations = _descriptionLocalizations,
|
DescriptionLocalizations = _descriptionLocalizations,
|
||||||
IsDMEnabled = IsDMEnabled,
|
IsDMEnabled = IsDMEnabled,
|
||||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified
|
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified,
|
||||||
|
IsNsfw = IsNsfw,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Options != null && Options.Any())
|
if (Options != null && Options.Any())
|
||||||
@@ -161,7 +167,7 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets whether or not this command can be used in dms
|
/// Sets whether or not this command can be used in dms.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param>
|
||||||
/// <returns>The current builder.</returns>
|
/// <returns>The current builder.</returns>
|
||||||
@@ -171,6 +177,17 @@ namespace Discord
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets whether or not this command is age restricted.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="permission"><see langword="true"/> if the command is age restricted, otherwise <see langword="false"/>.</param>
|
||||||
|
/// <returns>The current builder.</returns>
|
||||||
|
public SlashCommandBuilder WithNsfw(bool permission)
|
||||||
|
{
|
||||||
|
IsNsfw = permission;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the default member permissions required to use this application command.
|
/// Sets the default member permissions required to use this application command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -190,6 +195,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 ModuleBuilder SetNsfw(bool isNsfw)
|
||||||
|
{
|
||||||
|
IsNsfw = isNsfw;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets <see cref="DefaultMemberPermissions"/>.
|
/// Sets <see cref="DefaultMemberPermissions"/>.
|
||||||
/// </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.SetNsfw(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)
|
||||||
@@ -162,6 +165,7 @@ namespace Discord.Interactions
|
|||||||
Description = moduleInfo.Description,
|
Description = moduleInfo.Description,
|
||||||
IsDefaultPermission = moduleInfo.DefaultPermission,
|
IsDefaultPermission = moduleInfo.DefaultPermission,
|
||||||
IsDMEnabled = moduleInfo.IsEnabledInDm,
|
IsDMEnabled = moduleInfo.IsEnabledInDm,
|
||||||
|
IsNsfw = moduleInfo.IsNsfw,
|
||||||
DefaultMemberPermissions = moduleInfo.DefaultMemberPermissions
|
DefaultMemberPermissions = moduleInfo.DefaultMemberPermissions
|
||||||
}
|
}
|
||||||
.WithNameLocalizations(localizationManager?.GetAllNames(modulePath, LocalizationTarget.Group) ?? ImmutableDictionary<string, string>.Empty)
|
.WithNameLocalizations(localizationManager?.GetAllNames(modulePath, LocalizationTarget.Group) ?? ImmutableDictionary<string, string>.Empty)
|
||||||
@@ -225,6 +229,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 +239,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 +249,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
|
||||||
|
|||||||
@@ -44,5 +44,8 @@ namespace Discord.API
|
|||||||
|
|
||||||
[JsonProperty("default_member_permissions")]
|
[JsonProperty("default_member_permissions")]
|
||||||
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }
|
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("nsfw")]
|
||||||
|
public Optional<bool?> Nsfw { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,12 @@ namespace Discord.API.Rest
|
|||||||
[JsonProperty("default_member_permissions")]
|
[JsonProperty("default_member_permissions")]
|
||||||
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }
|
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("nsfw")]
|
||||||
|
public Optional<bool> Nsfw { get; set; }
|
||||||
|
|
||||||
public CreateApplicationCommandParams() { }
|
public CreateApplicationCommandParams() { }
|
||||||
public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null,
|
public CreateApplicationCommandParams(string name, string description, ApplicationCommandType type, ApplicationCommandOption[] options = null,
|
||||||
IDictionary<string, string> nameLocalizations = null, IDictionary<string, string> descriptionLocalizations = null)
|
IDictionary<string, string> nameLocalizations = null, IDictionary<string, string> descriptionLocalizations = null, bool nsfw = false)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Description = description;
|
Description = description;
|
||||||
@@ -45,6 +48,7 @@ namespace Discord.API.Rest
|
|||||||
Type = type;
|
Type = type;
|
||||||
NameLocalizations = nameLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
|
NameLocalizations = nameLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
|
||||||
DescriptionLocalizations = descriptionLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
|
DescriptionLocalizations = descriptionLocalizations?.ToDictionary(x => x.Key, x => x.Value) ?? Optional<Dictionary<string, string>>.Unspecified;
|
||||||
|
Nsfw = nsfw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ namespace Discord.API.Rest
|
|||||||
[JsonProperty("default_permission")]
|
[JsonProperty("default_permission")]
|
||||||
public Optional<bool> DefaultPermission { get; set; }
|
public Optional<bool> DefaultPermission { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("nsfw")]
|
||||||
|
public Optional<bool> Nsfw { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("default_member_permissions")]
|
||||||
|
public Optional<GuildPermission?> DefaultMemberPermission { get; set; }
|
||||||
|
|
||||||
[JsonProperty("name_localizations")]
|
[JsonProperty("name_localizations")]
|
||||||
public Optional<Dictionary<string, string>> NameLocalizations { get; set; }
|
public Optional<Dictionary<string, string>> NameLocalizations { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
// TODO: better conversion to nullable optionals
|
// TODO: better conversion to nullable optionals
|
||||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||||
DmPermission = arg.IsDMEnabled.ToNullable()
|
DmPermission = arg.IsDMEnabled.ToNullable(),
|
||||||
|
Nsfw = arg.IsNsfw.GetValueOrDefault(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (arg is SlashCommandProperties slashProps)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
@@ -147,8 +148,9 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
// TODO: better conversion to nullable optionals
|
// TODO: better conversion to nullable optionals
|
||||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||||
DmPermission = arg.IsDMEnabled.ToNullable()
|
DmPermission = arg.IsDMEnabled.ToNullable(),
|
||||||
};
|
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
|
||||||
|
};
|
||||||
|
|
||||||
if (arg is SlashCommandProperties slashProps)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
{
|
{
|
||||||
@@ -190,7 +192,8 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
// TODO: better conversion to nullable optionals
|
// TODO: better conversion to nullable optionals
|
||||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||||
DmPermission = arg.IsDMEnabled.ToNullable()
|
DmPermission = arg.IsDMEnabled.ToNullable(),
|
||||||
|
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (arg is SlashCommandProperties slashProps)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
@@ -252,7 +255,9 @@ namespace Discord.Rest
|
|||||||
? args.IsDefaultPermission.Value
|
? args.IsDefaultPermission.Value
|
||||||
: Optional<bool>.Unspecified,
|
: Optional<bool>.Unspecified,
|
||||||
NameLocalizations = args.NameLocalizations?.ToDictionary(),
|
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)
|
if (args is SlashCommandProperties slashProps)
|
||||||
@@ -312,7 +317,8 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
// TODO: better conversion to nullable optionals
|
// TODO: better conversion to nullable optionals
|
||||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(),
|
||||||
DmPermission = arg.IsDMEnabled.ToNullable()
|
DmPermission = arg.IsDMEnabled.ToNullable(),
|
||||||
|
Nsfw = arg.IsNsfw.GetValueOrDefault(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (arg is SlashCommandProperties slashProps)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
@@ -347,7 +353,9 @@ namespace Discord.Rest
|
|||||||
? arg.IsDefaultPermission.Value
|
? arg.IsDefaultPermission.Value
|
||||||
: Optional<bool>.Unspecified,
|
: Optional<bool>.Unspecified,
|
||||||
NameLocalizations = arg.NameLocalizations?.ToDictionary(),
|
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)
|
if (arg is SlashCommandProperties slashProps)
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ namespace Discord.Rest
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool IsEnabledInDm { get; private set; }
|
public bool IsEnabledInDm { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool IsNsfw { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public GuildPermissions DefaultMemberPermissions { get; private set; }
|
public GuildPermissions DefaultMemberPermissions { get; private set; }
|
||||||
|
|
||||||
@@ -101,6 +104,7 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
||||||
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
||||||
|
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool IsEnabledInDm { get; private set; }
|
public bool IsEnabledInDm { get; private set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool IsNsfw { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public GuildPermissions DefaultMemberPermissions { get; private set; }
|
public GuildPermissions DefaultMemberPermissions { get; private set; }
|
||||||
|
|
||||||
@@ -130,6 +133,7 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true);
|
||||||
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
DefaultMemberPermissions = new GuildPermissions((ulong)model.DefaultMemberPermission.GetValueOrDefault(0).GetValueOrDefault(0));
|
||||||
|
IsNsfw = model.Nsfw.GetValueOrDefault(false).GetValueOrDefault(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
Reference in New Issue
Block a user