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.

rights.py 1.1 KiB

12345678910111213141516171819202122232425262728293031323334353637
  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. user = site.get_user(username)
  19. try:
  20. rights = user.groups()
  21. except wiki.UserNotFoundError:
  22. msg = "the user \x0302{0}\x0301 does not exist."
  23. self.connection.reply(data, msg.format(username))
  24. return
  25. try:
  26. rights.remove("*") # Remove the '*' group given to everyone
  27. except ValueError:
  28. pass
  29. msg = "the rights for \x0302{0}\x0301 are {1}."
  30. self.connection.reply(data, msg.format(username, ', '.join(rights)))