@@ -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,8 +51,19 @@ 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> | |||||
/// 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> | /// <summary> | ||||
/// Gets and sets whether this has a <see cref="DontAutoRegisterAttribute"/>. | /// Gets and sets whether this has a <see cref="DontAutoRegisterAttribute"/>. | ||||
/// </summary> | /// </summary> | ||||
@@ -159,12 +170,39 @@ 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; | ||||
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 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> | /// <summary> | ||||
/// Adds attributes to <see cref="Attributes"/>. | /// Adds attributes to <see cref="Attributes"/>. | ||||
/// </summary> | /// </summary> | ||||
@@ -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; | ||||