A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
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.

преди 13 години
преди 13 години
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 name."""
  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)))