-
Notifications
You must be signed in to change notification settings - Fork 6
/
discord_wrappers.py
47 lines (37 loc) · 1.54 KB
/
discord_wrappers.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
import discord
from configurations import CONFIG
def guild_required(function):
async def wrapper(*args, **kwargs):
message = kwargs['message']
if not message.guild:
self = args[0]
e = discord.Embed(title='Restricted Command', color=self.RED)
e.add_field(name='Error', value='This command is not available in private messages.')
await self.answer(message, e)
return
await function(*args, **kwargs)
return wrapper
def admin_required(function):
async def wrapper(*args, **kwargs):
self = args[0]
message = kwargs['message']
if not self.is_guild_admin(message):
e = discord.Embed(title='Administrative change', color=self.RED)
e.add_field(name='Error', value='You need to be server owner or administrator to use this command.')
await self.answer(message, e)
return
await function(*args, **kwargs)
return wrapper
def owner_required(function):
async def wrapper(*args, **kwargs):
self = args[0]
message = kwargs['message']
is_special = message.author.id in CONFIG.get('special_users')
is_owner = await self.is_owner(message)
if not is_owner and not is_special:
e = discord.Embed(title='Owner command', color=self.RED)
e.add_field(name='Error', value='Only the bot owner has permission to use this command.')
await self.answer(message, e)
return
await function(*args, **kwargs)
return wrapper