Skip to content

Commit 4c3f717

Browse files
committed
Move decorators to seperate file
1 parent 682d9e6 commit 4c3f717

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

core/decorators.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import functools
2+
import discord
3+
from discord.ext import commands
4+
5+
def trigger_typing(func):
6+
@functools.wraps(func)
7+
async def wrapper(self, ctx, *args, **kwargs):
8+
await ctx.trigger_typing()
9+
return await func(self, ctx, *args, **kwargs)
10+
return wrapper
11+
12+
def auth_required(func):
13+
@functools.wraps(func)
14+
async def wrapper(self, ctx, *args, **kwargs):
15+
if self.bot.config.get('MODMAIL_API_TOKEN'):
16+
return await func(self, ctx, *args, **kwargs)
17+
em = discord.Embed(
18+
color=discord.Color.red(),
19+
title='Unauthorized',
20+
description='You can only use this command if you have a configured `MODMAIL_API_TOKEN`. Get your token from https://dashboard.modmail.tk'
21+
)
22+
await ctx.send(embed=em)
23+
return wrapper
24+
25+
def owner_only():
26+
async def predicate(ctx):
27+
allowed = [int(x) for x in ctx.bot.config.get('OWNERS', '0').split(',')]
28+
return ctx.author.id in allowed
29+
return commands.check(predicate)

0 commit comments

Comments
 (0)