A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

39 líneas
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Retrieve a list of user rights for a given username via the API.
  4. """
  5. from irc.classes import BaseCommand
  6. from wiki import tools
  7. class Rights(BaseCommand):
  8. def get_hooks(self):
  9. return ["msg"]
  10. def get_help(self, command):
  11. return "Retrieve a list of rights for a given username."
  12. def check(self, data):
  13. if data.is_command and data.command in ["rights", "groups", "permissions", "privileges"]:
  14. return True
  15. return False
  16. def process(self, data):
  17. if not data.args:
  18. self.connection.reply(data, "what user do you want me to look up?")
  19. return
  20. username = ' '.join(data.args)
  21. site = tools.get_site()
  22. user = site.get_user(username)
  23. rights = user.get_groups()
  24. if rights:
  25. try:
  26. rights.remove("*") # remove the implicit '*' group given to everyone
  27. except ValueError:
  28. pass
  29. self.connection.reply(data, "the rights for \x0302{0}\x0301 are {1}.".format(username, ', '.join(rights)))
  30. else:
  31. self.connection.reply(data, "the user \x0302{0}\x0301 has no rights, or does not exist.".format(username))