TotalFreedomBot/checks.py

134 lines
3.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
2021-03-29 23:19:01 +00:00
2021-03-29 22:56:25 +00:00
class notAdminCommand(Exception):
2021-03-29 23:19:01 +00:00
def __init__(self,
message="The command you attempted does not exist or is not a whitelisted command for the adminconsole."):
self.message = message
2021-03-29 22:56:25 +00:00
super().__init__(self.message)
2021-03-29 23:19:01 +00:00
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-03-29 22:56:25 +00:00
if role.id in [ctx.bot.discord_mod, ctx.bot.discord_admin] or permissions and all(
getattr(ctx.channel.permissions_for(ctx.author), name, None) == value for name, value in
permissions.items()):
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)
2021-03-29 22:56:25 +00:00
def is_smp_owner():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
if role.id == ctx.bot.smp_owner_id:
return True
else:
raise NoPermission(['IS_GMOD_OWNER'])
2021-03-29 23:19:01 +00:00
2021-03-29 22:56:25 +00:00
return commands.check(predicate)
2021-03-29 23:19:01 +00:00
2021-03-29 22:56:25 +00:00
def is_gmod_owner():
def predicate(ctx):
user = ctx.message.author
for role in user.roles:
if role.id == ctx.bot.gmod_owner_id:
return True
else:
raise NoPermission(['IS_GMOD_OWNER'])
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)