You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7KB

  1. from discord.ext import commands
  2. import load_config
  3. from config.server_config import ServerConfig
  4. import discord
  5. def is_bot_owner():
  6. return commands.check(lambda ctx: ctx.message.author.id == load_config.owner)
  7. def is_owner_or_admin():
  8. def predicate(ctx):
  9. if ctx.message.author.id == load_config.owner:
  10. return True
  11. else:
  12. for role in ctx.message.author.roles:
  13. if role.id in ServerConfig().load_config()[ctx.message.server.id]["perm_roles"]["admin"]:
  14. return True
  15. return False
  16. return commands.check(predicate)
  17. def is_admin_or_mod():
  18. def predicate(ctx):
  19. if ctx.message.author.id == load_config.owner:
  20. return True
  21. else:
  22. admin_roles = ServerConfig().load_config()[ctx.message.server.id]["perm_roles"]["admin"]
  23. mod_roles = ServerConfig().load_config()[ctx.message.server.id]["perm_roles"]["mod"]
  24. for role in ctx.message.author.roles:
  25. if role.id in mod_roles or role.id in admin_roles:
  26. return True
  27. return False
  28. return commands.check(predicate)
  29. def nsfw_predicate(ctx):
  30. nsfw = ServerConfig().load_config()[ctx.message.server.id]["nsfw"]
  31. if not nsfw["channels"] and nsfw["enabled"]:
  32. return nsfw["enabled"] == 1
  33. elif nsfw["enabled"] and nsfw["channels"]:
  34. return ctx.message.channel.id in nsfw["channels"]
  35. else:
  36. return False
  37. def is_nfsw_enabled():
  38. return commands.check(lambda ctx: nsfw_predicate(ctx))
  39. def isnt_anal():
  40. return commands.check(lambda ctx: ServerConfig().load_config()[ctx.message.server.id]["is_anal"]["y/n"] and nsfw_predicate(ctx) or not ServerConfig().load_config()[ctx.message.server.id]["is_anal"]["y/n"])
  41. def not_pm():
  42. return commands.check(lambda ctx: ctx.message.channel.type != discord.ChannelType.private)