TotalFreedomBot/checks.py

101 lines
2.4 KiB
Python
Raw Normal View History

2020-10-28 11:47:39 +00:00
from discord.ext import commands
2021-01-07 19:09:07 +00:00
class NoPermission(commands.MissingPermissions):
2020-11-24 19:43:53 +00:00
pass
2020-11-24 19:43:53 +00:00
def is_staff():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
2021-01-07 19:09:07 +00:00
if role.id in [ctx.bot.admin, ctx.bot.senior_admin]:
2020-11-24 19:43:53 +00:00
return True
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['IS_STAFF_MEMBER'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)
2020-11-24 19:43:53 +00:00
def is_dev():
def predicate(ctx):
user = ctx.message.author
2021-01-07 19:09:07 +00:00
if user.id in ctx.bot.devs:
2020-11-24 19:43:53 +00:00
return True
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['BOT_DEVELOPER'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)
2020-11-24 19:43:53 +00:00
def is_mod_or_has_perms(**permissions):
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
2021-01-07 19:09:07 +00:00
if role.id in [ctx.bot.discord_mod, ctx.bot.discord_admin] or permissions:
2020-11-24 19:43:53 +00:00
return True
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['IS_MOD_OR_HAS_PERMS'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)
2020-11-24 19:43:53 +00:00
def is_executive():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
2021-01-07 19:09:07 +00:00
if role.id in [ctx.bot.executive, ctx.bot.asst_exec]:
2020-11-24 19:43:53 +00:00
return True
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['IS_EXECUTIVE'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)
2020-11-24 19:43:53 +00:00
def is_tf_developer():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
2021-01-07 19:09:07 +00:00
if role.id == ctx.bot.developer:
2020-11-24 19:43:53 +00:00
return True
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['IS_TOTALFREEDOM_DEVELOPER'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)
2020-11-24 19:43:53 +00:00
def is_liaison():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
2021-01-07 19:09:07 +00:00
if role.id == ctx.bot.server_liaison:
return True
2020-11-24 19:43:53 +00:00
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['IS_SERVER_LIAISON'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)
2020-10-31 02:05:32 +00:00
2020-11-24 19:43:53 +00:00
def is_creative_designer():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
2021-01-07 19:09:07 +00:00
if role.id == ctx.bot.creative_designer:
return True
2020-11-24 19:43:53 +00:00
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['IS_CREATIVE_DESIGNER'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)
2020-11-24 19:43:53 +00:00
def is_senior():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
2021-01-07 19:09:07 +00:00
if role.id == ctx.bot.senior_admin:
return True
2020-11-24 19:43:53 +00:00
else:
2021-01-07 19:09:07 +00:00
raise NoPermission(['IS_SENIOR_ADMIN'])
2021-01-04 23:43:11 +00:00
2020-11-24 19:43:53 +00:00
return commands.check(predicate)