permissions.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import discord
  2. import myanimebot.utils as utils
  3. import myanimebot.globals as globals
  4. async def in_allowed_role(ctx) -> bool :
  5. ''' Checks if a user has the permissions to configure the bot on a specific server '''
  6. user = ctx.author
  7. server = ctx.guild
  8. targetRole = utils.get_allowed_role(server.id)
  9. globals.logger.debug ("Role target: " + str(targetRole))
  10. if user.guild_permissions.administrator:
  11. globals.logger.debug (str(user) + " is server admin on " + str(server) + "!")
  12. return True
  13. elif (targetRole is None):
  14. globals.logger.debug ("No role specified for " + str(server))
  15. return True
  16. else:
  17. for role in user.roles:
  18. if str(role.id) == str(targetRole):
  19. globals.logger.debug ("Permissions validated for " + str(user))
  20. return True
  21. await ctx.send("Only allowed users can use this command!")
  22. return False
  23. async def is_administrator(ctx) -> bool :
  24. ''' Checks if a user is a server's adminitrator '''
  25. if ctx.author.guild_permissions.administrator:
  26. return True
  27. await ctx.send("Only server's admins can use this command.")
  28. return False