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.

70 lines
3.0 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. BOT_CHANS = ["##earwigbot", "#wikipedia-en-afc"] # report edits containing "!earwigbot"
  9. # Define some commonly used strings.
  10. afc_prefix = "wikipedia( talk)?:(wikiproject )?articles for creation"
  11. # Define our compiled regexps used when finding certain edits.
  12. r_page = re.compile(afc_prefix)
  13. r_ffu = re.compile("wikipedia( talk)?:files for upload")
  14. r_move1 = re.compile("moved \[\[{}".format(afc_prefix)) # an AFC page was either moved locally or out
  15. r_move2 = re.compile("moved \[\[(.*?)\]\] to \[\[{}".format(afc_prefix)) # an outside page was moved into AFC
  16. r_moved_pages = re.compile("^moved \[\[(.*?)\]\] to \[\[(.*?)\]\]")
  17. r_delete = re.compile("deleted \"\[\[{}".format(afc_prefix))
  18. r_deleted_page = re.compile("^deleted \"\[\[(.*?)\]\]")
  19. r_restore = re.compile("restored \"\[\[{}".format(afc_prefix))
  20. r_restored_page = re.compile("^restored \"\[\[(.*?)\]\]")
  21. r_protect = re.compile("protected \"\[\[{}".format(afc_prefix))
  22. def process(rc):
  23. chans = set() # channels to report this message to
  24. page_name = rc.page.lower()
  25. comment = rc.comment.lower()
  26. if "!earwigbot" in rc.msg.lower():
  27. chans.update(BOT_CHANS)
  28. if r_page.search(page_name):
  29. task_manager.start_task("afc_statistics", action="process_edit", page=rc.page)
  30. task_manager.start_task("afc_copyvios", action="process_edit", page=rc.page)
  31. chans.update(AFC_CHANS)
  32. elif r_ffu.match(page_name):
  33. chans.update(AFC_CHANS)
  34. elif page_name.startswith("template:afc submission"):
  35. chans.update(AFC_CHANS)
  36. elif rc.flags == "move" and (r_move1.match(comment) or r_move2.match(comment)):
  37. p = r_moved_pages.findall(rc.comment)[0]
  38. task_manager.start_task("afc_statistics", action="process_move", pages=p)
  39. task_manager.start_task("afc_copyvios", action="process_move", pages=p)
  40. chans.update(AFC_CHANS)
  41. elif rc.flags == "delete" and r_delete.match(comment):
  42. p = r_deleted_page.findall(rc.comment)[0][0]
  43. task_manager.start_task("afc_statistics", action="process_delete", page=p)
  44. task_manager.start_task("afc_copyvios", action="process_delete", page=p)
  45. chans.update(AFC_CHANS)
  46. elif rc.flags == "restore" and r_restore.match(comment):
  47. p = r_restored_page.findall(rc.comment)[0][0]
  48. task_manager.start_task("afc_statistics", action="process_restore", page=p)
  49. task_manager.start_task("afc_copyvios", action="process_restore", page=p)
  50. chans.update(AFC_CHANS)
  51. elif rc.flags == "protect" and r_protect.match(comment):
  52. chans.update(AFC_CHANS)
  53. return chans