* Initial V2 permissions * add perms-v2 attributes and properties, add deprecation messages * add perms-v2 properties to command info classes * add perms-v2 fields to Rest/SocketApplicationCommand entities and IApplicationCommand * fix json name of DmPermission field Co-authored-by: Cenngo <cenk.ergen1@gmail.com>tags/3.6.0
@@ -17,6 +17,16 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public Optional<bool> IsDefaultPermission { get; set; } | public Optional<bool> IsDefaultPermission { get; set; } | ||||
/// <summary> | |||||
/// Gets or sets whether or not this command can be used in DMs. | |||||
/// </summary> | |||||
public Optional<bool> IsDMEnabled { get; set; } | |||||
/// <summary> | |||||
/// Gets or sets the default permissions required by a user to execute this application command. | |||||
/// </summary> | |||||
public Optional<GuildPermission> DefaultMemberPermissions { get; set; } | |||||
internal ApplicationCommandProperties() { } | internal ApplicationCommandProperties() { } | ||||
} | } | ||||
} | } |
@@ -31,6 +31,16 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public bool IsDefaultPermission { get; set; } = true; | public bool IsDefaultPermission { get; set; } = true; | ||||
/// <summary> | |||||
/// Gets or sets whether or not this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsDMEnabled { get; set; } = true; | |||||
/// <summary> | |||||
/// Gets or sets the default permission required to use this slash command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; set; } | |||||
private string _name; | private string _name; | ||||
/// <summary> | /// <summary> | ||||
@@ -44,7 +54,9 @@ namespace Discord | |||||
var props = new MessageCommandProperties | var props = new MessageCommandProperties | ||||
{ | { | ||||
Name = Name, | Name = Name, | ||||
IsDefaultPermission = IsDefaultPermission | |||||
IsDefaultPermission = IsDefaultPermission, | |||||
IsDMEnabled = IsDMEnabled, | |||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified | |||||
}; | }; | ||||
return props; | return props; | ||||
@@ -73,5 +85,27 @@ namespace Discord | |||||
IsDefaultPermission = isDefaultPermission; | IsDefaultPermission = isDefaultPermission; | ||||
return this; | return this; | ||||
} | } | ||||
/// <summary> | |||||
/// Sets whether or not this command can be used in dms | |||||
/// </summary> | |||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param> | |||||
/// <returns>The current builder.</returns> | |||||
public MessageCommandBuilder WithDMPermission(bool permission) | |||||
{ | |||||
IsDMEnabled = permission; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Sets the default member permissions required to use this application command. | |||||
/// </summary> | |||||
/// <param name="permissions">The permissions required to use this command.</param> | |||||
/// <returns>The current builder.</returns> | |||||
public MessageCommandBuilder WithDefaultMemberPermissions(GuildPermission? permissions) | |||||
{ | |||||
DefaultMemberPermissions = permissions; | |||||
return this; | |||||
} | |||||
} | } | ||||
} | } |
@@ -31,6 +31,16 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public bool IsDefaultPermission { get; set; } = true; | public bool IsDefaultPermission { get; set; } = true; | ||||
/// <summary> | |||||
/// Gets or sets whether or not this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsDMEnabled { get; set; } = true; | |||||
/// <summary> | |||||
/// Gets or sets the default permission required to use this slash command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; set; } | |||||
private string _name; | private string _name; | ||||
/// <summary> | /// <summary> | ||||
@@ -42,7 +52,9 @@ namespace Discord | |||||
var props = new UserCommandProperties | var props = new UserCommandProperties | ||||
{ | { | ||||
Name = Name, | Name = Name, | ||||
IsDefaultPermission = IsDefaultPermission | |||||
IsDefaultPermission = IsDefaultPermission, | |||||
IsDMEnabled = IsDMEnabled, | |||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified | |||||
}; | }; | ||||
return props; | return props; | ||||
@@ -71,5 +83,27 @@ namespace Discord | |||||
IsDefaultPermission = isDefaultPermission; | IsDefaultPermission = isDefaultPermission; | ||||
return this; | return this; | ||||
} | } | ||||
/// <summary> | |||||
/// Sets whether or not this command can be used in dms | |||||
/// </summary> | |||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param> | |||||
/// <returns>The current builder.</returns> | |||||
public UserCommandBuilder WithDMPermission(bool permission) | |||||
{ | |||||
IsDMEnabled = permission; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Sets the default member permissions required to use this application command. | |||||
/// </summary> | |||||
/// <param name="permissions">The permissions required to use this command.</param> | |||||
/// <returns>The current builder.</returns> | |||||
public UserCommandBuilder WithDefaultMemberPermissions(GuildPermission? permissions) | |||||
{ | |||||
DefaultMemberPermissions = permissions; | |||||
return this; | |||||
} | |||||
} | } | ||||
} | } |
@@ -35,6 +35,19 @@ namespace Discord | |||||
bool IsDefaultPermission { get; } | bool IsDefaultPermission { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Indicates whether the command is available in DMs with the app. | |||||
/// </summary> | |||||
/// <remarks> | |||||
/// Only for globally-scoped commands. | |||||
/// </remarks> | |||||
bool IsEnabledInDm { get; } | |||||
/// <summary> | |||||
/// Set of default <see cref="GuildPermission"/> required to invoke the command. | |||||
/// </summary> | |||||
GuildPermissions DefaultMemberPermissions { get; } | |||||
/// <summary> | |||||
/// Gets a collection of options for this application command. | /// Gets a collection of options for this application command. | ||||
/// </summary> | /// </summary> | ||||
IReadOnlyCollection<IApplicationCommandOption> Options { get; } | IReadOnlyCollection<IApplicationCommandOption> Options { get; } | ||||
@@ -81,6 +81,16 @@ namespace Discord | |||||
/// </summary> | /// </summary> | ||||
public bool IsDefaultPermission { get; set; } = true; | public bool IsDefaultPermission { get; set; } = true; | ||||
/// <summary> | |||||
/// Gets or sets whether or not this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsDMEnabled { get; set; } = true; | |||||
/// <summary> | |||||
/// Gets or sets the default permission required to use this slash command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; set; } | |||||
private string _name; | private string _name; | ||||
private string _description; | private string _description; | ||||
private List<SlashCommandOptionBuilder> _options; | private List<SlashCommandOptionBuilder> _options; | ||||
@@ -96,6 +106,8 @@ namespace Discord | |||||
Name = Name, | Name = Name, | ||||
Description = Description, | Description = Description, | ||||
IsDefaultPermission = IsDefaultPermission, | IsDefaultPermission = IsDefaultPermission, | ||||
IsDMEnabled = IsDMEnabled, | |||||
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified | |||||
}; | }; | ||||
if (Options != null && Options.Any()) | if (Options != null && Options.Any()) | ||||
@@ -146,6 +158,28 @@ namespace Discord | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Sets whether or not this command can be used in dms | |||||
/// </summary> | |||||
/// <param name="permission"><see langword="true"/> if the command is available in dms, otherwise <see langword="false"/>.</param> | |||||
/// <returns>The current builder.</returns> | |||||
public SlashCommandBuilder WithDMPermission(bool permission) | |||||
{ | |||||
IsDMEnabled = permission; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Sets the default member permissions required to use this application command. | |||||
/// </summary> | |||||
/// <param name="permissions">The permissions required to use this command.</param> | |||||
/// <returns>The current builder.</returns> | |||||
public SlashCommandBuilder WithDefaultMemberPermissions(GuildPermission? permissions) | |||||
{ | |||||
DefaultMemberPermissions = permissions; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Adds an option to the current slash command. | /// Adds an option to the current slash command. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="name">The name of the option to add.</param> | /// <param name="name">The name of the option to add.</param> | ||||
@@ -0,0 +1,25 @@ | |||||
using System; | |||||
namespace Discord.Interactions | |||||
{ | |||||
/// <summary> | |||||
/// Sets the <see cref="IApplicationCommandInfo.DefaultMemberPermissions"/> of an application command or module. | |||||
/// </summary> | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | |||||
public class DefaultMemberPermissionsAttribute : Attribute | |||||
{ | |||||
/// <summary> | |||||
/// Gets the default permission required to use this command. | |||||
/// </summary> | |||||
public GuildPermission Permissions { get; } | |||||
/// <summary> | |||||
/// Sets the <see cref="IApplicationCommandInfo.DefaultMemberPermissions"/> of an application command or module. | |||||
/// </summary> | |||||
/// <param name="permissions">The default permission required to use this command.</param> | |||||
public DefaultMemberPermissionsAttribute(GuildPermission permissions) | |||||
{ | |||||
Permissions = permissions; | |||||
} | |||||
} | |||||
} |
@@ -6,6 +6,7 @@ namespace Discord.Interactions | |||||
/// Set the "Default Permission" property of an Application Command. | /// Set the "Default Permission" property of an Application Command. | ||||
/// </summary> | /// </summary> | ||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
[Obsolete($"Soon to be deprecated, use Permissions-v2 attributes like {nameof(EnabledInDmAttribute)} and {nameof(DefaultMemberPermissionsAttribute)}")] | |||||
public class DefaultPermissionAttribute : Attribute | public class DefaultPermissionAttribute : Attribute | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -0,0 +1,25 @@ | |||||
using System; | |||||
namespace Discord.Interactions | |||||
{ | |||||
/// <summary> | |||||
/// Sets the <see cref="IApplicationCommandInfo.IsEnabledInDm"/> property of an application command or module. | |||||
/// </summary> | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | |||||
public class EnabledInDmAttribute : Attribute | |||||
{ | |||||
/// <summary> | |||||
/// Gets whether or not this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsEnabled { get; } | |||||
/// <summary> | |||||
/// Sets the <see cref="IApplicationCommandInfo.IsEnabledInDm"/> property of an application command or module. | |||||
/// </summary> | |||||
/// <param name="isEnabled">Whether or not this command can be used in DMs.</param> | |||||
public EnabledInDmAttribute(bool isEnabled) | |||||
{ | |||||
IsEnabled = isEnabled; | |||||
} | |||||
} | |||||
} |
@@ -17,8 +17,19 @@ namespace Discord.Interactions.Builders | |||||
/// <summary> | /// <summary> | ||||
/// Gets the default permission of this command. | /// Gets the default permission of this command. | ||||
/// </summary> | /// </summary> | ||||
[Obsolete($"To be deprecated soon, use {nameof(IsEnabledInDm)} and {nameof(DefaultMemberPermissions)} instead.")] | |||||
public bool DefaultPermission { get; set; } = true; | public bool DefaultPermission { get; set; } = true; | ||||
/// <summary> | |||||
/// Gets whether this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsEnabledInDm { get; set; } = true; | |||||
/// <summary> | |||||
/// Gets the default permissions needed for executing this command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null; | |||||
internal ContextCommandBuilder (ModuleBuilder module) : base(module) { } | internal ContextCommandBuilder (ModuleBuilder module) : base(module) { } | ||||
/// <summary> | /// <summary> | ||||
@@ -49,6 +60,7 @@ namespace Discord.Interactions.Builders | |||||
/// <returns> | /// <returns> | ||||
/// The builder instance. | /// The builder instance. | ||||
/// </returns> | /// </returns> | ||||
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")] | |||||
public ContextCommandBuilder SetDefaultPermission (bool defaultPermision) | public ContextCommandBuilder SetDefaultPermission (bool defaultPermision) | ||||
{ | { | ||||
DefaultPermission = defaultPermision; | DefaultPermission = defaultPermision; | ||||
@@ -70,6 +82,32 @@ namespace Discord.Interactions.Builders | |||||
return this; | return this; | ||||
} | } | ||||
/// <summary> | |||||
/// Sets <see cref="IsEnabledInDm"/>. | |||||
/// </summary> | |||||
/// <param name="isEnabled">New value of the <see cref="IsEnabledInDm"/>.</param> | |||||
/// <returns> | |||||
/// The builder instance. | |||||
/// </returns> | |||||
public ContextCommandBuilder SetEnabledInDm(bool isEnabled) | |||||
{ | |||||
IsEnabledInDm = isEnabled; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Sets <see cref="DefaultMemberPermissions"/>. | |||||
/// </summary> | |||||
/// <param name="permissions">New value of the <see cref="DefaultMemberPermissions"/>.</param> | |||||
/// <returns> | |||||
/// The builder instance. | |||||
/// </returns> | |||||
public ContextCommandBuilder WithDefaultMemberPermissions(GuildPermission permissions) | |||||
{ | |||||
DefaultMemberPermissions = permissions; | |||||
return this; | |||||
} | |||||
internal override ContextCommandInfo Build (ModuleInfo module, InteractionService commandService) => | internal override ContextCommandInfo Build (ModuleInfo module, InteractionService commandService) => | ||||
ContextCommandInfo.Create(this, module, commandService); | ContextCommandInfo.Create(this, module, commandService); | ||||
} | } | ||||
@@ -17,8 +17,19 @@ namespace Discord.Interactions.Builders | |||||
/// <summary> | /// <summary> | ||||
/// Gets and sets the default permission of this command. | /// Gets and sets the default permission of this command. | ||||
/// </summary> | /// </summary> | ||||
[Obsolete($"To be deprecated soon, use {nameof(IsEnabledInDm)} and {nameof(DefaultMemberPermissions)} instead.")] | |||||
public bool DefaultPermission { get; set; } = true; | public bool DefaultPermission { get; set; } = true; | ||||
/// <summary> | |||||
/// Gets whether this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsEnabledInDm { get; set; } = true; | |||||
/// <summary> | |||||
/// Gets the default permissions needed for executing this command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null; | |||||
internal SlashCommandBuilder (ModuleBuilder module) : base(module) { } | internal SlashCommandBuilder (ModuleBuilder module) : base(module) { } | ||||
/// <summary> | /// <summary> | ||||
@@ -49,6 +60,7 @@ namespace Discord.Interactions.Builders | |||||
/// <returns> | /// <returns> | ||||
/// The builder instance. | /// The builder instance. | ||||
/// </returns> | /// </returns> | ||||
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")] | |||||
public SlashCommandBuilder WithDefaultPermission (bool permission) | public SlashCommandBuilder WithDefaultPermission (bool permission) | ||||
{ | { | ||||
DefaultPermission = permission; | DefaultPermission = permission; | ||||
@@ -70,6 +82,32 @@ namespace Discord.Interactions.Builders | |||||
return this; | return this; | ||||
} | } | ||||
/// <summary> | |||||
/// Sets <see cref="IsEnabledInDm"/>. | |||||
/// </summary> | |||||
/// <param name="isEnabled">New value of the <see cref="IsEnabledInDm"/>.</param> | |||||
/// <returns> | |||||
/// The builder instance. | |||||
/// </returns> | |||||
public SlashCommandBuilder SetEnabledInDm(bool isEnabled) | |||||
{ | |||||
IsEnabledInDm = isEnabled; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Sets <see cref="DefaultMemberPermissions"/>. | |||||
/// </summary> | |||||
/// <param name="permissions">New value of the <see cref="DefaultMemberPermissions"/>.</param> | |||||
/// <returns> | |||||
/// The builder instance. | |||||
/// </returns> | |||||
public SlashCommandBuilder WithDefaultMemberPermissions(GuildPermission permissions) | |||||
{ | |||||
DefaultMemberPermissions = permissions; | |||||
return this; | |||||
} | |||||
internal override SlashCommandInfo Build (ModuleInfo module, InteractionService commandService) => | internal override SlashCommandInfo Build (ModuleInfo module, InteractionService commandService) => | ||||
new SlashCommandInfo(this, module, commandService); | new SlashCommandInfo(this, module, commandService); | ||||
} | } | ||||
@@ -51,9 +51,20 @@ namespace Discord.Interactions.Builders | |||||
/// <summary> | /// <summary> | ||||
/// Gets and sets the default permission of this module. | /// Gets and sets the default permission of this module. | ||||
/// </summary> | /// </summary> | ||||
[Obsolete($"To be deprecated soon, use {nameof(IsEnabledInDm)} and {nameof(DefaultMemberPermissions)} instead.")] | |||||
public bool DefaultPermission { get; set; } = true; | public bool DefaultPermission { get; set; } = true; | ||||
/// <summary> | /// <summary> | ||||
/// Gets whether this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsEnabledInDm { get; set; } = true; | |||||
/// <summary> | |||||
/// Gets the default permissions needed for executing this command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; set; } = null; | |||||
/// <summary> | |||||
/// Gets and sets whether this has a <see cref="DontAutoRegisterAttribute"/>. | /// Gets and sets whether this has a <see cref="DontAutoRegisterAttribute"/>. | ||||
/// </summary> | /// </summary> | ||||
public bool DontAutoRegister { get; set; } = false; | public bool DontAutoRegister { get; set; } = false; | ||||
@@ -159,6 +170,7 @@ namespace Discord.Interactions.Builders | |||||
/// <returns> | /// <returns> | ||||
/// The builder instance. | /// The builder instance. | ||||
/// </returns> | /// </returns> | ||||
[Obsolete($"To be deprecated soon, use {nameof(SetEnabledInDm)} and {nameof(WithDefaultMemberPermissions)} instead.")] | |||||
public ModuleBuilder WithDefaultPermission (bool permission) | public ModuleBuilder WithDefaultPermission (bool permission) | ||||
{ | { | ||||
DefaultPermission = permission; | DefaultPermission = permission; | ||||
@@ -166,6 +178,32 @@ namespace Discord.Interactions.Builders | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Sets <see cref="IsEnabledInDm"/>. | |||||
/// </summary> | |||||
/// <param name="isEnabled">New value of the <see cref="IsEnabledInDm"/>.</param> | |||||
/// <returns> | |||||
/// The builder instance. | |||||
/// </returns> | |||||
public ModuleBuilder SetEnabledInDm(bool isEnabled) | |||||
{ | |||||
IsEnabledInDm = isEnabled; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Sets <see cref="DefaultMemberPermissions"/>. | |||||
/// </summary> | |||||
/// <param name="permissions">New value of the <see cref="DefaultMemberPermissions"/>.</param> | |||||
/// <returns> | |||||
/// The builder instance. | |||||
/// </returns> | |||||
public ModuleBuilder WithDefaultMemberPermissions(GuildPermission permissions) | |||||
{ | |||||
DefaultMemberPermissions = permissions; | |||||
return this; | |||||
} | |||||
/// <summary> | |||||
/// Adds attributes to <see cref="Attributes"/>. | /// Adds attributes to <see cref="Attributes"/>. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="attributes">New attributes to be added to <see cref="Attributes"/>.</param> | /// <param name="attributes">New attributes to be added to <see cref="Attributes"/>.</param> | ||||
@@ -85,6 +85,16 @@ namespace Discord.Interactions.Builders | |||||
builder.DefaultPermission = defPermission.IsDefaultPermission; | builder.DefaultPermission = defPermission.IsDefaultPermission; | ||||
} | } | ||||
break; | break; | ||||
case EnabledInDmAttribute enabledInDm: | |||||
{ | |||||
builder.IsEnabledInDm = enabledInDm.IsEnabled; | |||||
} | |||||
break; | |||||
case DefaultMemberPermissionsAttribute memberPermission: | |||||
{ | |||||
builder.DefaultMemberPermissions = memberPermission.Permissions; | |||||
} | |||||
break; | |||||
case PreconditionAttribute precondition: | case PreconditionAttribute precondition: | ||||
builder.AddPreconditions(precondition); | builder.AddPreconditions(precondition); | ||||
break; | break; | ||||
@@ -169,6 +179,16 @@ namespace Discord.Interactions.Builders | |||||
builder.DefaultPermission = defaultPermission.IsDefaultPermission; | builder.DefaultPermission = defaultPermission.IsDefaultPermission; | ||||
} | } | ||||
break; | break; | ||||
case EnabledInDmAttribute enabledInDm: | |||||
{ | |||||
builder.IsEnabledInDm = enabledInDm.IsEnabled; | |||||
} | |||||
break; | |||||
case DefaultMemberPermissionsAttribute memberPermission: | |||||
{ | |||||
builder.DefaultMemberPermissions = memberPermission.Permissions; | |||||
} | |||||
break; | |||||
case PreconditionAttribute precondition: | case PreconditionAttribute precondition: | ||||
builder.WithPreconditions(precondition); | builder.WithPreconditions(precondition); | ||||
break; | break; | ||||
@@ -211,6 +231,16 @@ namespace Discord.Interactions.Builders | |||||
builder.DefaultPermission = defaultPermission.IsDefaultPermission; | builder.DefaultPermission = defaultPermission.IsDefaultPermission; | ||||
} | } | ||||
break; | break; | ||||
case EnabledInDmAttribute enabledInDm: | |||||
{ | |||||
builder.IsEnabledInDm = enabledInDm.IsEnabled; | |||||
} | |||||
break; | |||||
case DefaultMemberPermissionsAttribute memberPermission: | |||||
{ | |||||
builder.DefaultMemberPermissions = memberPermission.Permissions; | |||||
} | |||||
break; | |||||
case PreconditionAttribute precondition: | case PreconditionAttribute precondition: | ||||
builder.WithPreconditions(precondition); | builder.WithPreconditions(precondition); | ||||
break; | break; | ||||
@@ -18,6 +18,12 @@ namespace Discord.Interactions | |||||
public bool DefaultPermission { get; } | public bool DefaultPermission { get; } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public bool IsEnabledInDm { get; } | |||||
/// <inheritdoc/> | |||||
public GuildPermission? DefaultMemberPermissions { get; } | |||||
/// <inheritdoc/> | |||||
public override IReadOnlyCollection<CommandParameterInfo> Parameters { get; } | public override IReadOnlyCollection<CommandParameterInfo> Parameters { get; } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
@@ -31,6 +37,8 @@ namespace Discord.Interactions | |||||
{ | { | ||||
CommandType = builder.CommandType; | CommandType = builder.CommandType; | ||||
DefaultPermission = builder.DefaultPermission; | DefaultPermission = builder.DefaultPermission; | ||||
IsEnabledInDm = builder.IsEnabledInDm; | |||||
DefaultMemberPermissions = builder.DefaultMemberPermissions; | |||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | ||||
} | } | ||||
@@ -27,6 +27,12 @@ namespace Discord.Interactions | |||||
public bool DefaultPermission { get; } | public bool DefaultPermission { get; } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public bool IsEnabledInDm { get; } | |||||
/// <inheritdoc/> | |||||
public GuildPermission? DefaultMemberPermissions { get; } | |||||
/// <inheritdoc/> | |||||
public override IReadOnlyCollection<SlashCommandParameterInfo> Parameters { get; } | public override IReadOnlyCollection<SlashCommandParameterInfo> Parameters { get; } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
@@ -41,6 +47,8 @@ namespace Discord.Interactions | |||||
{ | { | ||||
Description = builder.Description; | Description = builder.Description; | ||||
DefaultPermission = builder.DefaultPermission; | DefaultPermission = builder.DefaultPermission; | ||||
IsEnabledInDm = builder.IsEnabledInDm; | |||||
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(); | ||||
@@ -1,3 +1,5 @@ | |||||
using System; | |||||
namespace Discord.Interactions | namespace Discord.Interactions | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -18,6 +20,17 @@ namespace Discord.Interactions | |||||
/// <summary> | /// <summary> | ||||
/// Gets the DefaultPermission of this command. | /// Gets the DefaultPermission of this command. | ||||
/// </summary> | /// </summary> | ||||
[Obsolete($"To be deprecated soon, use {nameof(IsEnabledInDm)} and {nameof(DefaultMemberPermissions)} instead.")] | |||||
bool DefaultPermission { get; } | bool DefaultPermission { get; } | ||||
/// <summary> | |||||
/// Gets whether this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsEnabledInDm { get; } | |||||
/// <summary> | |||||
/// Gets the default permissions needed for executing this command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; } | |||||
} | } | ||||
} | } |
@@ -41,9 +41,20 @@ namespace Discord.Interactions | |||||
/// <summary> | /// <summary> | ||||
/// Gets the default Permission of this module. | /// Gets the default Permission of this module. | ||||
/// </summary> | /// </summary> | ||||
[Obsolete($"To be deprecated soon, use {nameof(IsEnabledInDm)} and {nameof(DefaultMemberPermissions)} instead.")] | |||||
public bool DefaultPermission { get; } | public bool DefaultPermission { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets whether this command can be used in DMs. | |||||
/// </summary> | |||||
public bool IsEnabledInDm { get; } | |||||
/// <summary> | |||||
/// Gets the default permissions needed for executing this command. | |||||
/// </summary> | |||||
public GuildPermission? DefaultMemberPermissions { get; } | |||||
/// <summary> | |||||
/// Gets the collection of Sub Modules of this module. | /// Gets the collection of Sub Modules of this module. | ||||
/// </summary> | /// </summary> | ||||
public IReadOnlyList<ModuleInfo> SubModules { get; } | public IReadOnlyList<ModuleInfo> SubModules { get; } | ||||
@@ -110,6 +121,8 @@ namespace Discord.Interactions | |||||
Description = builder.Description; | Description = builder.Description; | ||||
Parent = parent; | Parent = parent; | ||||
DefaultPermission = builder.DefaultPermission; | DefaultPermission = builder.DefaultPermission; | ||||
IsEnabledInDm = builder.IsEnabledInDm; | |||||
DefaultMemberPermissions = BuildDefaultMemberPermissions(builder); | |||||
SlashCommands = BuildSlashCommands(builder).ToImmutableArray(); | SlashCommands = BuildSlashCommands(builder).ToImmutableArray(); | ||||
ContextCommands = BuildContextCommands(builder).ToImmutableArray(); | ContextCommands = BuildContextCommands(builder).ToImmutableArray(); | ||||
ComponentCommands = BuildComponentCommands(builder).ToImmutableArray(); | ComponentCommands = BuildComponentCommands(builder).ToImmutableArray(); | ||||
@@ -226,5 +239,20 @@ namespace Discord.Interactions | |||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
private static GuildPermission? BuildDefaultMemberPermissions(ModuleBuilder builder) | |||||
{ | |||||
var permissions = builder.DefaultMemberPermissions; | |||||
var parent = builder.Parent; | |||||
while (parent != null) | |||||
{ | |||||
permissions = (permissions ?? 0) | (parent.DefaultMemberPermissions ?? 0); | |||||
parent = parent.Parent; | |||||
} | |||||
return permissions; | |||||
} | |||||
} | } | ||||
} | } |
@@ -40,7 +40,8 @@ namespace Discord.Interactions | |||||
{ | { | ||||
Name = commandInfo.Name, | Name = commandInfo.Name, | ||||
Description = commandInfo.Description, | Description = commandInfo.Description, | ||||
IsDefaultPermission = commandInfo.DefaultPermission, | |||||
IsDMEnabled = commandInfo.IsEnabledInDm, | |||||
DefaultMemberPermissions = (commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0) | |||||
}.Build(); | }.Build(); | ||||
if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount) | if (commandInfo.Parameters.Count > SlashCommandBuilder.MaxOptionsCount) | ||||
@@ -64,8 +65,20 @@ namespace Discord.Interactions | |||||
public static ApplicationCommandProperties ToApplicationCommandProps(this ContextCommandInfo commandInfo) | public static ApplicationCommandProperties ToApplicationCommandProps(this ContextCommandInfo commandInfo) | ||||
=> commandInfo.CommandType switch | => commandInfo.CommandType switch | ||||
{ | { | ||||
ApplicationCommandType.Message => new MessageCommandBuilder { Name = commandInfo.Name, IsDefaultPermission = commandInfo.DefaultPermission}.Build(), | |||||
ApplicationCommandType.User => new UserCommandBuilder { Name = commandInfo.Name, IsDefaultPermission=commandInfo.DefaultPermission}.Build(), | |||||
ApplicationCommandType.Message => new MessageCommandBuilder | |||||
{ | |||||
Name = commandInfo.Name, | |||||
IsDefaultPermission = commandInfo.DefaultPermission, | |||||
DefaultMemberPermissions = (commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0), | |||||
IsDMEnabled = commandInfo.IsEnabledInDm | |||||
}.Build(), | |||||
ApplicationCommandType.User => new UserCommandBuilder | |||||
{ | |||||
Name = commandInfo.Name, | |||||
IsDefaultPermission = commandInfo.DefaultPermission, | |||||
DefaultMemberPermissions = (commandInfo.DefaultMemberPermissions ?? 0) | (commandInfo.Module.DefaultMemberPermissions ?? 0), | |||||
IsDMEnabled = commandInfo.IsEnabledInDm | |||||
}.Build(), | |||||
_ => throw new InvalidOperationException($"{commandInfo.CommandType} isn't a supported command type.") | _ => throw new InvalidOperationException($"{commandInfo.CommandType} isn't a supported command type.") | ||||
}; | }; | ||||
#endregion | #endregion | ||||
@@ -113,6 +126,8 @@ namespace Discord.Interactions | |||||
Name = moduleInfo.SlashGroupName, | Name = moduleInfo.SlashGroupName, | ||||
Description = moduleInfo.Description, | Description = moduleInfo.Description, | ||||
IsDefaultPermission = moduleInfo.DefaultPermission, | IsDefaultPermission = moduleInfo.DefaultPermission, | ||||
IsDMEnabled = moduleInfo.IsEnabledInDm, | |||||
DefaultMemberPermissions = moduleInfo.DefaultMemberPermissions | |||||
}.Build(); | }.Build(); | ||||
if (options.Count > SlashCommandBuilder.MaxOptionsCount) | if (options.Count > SlashCommandBuilder.MaxOptionsCount) | ||||
@@ -24,5 +24,12 @@ namespace Discord.API | |||||
[JsonProperty("default_permission")] | [JsonProperty("default_permission")] | ||||
public Optional<bool> DefaultPermissions { get; set; } | public Optional<bool> DefaultPermissions { get; set; } | ||||
// V2 Permissions | |||||
[JsonProperty("dm_permission")] | |||||
public Optional<bool?> DmPermission { get; set; } | |||||
[JsonProperty("default_member_permissions")] | |||||
public Optional<GuildPermission?> DefaultMemberPermission { get; set; } | |||||
} | } | ||||
} | } |
@@ -19,6 +19,12 @@ namespace Discord.API.Rest | |||||
[JsonProperty("default_permission")] | [JsonProperty("default_permission")] | ||||
public Optional<bool> DefaultPermission { get; set; } | public Optional<bool> DefaultPermission { get; set; } | ||||
[JsonProperty("dm_permission")] | |||||
public Optional<bool?> DmPermission { get; set; } | |||||
[JsonProperty("default_member_permissions")] | |||||
public Optional<GuildPermission?> DefaultMemberPermission { 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) | ||||
{ | { | ||||
@@ -100,7 +100,12 @@ namespace Discord.Rest | |||||
Type = arg.Type, | Type = arg.Type, | ||||
DefaultPermission = arg.IsDefaultPermission.IsSpecified | DefaultPermission = arg.IsDefaultPermission.IsSpecified | ||||
? arg.IsDefaultPermission.Value | ? arg.IsDefaultPermission.Value | ||||
: Optional<bool>.Unspecified | |||||
: Optional<bool>.Unspecified, | |||||
// TODO: better conversion to nullable optionals | |||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), | |||||
DmPermission = arg.IsDMEnabled.ToNullable() | |||||
}; | }; | ||||
if (arg is SlashCommandProperties slashProps) | if (arg is SlashCommandProperties slashProps) | ||||
@@ -134,7 +139,11 @@ namespace Discord.Rest | |||||
Type = arg.Type, | Type = arg.Type, | ||||
DefaultPermission = arg.IsDefaultPermission.IsSpecified | DefaultPermission = arg.IsDefaultPermission.IsSpecified | ||||
? arg.IsDefaultPermission.Value | ? arg.IsDefaultPermission.Value | ||||
: Optional<bool>.Unspecified | |||||
: Optional<bool>.Unspecified, | |||||
// TODO: better conversion to nullable optionals | |||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), | |||||
DmPermission = arg.IsDMEnabled.ToNullable() | |||||
}; | }; | ||||
if (arg is SlashCommandProperties slashProps) | if (arg is SlashCommandProperties slashProps) | ||||
@@ -171,7 +180,11 @@ namespace Discord.Rest | |||||
Type = arg.Type, | Type = arg.Type, | ||||
DefaultPermission = arg.IsDefaultPermission.IsSpecified | DefaultPermission = arg.IsDefaultPermission.IsSpecified | ||||
? arg.IsDefaultPermission.Value | ? arg.IsDefaultPermission.Value | ||||
: Optional<bool>.Unspecified | |||||
: Optional<bool>.Unspecified, | |||||
// TODO: better conversion to nullable optionals | |||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), | |||||
DmPermission = arg.IsDMEnabled.ToNullable() | |||||
}; | }; | ||||
if (arg is SlashCommandProperties slashProps) | if (arg is SlashCommandProperties slashProps) | ||||
@@ -285,7 +298,11 @@ namespace Discord.Rest | |||||
Type = arg.Type, | Type = arg.Type, | ||||
DefaultPermission = arg.IsDefaultPermission.IsSpecified | DefaultPermission = arg.IsDefaultPermission.IsSpecified | ||||
? arg.IsDefaultPermission.Value | ? arg.IsDefaultPermission.Value | ||||
: Optional<bool>.Unspecified | |||||
: Optional<bool>.Unspecified, | |||||
// TODO: better conversion to nullable optionals | |||||
DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), | |||||
DmPermission = arg.IsDMEnabled.ToNullable() | |||||
}; | }; | ||||
if (arg is SlashCommandProperties slashProps) | if (arg is SlashCommandProperties slashProps) | ||||
@@ -27,6 +27,12 @@ namespace Discord.Rest | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public bool IsDefaultPermission { get; private set; } | public bool IsDefaultPermission { get; private set; } | ||||
/// <inheritdoc/> | |||||
public bool IsEnabledInDm { get; private set; } | |||||
/// <inheritdoc/> | |||||
public GuildPermissions DefaultMemberPermissions { get; private set; } | |||||
/// <summary> | /// <summary> | ||||
/// Gets a collection of options for this command. | /// Gets a collection of options for this command. | ||||
/// </summary> | /// </summary> | ||||
@@ -57,6 +63,10 @@ namespace Discord.Rest | |||||
Options = model.Options.IsSpecified | Options = model.Options.IsSpecified | ||||
? model.Options.Value.Select(RestApplicationCommandOption.Create).ToImmutableArray() | ? model.Options.Value.Select(RestApplicationCommandOption.Create).ToImmutableArray() | ||||
: ImmutableArray.Create<RestApplicationCommandOption>(); | : ImmutableArray.Create<RestApplicationCommandOption>(); | ||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true); | |||||
DefaultMemberPermissions = model.DefaultMemberPermission.IsSpecified | |||||
? new GuildPermissions((ulong)model.DefaultMemberPermission.Value) : GuildPermissions.None; | |||||
} | } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
@@ -36,6 +36,12 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||
public bool IsDefaultPermission { get; private set; } | public bool IsDefaultPermission { get; private set; } | ||||
/// <inheritdoc/> | |||||
public bool IsEnabledInDm { get; private set; } | |||||
/// <inheritdoc/> | |||||
public GuildPermissions DefaultMemberPermissions { get; private set; } | |||||
/// <summary> | /// <summary> | ||||
/// Gets a collection of <see cref="SocketApplicationCommandOption"/>s for this command. | /// Gets a collection of <see cref="SocketApplicationCommandOption"/>s for this command. | ||||
/// </summary> | /// </summary> | ||||
@@ -86,6 +92,10 @@ namespace Discord.WebSocket | |||||
Options = model.Options.IsSpecified | Options = model.Options.IsSpecified | ||||
? model.Options.Value.Select(SocketApplicationCommandOption.Create).ToImmutableArray() | ? model.Options.Value.Select(SocketApplicationCommandOption.Create).ToImmutableArray() | ||||
: ImmutableArray.Create<SocketApplicationCommandOption>(); | : ImmutableArray.Create<SocketApplicationCommandOption>(); | ||||
IsEnabledInDm = model.DmPermission.GetValueOrDefault(true).GetValueOrDefault(true); | |||||
DefaultMemberPermissions = model.DefaultMemberPermission.IsSpecified | |||||
? new GuildPermissions((ulong)model.DefaultMemberPermission.Value) : GuildPermissions.None; | |||||
} | } | ||||
/// <inheritdoc/> | /// <inheritdoc/> | ||||