|
@@ -3,17 +3,39 @@ using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
namespace Discord.Commands |
|
|
namespace Discord.Commands |
|
|
{ |
|
|
{ |
|
|
|
|
|
/// <summary> |
|
|
|
|
|
/// This attribute requires that the user invoking the command has a specified permission. |
|
|
|
|
|
/// </summary> |
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] |
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] |
|
|
public class RequireUserPermissionAttribute : PreconditionAttribute |
|
|
public class RequireUserPermissionAttribute : PreconditionAttribute |
|
|
{ |
|
|
{ |
|
|
public GuildPermission? GuildPermission { get; } |
|
|
public GuildPermission? GuildPermission { get; } |
|
|
public ChannelPermission? ChannelPermission { get; } |
|
|
public ChannelPermission? ChannelPermission { get; } |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
/// Require that the user invoking the command has a specified GuildPermission |
|
|
|
|
|
/// </summary> |
|
|
|
|
|
/// <remarks>This precondition will always fail if the command is being invoked in a private channel.</remarks> |
|
|
|
|
|
/// <param name="permission">The GuildPermission that the user must have. Multiple permissions can be specified by ORing or ANDing the permissions together.</param> |
|
|
public RequireUserPermissionAttribute(GuildPermission permission) |
|
|
public RequireUserPermissionAttribute(GuildPermission permission) |
|
|
{ |
|
|
{ |
|
|
GuildPermission = permission; |
|
|
GuildPermission = permission; |
|
|
ChannelPermission = null; |
|
|
ChannelPermission = null; |
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
|
|
|
/// Require that the user invoking the command has a specified ChannelPermission. |
|
|
|
|
|
/// </summary> |
|
|
|
|
|
/// <param name="permission">The ChannelPermission that the user must have. Multiple permissions can be specified by ORing or ANDing the permissions together.</param> |
|
|
|
|
|
/// <example> |
|
|
|
|
|
/// <code language="c#"> |
|
|
|
|
|
/// [Command("permission")] |
|
|
|
|
|
/// [RequireUserPermission(ChannelPermission.ReadMessageHistory & ChannelPermission.ReadMessages)] |
|
|
|
|
|
/// public async Task HasPermission() |
|
|
|
|
|
/// { |
|
|
|
|
|
/// await ReplyAsync("You can read messages and the message history!"); |
|
|
|
|
|
/// } |
|
|
|
|
|
/// </code> |
|
|
|
|
|
/// </example> |
|
|
public RequireUserPermissionAttribute(ChannelPermission permission) |
|
|
public RequireUserPermissionAttribute(ChannelPermission permission) |
|
|
{ |
|
|
{ |
|
|
ChannelPermission = permission; |
|
|
ChannelPermission = permission; |
|
|