KiTTY, un bot Discord qui est un petit chat :) Il est basé sur une ancienne version du bot Red, sous Python 3.6 et qui a des fonctionnalités bien sympatiques !
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

90 lines
2.7KB

  1. from discord.ext import commands
  2. import discord.utils
  3. from __main__ import settings
  4. #
  5. # This is a modified version of checks.py, originally made by Rapptz
  6. #
  7. # https://github.com/Rapptz
  8. # https://github.com/Rapptz/RoboDanny/tree/async
  9. #
  10. def is_owner_check(ctx):
  11. _id = ctx.message.author.id
  12. return _id == settings.owner or _id in ctx.bot.settings.co_owners
  13. def is_owner():
  14. return commands.check(is_owner_check)
  15. # The permission system of the bot is based on a "just works" basis
  16. # You have permissions and the bot has permissions. If you meet the permissions
  17. # required to execute the command (and the bot does as well) then it goes through
  18. # and you can execute the command.
  19. # If these checks fail, then there are two fallbacks.
  20. # A role with the name of Bot Mod and a role with the name of Bot Admin.
  21. # Having these roles provides you access to certain commands without actually having
  22. # the permissions required for them.
  23. # Of course, the owner will always be able to execute commands.
  24. def check_permissions(ctx, perms):
  25. if is_owner_check(ctx):
  26. return True
  27. elif not perms:
  28. return False
  29. ch = ctx.message.channel
  30. author = ctx.message.author
  31. resolved = ch.permissions_for(author)
  32. return all(getattr(resolved, name, None) == value for name, value in perms.items())
  33. def role_or_permissions(ctx, check, **perms):
  34. if check_permissions(ctx, perms):
  35. return True
  36. ch = ctx.message.channel
  37. author = ctx.message.author
  38. if ch.is_private:
  39. return False # can't have roles in PMs
  40. role = discord.utils.find(check, author.roles)
  41. return role is not None
  42. def mod_or_permissions(**perms):
  43. def predicate(ctx):
  44. server = ctx.message.server
  45. mod_role = settings.get_server_mod(server).lower()
  46. admin_role = settings.get_server_admin(server).lower()
  47. return role_or_permissions(ctx, lambda r: r.name.lower() in (mod_role,admin_role), **perms)
  48. return commands.check(predicate)
  49. def admin_or_permissions(**perms):
  50. def predicate(ctx):
  51. server = ctx.message.server
  52. admin_role = settings.get_server_admin(server)
  53. return role_or_permissions(ctx, lambda r: r.name.lower() == admin_role.lower(), **perms)
  54. return commands.check(predicate)
  55. def serverowner_or_permissions(**perms):
  56. def predicate(ctx):
  57. if ctx.message.server is None:
  58. return False
  59. server = ctx.message.server
  60. owner = server.owner
  61. if ctx.message.author.id == owner.id:
  62. return True
  63. return check_permissions(ctx,perms)
  64. return commands.check(predicate)
  65. def serverowner():
  66. return serverowner_or_permissions()
  67. def admin():
  68. return admin_or_permissions()
  69. def mod():
  70. return mod_or_permissions()