forked from skyegallup/lehrbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
52 lines (43 loc) · 1.62 KB
/
classes.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
from typing import Callable, List
from discord.channel import TextChannel
from discord.guild import Guild
from discord.member import Member
from discord.role import Role
def check_admin(func: Callable[[Member, TextChannel], None]):
async def wrapper(caller: Member, channel: TextChannel, *args, **kwargs):
if not caller.guild_permissions.administrator:
await channel.send(
caller.mention + " You must be an administrator "
"to call this command."
)
else:
await func(caller, channel, *args, **kwargs)
return wrapper
@check_admin
async def makeclass(caller: Member, channel: TextChannel, name: str) -> None:
guild: Guild = caller.guild
await guild.create_role(
name="Class-" + name,
mentionable=True,
reason="Requested by " + caller.mention
)
await channel.send(
caller.mention + ' Class role "{}" has been created.'.format(name)
)
@check_admin
async def deleteclass(caller: Member, channel: TextChannel, name: str) -> None:
guild: Guild = caller.guild
roles: List[Role] = guild.roles
role: Role # doesn't do anything except type hints
for role in roles:
if role.name == "Class-" + name:
await role.delete(reason="Requested by " + caller.mention)
await channel.send(
caller.mention +
' Class role "{}" has been deleted.'.format(name)
)
return
# only runs if the class doesn't exist
await channel.send(
caller.mention + ' Class role "{}" does not exist.'.format(name)
)