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.

71 lines
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # EarwigBot Configuration File
  3. # This file contains rules for the bot's watcher component.
  4. import re
  5. from wiki import task_manager
  6. # Define different report channels on our front-end server. They /must/ be in CHANS in config/irc.py or the bot will not be able to send messages to them (unless they have -n set).
  7. #AFC_CHANS = ["#wikipedia-en-afc"] # report recent AfC changes/give AfC status messages upon join
  8. AFC_CHANS = ["##earwigbot"] # report recent AfC changes/give AfC status messages upon join
  9. BOT_CHANS = ["##earwigbot", "#wikipedia-en-afc"] # report edits containing "!earwigbot"
  10. # Define some commonly used strings.
  11. afc_prefix = "wikipedia( talk)?:(wikiproject )?articles for creation"
  12. # Define our compiled regexps used when finding certain edits.
  13. r_page = re.compile(afc_prefix)
  14. r_ffu = re.compile("wikipedia( talk)?:files for upload")
  15. r_move1 = re.compile("moved \[\[{}".format(afc_prefix)) # an AFC page was either moved locally or out
  16. r_move2 = re.compile("moved \[\[(.*?)\]\] to \[\[{}".format(afc_prefix)) # an outside page was moved into AFC
  17. r_moved_pages = re.compile("^moved \[\[(.*?)\]\] to \[\[(.*?)\]\]")
  18. r_delete = re.compile("deleted \"\[\[{}".format(afc_prefix))
  19. r_deleted_page = re.compile("^deleted \"\[\[(.*?)\]\]")
  20. r_restore = re.compile("restored \"\[\[{}".format(afc_prefix))
  21. r_restored_page = re.compile("^restored \"\[\[(.*?)\]\]")
  22. r_protect = re.compile("protected \"\[\[{}".format(afc_prefix))
  23. def process(rc):
  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(BOT_CHANS)
  29. if r_page.search(page_name):
  30. task_manager.start_task("afc_statistics", action="process_edit", page=rc.page)
  31. task_manager.start_task("afc_copyvios", action="process_edit", page=rc.page)
  32. chans.update(AFC_CHANS)
  33. elif r_ffu.match(page_name):
  34. chans.update(AFC_CHANS)
  35. elif page_name.startswith("template:afc submission"):
  36. chans.update(AFC_CHANS)
  37. elif rc.flags == "move" and (r_move1.match(comment) or r_move2.match(comment)):
  38. p = r_moved_pages.findall(rc.comment)[0]
  39. task_manager.start_task("afc_statistics", action="process_move", pages=p)
  40. task_manager.start_task("afc_copyvios", action="process_move", pages=p)
  41. chans.update(AFC_CHANS)
  42. elif rc.flags == "delete" and r_delete.match(comment):
  43. p = r_deleted_page.findall(rc.comment)[0][0]
  44. task_manager.start_task("afc_statistics", action="process_delete", page=p)
  45. task_manager.start_task("afc_copyvios", action="process_delete", page=p)
  46. chans.update(AFC_CHANS)
  47. elif rc.flags == "delete" and r_restore.match(comment):
  48. p = r_restored_page.findall(rc.comment)[0][0]
  49. task_manager.start_task("afc_statistics", action="process_restore", page=p)
  50. task_manager.start_task("afc_copyvios", action="process_restore", page=p)
  51. chans.update(AFC_CHANS)
  52. elif rc.flags == "protect" and r_protect.match(comment):
  53. chans.update(AFC_CHANS)
  54. return chans