-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.py
69 lines (55 loc) · 1.61 KB
/
util.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from typing import Optional
commands = {
"queryc": [],
"query": [],
"forcopy": [],
"pinset": [],
"pinsetid": [],
"channelblock": [],
"channelidblock": [],
"clip": [],
"onii-chan": [],
"bean": [],
"help": [],
None: [],
}
clip_requester_roles = [
"contributor",
"clipper",
"regular",
"server booster",
"donator",
"sponsor",
]
def command_starts_with(command: str) -> Optional[str]:
for possible in commands:
if command.startswith(possible):
return possible
def register_command(command: Optional[str]):
def wrapper(func):
async def inner(**kwargs):
try:
return await func(**kwargs)
except TypeError:
return func(**kwargs)
commands[command].append(inner)
return inner
return wrapper
def needs_contributor(func):
async def inner(*args, **kwargs):
if await is_contributor(kwargs["message"].author):
return await func(*args, **kwargs)
else:
await kwargs["message"].channel.send("nice try")
return inner
def needs_clip_requester(func):
async def inner(*args, **kwargs):
if await is_clip_requester(kwargs["message"].author):
return await func(*args, **kwargs)
else:
await kwargs["message"].channel.send("Sorry, you can't request a clip")
return inner
async def is_clip_requester(user):
return any(x.name.lower() in clip_requester_roles for x in user.roles)
async def is_contributor(user):
return any(x.name.lower() == "contributor" for x in user.roles)