From 1e98b44cb7392b76eb9a75cd0c5c5c37bdf41f58 Mon Sep 17 00:00:00 2001 From: Runebaas Date: Sun, 17 Mar 2019 18:32:56 +0100 Subject: [PATCH] Add Attribute to disable commands in DMs --- .../DisableInDirectMessageAttribute.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Geekbot.net/Lib/CommandPreconditions/DisableInDirectMessageAttribute.cs diff --git a/Geekbot.net/Lib/CommandPreconditions/DisableInDirectMessageAttribute.cs b/Geekbot.net/Lib/CommandPreconditions/DisableInDirectMessageAttribute.cs new file mode 100644 index 0000000..110b69b --- /dev/null +++ b/Geekbot.net/Lib/CommandPreconditions/DisableInDirectMessageAttribute.cs @@ -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 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); + } + } +} \ No newline at end of file