-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathperm_check.py
51 lines (33 loc) · 1.27 KB
/
perm_check.py
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
44
45
46
47
48
49
50
51
from discord.ext import commands
import discord.utils
# These are coroutines embedded with @something before the async command to
# check the permission before executing a command
def check_permissions(ctx, perms):
msg = ctx.message
if is_owner_check(msg):
return True
ch = msg.channel
author = msg.author
resolved = ch.permissions_for(author)
return all(getattr(resolved, name, None) == value for name, value in perms.items())
def role_or_permissions(ctx, check, **perms):
if check_permissions(ctx, perms):
return True
ch = ctx.message.channel
author = ctx.message.author
if ch.is_private:
return False
role = discord.utils.find(check, author.roles)
return role is not None
def mod_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name in ('Bot Mod', 'Bot Admin'), **perms)
return commands.check(predicate)
def admin_or_permissions(**perms):
def predicate(ctx):
return role_or_permissions(ctx, lambda r: r.name == 'Bot Admin', **perms)
return commands.check(predicate)
def is_owner_check(message):
return message.author.id == '80088516616269824'
def is_owner():
return commands.check(lambda ctx: is_owner_check(ctx.message))