diff options
author | TrueDoctor <d-kobert@web.de> | 2018-06-01 11:25:03 +0100 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-06-01 11:25:03 +0100 |
commit | f6edadbfcadbc9e38e22500a496a74dd49d96d8a (patch) | |
tree | 36749e99ee87b9f481254a890acfb7149e6b3fb8 /DiscoBot/Auxiliary | |
parent | 181dba0f96d8792e3565286b3983830674624cc5 (diff) |
added Permissions Class for easy Permission required commands
Diffstat (limited to 'DiscoBot/Auxiliary')
-rw-r--r-- | DiscoBot/Auxiliary/CommandExtension.cs | 2 | ||||
-rw-r--r-- | DiscoBot/Auxiliary/Permissions.cs | 40 |
2 files changed, 42 insertions, 0 deletions
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(); + } + } + } +} |