From f6edadbfcadbc9e38e22500a496a74dd49d96d8a Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Fri, 1 Jun 2018 11:25:03 +0100 Subject: added Permissions Class for easy Permission required commands --- DiscoBot/Auxiliary/CommandExtension.cs | 2 ++ DiscoBot/Auxiliary/Permissions.cs | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 DiscoBot/Auxiliary/Permissions.cs (limited to 'DiscoBot/Auxiliary') diff --git a/DiscoBot/Auxiliary/CommandExtension.cs b/DiscoBot/Auxiliary/CommandExtension.cs index 059ea91..5d07f6c 100644 --- a/DiscoBot/Auxiliary/CommandExtension.cs +++ b/DiscoBot/Auxiliary/CommandExtension.cs @@ -42,5 +42,7 @@ m.Context.Channel.DeleteMessagesAsync( messages.Where(x => x.Content.StartsWith($"#{token}\n") && x.Author.IsBot)); } + + } } diff --git a/DiscoBot/Auxiliary/Permissions.cs b/DiscoBot/Auxiliary/Permissions.cs new file mode 100644 index 0000000..48f8040 --- /dev/null +++ b/DiscoBot/Auxiliary/Permissions.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot.Auxiliary +{ + using Discord.Commands; + using Discord.WebSocket; + + public static class Permissions + { + public static bool Check(ICommandContext c, string role) + { + return ((SocketGuildUser)c.User).Roles.ToList().Exists(v => v.Name.Equals(role)); + } + + public static bool Check(ICommandContext c, string[] roles) + { + return roles.Any(role => ((SocketGuildUser)c.User).Roles.ToList().Exists(v => v.Name.Equals(role))); + } + + public static void Test(ICommandContext c, string role) + { + if (!Check(c, role)) + { + c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait(); + } + } + + public static void Test(ICommandContext c, string[] roles) + { + if (!Check(c, roles)) + { + c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait(); + } + } + } +} -- cgit v1.2.3-54-g00ecf