@@ -5,17 +5,38 @@ using System.Threading.Tasks; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> | |||||
/// This attribute requires that the bot has a speicifed permission in the channel a command is invoked in. | |||||
/// </summary> | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
public class RequireBotPermissionAttribute : PreconditionAttribute | public class RequireBotPermissionAttribute : PreconditionAttribute | ||||
{ | { | ||||
public GuildPermission? GuildPermission { get; } | public GuildPermission? GuildPermission { get; } | ||||
public ChannelPermission? ChannelPermission { get; } | public ChannelPermission? ChannelPermission { get; } | ||||
/// <summary> | |||||
/// Require that the bot account 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 bot must have. Multiple permissions can be specified by ORing or ANDing the permissions together.</param> | |||||
public RequireBotPermissionAttribute(GuildPermission permission) | public RequireBotPermissionAttribute(GuildPermission permission) | ||||
{ | { | ||||
GuildPermission = permission; | GuildPermission = permission; | ||||
ChannelPermission = null; | ChannelPermission = null; | ||||
} | } | ||||
/// <summary> | |||||
/// Require that the bot account has a specified ChannelPermission. | |||||
/// </summary> | |||||
/// <param name="permission">The ChannelPermission that the bot must have. Multiple permissions can be specified by ORing or ANDing the permissions together.</param> | |||||
/// <example> | |||||
/// <code language="c#"> | |||||
/// [Command("permission")] | |||||
/// [RequireBotPermission(ChannelPermission.ManageMessages)] | |||||
/// public async Task Purge() | |||||
/// { | |||||
/// } | |||||
/// </code> | |||||
/// </example> | |||||
public RequireBotPermissionAttribute(ChannelPermission permission) | public RequireBotPermissionAttribute(ChannelPermission permission) | ||||
{ | { | ||||
ChannelPermission = permission; | ChannelPermission = permission; | ||||
@@ -11,11 +11,27 @@ namespace Discord.Commands | |||||
Group = 0x04 | Group = 0x04 | ||||
} | } | ||||
/// <summary> | |||||
/// Require that the command be invoked in a specified context. | |||||
/// </summary> | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
public class RequireContextAttribute : PreconditionAttribute | public class RequireContextAttribute : PreconditionAttribute | ||||
{ | { | ||||
public ContextType Contexts { get; } | public ContextType Contexts { get; } | ||||
/// <summary> | |||||
/// Require that the command be invoked in a specified context. | |||||
/// </summary> | |||||
/// <param name="contexts">The type of context the command can be invoked in. Multiple contexts can be speicifed by ORing the contexts together.</param> | |||||
/// <example> | |||||
/// <code language="c#"> | |||||
/// [Command("private_only")] | |||||
/// [RequireContext(ContextType.DM | ContextType.Group)] | |||||
/// public async Task PrivateOnly() | |||||
/// { | |||||
/// } | |||||
/// </code> | |||||
/// </example> | |||||
public RequireContextAttribute(ContextType contexts) | public RequireContextAttribute(ContextType contexts) | ||||
{ | { | ||||
Contexts = contexts; | Contexts = contexts; | ||||
@@ -6,6 +6,10 @@ using Discord; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
/// <summary> | |||||
/// Require that the command is invoked by the owner of the bot. | |||||
/// </summary> | |||||
/// <remarks>This precondition will only work if the bot is a bot account.</remarks> | |||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||||
public class RequireOwnerAttribute : PreconditionAttribute | public class RequireOwnerAttribute : PreconditionAttribute | ||||
{ | { | ||||
@@ -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; | ||||