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.1 KiB

  1. # -*- coding: utf-8 -*-
  2. from classes import BaseCommand
  3. import wiki
  4. class Command(BaseCommand):
  5. """Retrieve a list of rights for a given username."""
  6. name = "rights"
  7. def check(self, data):
  8. commands = ["rights", "groups", "permissions", "privileges"]
  9. if data.is_command and data.command in commands:
  10. return True
  11. return False
  12. def process(self, data):
  13. if not data.args:
  14. name = data.nick
  15. else:
  16. name = ' '.join(data.args)
  17. site = wiki.get_site()
  18. site._maxlag = None
  19. user = site.get_user(name)
  20. try:
  21. rights = user.groups()
  22. except wiki.UserNotFoundError:
  23. msg = "the user \x0302{0}\x0301 does not exist."
  24. self.connection.reply(data, msg.format(name))
  25. return
  26. try:
  27. rights.remove("*") # Remove the '*' group given to everyone
  28. except ValueError:
  29. pass
  30. msg = "the rights for \x0302{0}\x0301 are {1}."
  31. self.connection.reply(data, msg.format(name, ', '.join(rights)))