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.

47 lines
1.5KB

  1. from discord.ext.commands.converter import IDConverter
  2. from discord.ext.commands.errors import BadArgument
  3. import re
  4. # This could've been imported but since it's an internal it's safer
  5. # to get it here
  6. def _get_from_servers(bot, getter, argument):
  7. result = None
  8. for server in bot.servers:
  9. result = getattr(server, getter)(argument)
  10. if result:
  11. return result
  12. return result
  13. class GlobalUser(IDConverter):
  14. """
  15. This is an (almost) straight copy of discord.py's Member converter
  16. The key difference is that if the command is issued in a server it will
  17. first attempt to get the user from that server and upon failing it will
  18. attempt to fish it from the global pool
  19. """
  20. def convert(self):
  21. message = self.ctx.message
  22. bot = self.ctx.bot
  23. match = self._get_id_match() or re.match(r'<@!?([0-9]+)>$', self.argument)
  24. server = message.server
  25. result = None
  26. if match is None:
  27. # not a mention...
  28. if server:
  29. result = server.get_member_named(self.argument)
  30. if result is None:
  31. result = _get_from_servers(bot, 'get_member_named', self.argument)
  32. else:
  33. user_id = match.group(1)
  34. if server:
  35. result = server.get_member(user_id)
  36. if result is None:
  37. result = _get_from_servers(bot, 'get_member', user_id)
  38. if result is None:
  39. raise BadArgument('User "{}" not found'.format(self.argument))
  40. return result