A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

72 行
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. EarwigBot's IRC Watcher Rules
  4. This file contains (configurable!) rules that EarwigBot's watcher uses after it
  5. recieves an event from IRC.
  6. """
  7. import re
  8. import tasks
  9. afc_prefix = "wikipedia( talk)?:(wikiproject )?articles for creation"
  10. # compile some regexps used when finding specific events
  11. r_page = re.compile(afc_prefix)
  12. r_ffu = re.compile("wikipedia( talk)?:files for upload")
  13. r_move1 = re.compile("moved \[\[{}".format(afc_prefix))
  14. r_move2 = re.compile("moved \[\[(.*?)\]\] to \[\[{}".format(afc_prefix))
  15. r_moved_pages = re.compile("^moved \[\[(.*?)\]\] to \[\[(.*?)\]\]")
  16. r_delete = re.compile("deleted \"\[\[{}".format(afc_prefix))
  17. r_deleted_page = re.compile("^deleted \"\[\[(.*?)\]\]")
  18. r_restore = re.compile("restored \"\[\[{}".format(afc_prefix))
  19. r_restored_page = re.compile("^restored \"\[\[(.*?)\]\]")
  20. r_protect = re.compile("protected \"\[\[{}".format(afc_prefix))
  21. def process(rc):
  22. """Given an RC() object, return a list of channels to report this event to.
  23. Also, start any wiki bot tasks within this function if necessary."""
  24. chans = set() # channels to report this message to
  25. page_name = rc.page.lower()
  26. comment = rc.comment.lower()
  27. if "!earwigbot" in rc.msg.lower():
  28. chans.update(("##earwigbot", "#wikipedia-en-afc"))
  29. if r_page.search(page_name):
  30. tasks.start("afc_statistics", action="edit", page=rc.page)
  31. tasks.start("afc_copyvios", action="edit", page=rc.page)
  32. chans.add("#wikipedia-en-afc")
  33. elif r_ffu.match(page_name):
  34. chans.add("#wikipedia-en-afc")
  35. elif page_name.startswith("template:afc submission"):
  36. chans.add("#wikipedia-en-afc")
  37. elif rc.flags == "move" and (r_move1.match(comment) or
  38. r_move2.match(comment)):
  39. p = r_moved_pages.findall(rc.comment)[0]
  40. tasks.start("afc_statistics", action="move", page=p)
  41. tasks.start("afc_copyvios", action="move", page=p)
  42. chans.add("#wikipedia-en-afc")
  43. elif rc.flags == "delete" and r_delete.match(comment):
  44. p = r_deleted_page.findall(rc.comment)[0]
  45. tasks.start("afc_statistics", action="delete", page=p)
  46. tasks.start("afc_copyvios", action="delete", page=p)
  47. chans.add("#wikipedia-en-afc")
  48. elif rc.flags == "restore" and r_restore.match(comment):
  49. p = r_restored_page.findall(rc.comment)[0]
  50. tasks.start("afc_statistics", action="restore", page=p)
  51. tasks.start("afc_copyvios", action="restore", page=p)
  52. chans.add("#wikipedia-en-afc")
  53. elif rc.flags == "protect" and r_protect.match(comment):
  54. chans.add("#wikipedia-en-afc")
  55. return chans