Add IChannel.Nsfw, RequireNsfw precondition (#633)
* Add IChannel.Nsfw, RequireNsfw precondition * Refactored IChannel.Nsfw to IsNsfw, removed NsfwUtils Per pull-request feedback * proper nsfw channel check
This commit is contained in:
committed by
RogueException
parent
05f8f41567
commit
7f1fc286cf
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Require that the command is invoked in a channel marked NSFW
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class RequireNsfwAttribute : PreconditionAttribute
|
||||
{
|
||||
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
|
||||
{
|
||||
if (context.Channel.IsNsfw)
|
||||
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||
else
|
||||
return Task.FromResult(PreconditionResult.FromError("This command may only be invoked in an NSFW channel."));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user