A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

13 лет назад
13 лет назад
13 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_copyvios", action="edit", page=rc.page)
  31. chans.add("#wikipedia-en-afc")
  32. elif r_ffu.match(page_name):
  33. chans.add("#wikipedia-en-afc")
  34. elif page_name.startswith("template:afc submission"):
  35. chans.add("#wikipedia-en-afc")
  36. elif rc.flags == "move" and (r_move1.match(comment) or
  37. r_move2.match(comment)):
  38. p = r_moved_pages.findall(rc.comment)[0]
  39. #tasks.start("afc_copyvios", action="move", page=p)
  40. chans.add("#wikipedia-en-afc")
  41. elif rc.flags == "delete" and r_delete.match(comment):
  42. p = r_deleted_page.findall(rc.comment)[0]
  43. #tasks.start("afc_copyvios", action="delete", page=p)
  44. chans.add("#wikipedia-en-afc")
  45. elif rc.flags == "restore" and r_restore.match(comment):
  46. p = r_restored_page.findall(rc.comment)[0]
  47. #tasks.start("afc_copyvios", action="restore", page=p)
  48. chans.add("#wikipedia-en-afc")
  49. elif rc.flags == "protect" and r_protect.match(comment):
  50. chans.add("#wikipedia-en-afc")
  51. return chans