Add Attribute to disable commands in DMs

This commit is contained in:
Runebaas 2019-03-17 18:32:56 +01:00
parent 3d493fa531
commit 1e98b44cb7
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6

View file

@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
using Discord.Commands;
namespace Geekbot.net.Lib.CommandPreconditions
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class DisableInDirectMessageAttribute : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
{
var result = context.Guild.Id != 0 ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Command unavailable in Direct Messaging");
return Task.FromResult(result);
}
}
}