A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

tasks.py 2.0 KiB

il y a 13 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 Tasks(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(self.data, thread.name)
  39. def do_listall(self):
  40. tasks = task_manager.task_list.keys()
  41. self.connection.reply(self.data, ', '.join(tasks))
  42. def do_start(self):
  43. kwargs = {}
  44. try:
  45. task_manager.start_task(self.data.args[1], **kwargs)
  46. except IndexError: # no task name given
  47. self.connection.reply(self.data, "what task do you want me to start?")
  48. else:
  49. self.connection.reply(self.data, "task '{}' started.".format(self.data.args[1]))