A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

1234567891011121314151617181920212223242526272829303132333435363738
  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. self.connection.reply(data, "who do you want me to look up?")
  15. return
  16. username = ' '.join(data.args)
  17. site = wiki.get_site()
  18. site._maxlag = None
  19. user = site.get_user(username)
  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(username))
  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(username, ', '.join(rights)))