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.

65 rivejä
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Manage wiki tasks from IRC, and check on thread status.
  3. import threading
  4. from irc.base_command import BaseCommand
  5. from wiki import task_manager
  6. from config.irc import *
  7. class ChanOps(BaseCommand):
  8. def get_hooks(self):
  9. return ["msg"]
  10. def get_help(self, command):
  11. return "Manage wiki tasks from IRC, and check on thread status."
  12. def check(self, data):
  13. if data.is_command and data.command in ["tasks", "threads", "tasklist"]:
  14. return True
  15. return False
  16. def process(self, data):
  17. self.data = data
  18. if data.host not in OWNERS:
  19. self.connection.reply(data, "at this time, you must be a bot owner to use this command.")
  20. return
  21. if not data.args:
  22. if data.command == "!tasklist":
  23. self.do_list()
  24. else:
  25. self.connection.reply(data, "no arguments provided. Maybe you wanted '!{cmnd} list', '!{cmnd} start', or '!{cmnd} listall'?".format(cmnd=data.command))
  26. return
  27. if data.args[0] == "list":
  28. self.do_list()
  29. elif data.args[0] == "start":
  30. self.do_start()
  31. elif data.args[0] == "listall":
  32. self.do_listall()
  33. else: # they asked us to do something we don't know
  34. self.connection.reply(data, "unknown argument: \x0303{}\x0301.".format(data.args[0]))
  35. def do_list(self):
  36. threads = threading.enumerate()
  37. for thread in threads:
  38. self.connection.reply(data, thread.name)
  39. def do_listall(self):
  40. tasks = task_manager.task_list.keys()
  41. self.connection.reply(data, ', '.join(tasks))
  42. def do_start(self):
  43. kwargs = {}
  44. try:
  45. task_manager.start_task(data.args[1], **kwargs)
  46. except IndexError: # no task name given
  47. self.connection.reply(data, "what task do you want me to start?")
  48. else:
  49. self.connection.reply(data, "task '{}' started.".format(data.args[1]))