summaryrefslogtreecommitdiff
path: root/dsa/DiscoBot/Rework/Permissions.cs
blob: 4d73146a6f3452947997e8a78b1f446b421223de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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 bool Test(ICommandContext c, string role)
        {
            if (!Check(c, role))
            {
                c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait();
                return false;
            }

            return true;
        }

        public static void Test(ICommandContext c, string[] roles)
        {
            if (!Check(c, roles))
            {
                c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait();
            }
        }
    }
}