| @@ -19,8 +19,6 @@ REALNAME = "[[w:en:User:EarwigBot]]" | |||||
| # channels to join on main server's startup | # channels to join on main server's startup | ||||
| CHANS = ["##earwigbot", "##earwig", "#wikipedia-en-afc"] | CHANS = ["##earwigbot", "##earwig", "#wikipedia-en-afc"] | ||||
| AFC_CHANS = ["#wikipedia-en-afc"] # report recent AfC changes/give AfC status messages upon join | |||||
| BOT_CHANS = ["##earwigbot", "#wikipedia-en-afc"] # report edits containing "!earwigbot" | |||||
| # hardcoded hostnames of users with certain permissions | # hardcoded hostnames of users with certain permissions | ||||
| OWNERS = ["wikipedia/The-Earwig"] # can use owner-only commands (!restart and !git) | OWNERS = ["wikipedia/The-Earwig"] # can use owner-only commands (!restart and !git) | ||||
| @@ -0,0 +1,33 @@ | |||||
| # -*- coding: utf-8 -*- | |||||
| # EarwigBot Configuration File | |||||
| # This file contains rules for the bot's watcher component. | |||||
| import re | |||||
| AFC_CHANS = ["#wikipedia-en-afc"] # report recent AfC changes/give AfC status messages upon join | |||||
| BOT_CHANS = ["##earwigbot", "#wikipedia-en-afc"] # report edits containing "!earwigbot" | |||||
| def process(rc): | |||||
| chans = set() # channels to report this message to | |||||
| page_name = rc.page.lower() | |||||
| if "!earwigbot" in rc.msg.lower(): | |||||
| chans.update(BOT_CHANS) | |||||
| if re.match("wikipedia( talk)?:(wikiproject )?articles for creation", page_name): | |||||
| chans.update(AFC_CHANS) | |||||
| elif re.match("wikipedia( talk)?:files for upload", page_name): | |||||
| chans.update(AFC_CHANS) | |||||
| elif page_name.startswith("template:afc submission"): | |||||
| chans.update(AFC_CHANS) | |||||
| elif rc.flags == "delete" and re.match("deleted \"\[\[wikipedia( talk)?:(wikiproject )?articles for creation", rc.comment.lower()): | |||||
| chans.update(AFC_CHANS) | |||||
| elif rc.flags == "protect" and re.match("protected \"\[\[wikipedia( talk)?:(wikiproject )?articles for creation", rc.comment.lower()): | |||||
| chans.update(AFC_CHANS) | |||||
| return chans | |||||
| @@ -27,7 +27,7 @@ class RC: | |||||
| self.page, self.flags, self.url, self.user, self.comment = page, flags, url, user, comment | self.page, self.flags, self.url, self.user, self.comment = page, flags, url, user, comment | ||||
| def pretty(self): | |||||
| def get_pretty(self): | |||||
| """make a nice, colorful message from self.msg to send to the front-end""" | """make a nice, colorful message from self.msg to send to the front-end""" | ||||
| pretty = self.msg | pretty = self.msg | ||||
| return pretty | return pretty | ||||
| @@ -1,9 +1,8 @@ | |||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
| ## Imports | ## Imports | ||||
| import re | |||||
| from config.irc import * | from config.irc import * | ||||
| from config.watcher import * | |||||
| from irc.connection import Connection | from irc.connection import Connection | ||||
| from irc.rc import RC | from irc.rc import RC | ||||
| @@ -48,23 +47,11 @@ def main(connection, f_conn): | |||||
| if line[1] == "376": # Join the recent changes channel when we've finished starting up | if line[1] == "376": # Join the recent changes channel when we've finished starting up | ||||
| connection.join(WATCHER_CHAN) | connection.join(WATCHER_CHAN) | ||||
| def report(msg, chans): | |||||
| """send a message to a list of report channels on our front-end server""" | |||||
| for chan in chans: | |||||
| frontend_conn.say(chan, msg) | |||||
| def check(rc): | def check(rc): | ||||
| """check if we're supposed to report this message anywhere""" | """check if we're supposed to report this message anywhere""" | ||||
| page_name = rc.page.lower() | |||||
| pretty_msg = rc.pretty() | |||||
| if "!earwigbot" in rc.msg.lower(): | |||||
| report(pretty_msg, chans=BOT_CHANS) | |||||
| if re.match("wikipedia( talk)?:(wikiproject )?articles for creation", page_name): | |||||
| report(pretty_msg, chans=AFC_CHANS) | |||||
| elif re.match("wikipedia( talk)?:files for upload", page_name): | |||||
| report(pretty_msg, chans=AFC_CHANS) | |||||
| elif page_name.startswith("template:afc submission"): | |||||
| report(pretty_msg, chans=AFC_CHANS) | |||||
| if rc.flags == "delete" and re.match("deleted \"\[\[wikipedia( talk)?:(wikiproject )?articles for creation", rc.comment.lower()): | |||||
| report(pretty_msg, chans=AFC_CHANS) | |||||
| results = process(rc) # process the message in config/watcher.py, and get a list of channels to send it to | |||||
| if not results: | |||||
| return | |||||
| pretty = rc.get_pretty() | |||||
| for chan in results: | |||||
| frontend_conn.say(chan, pretty) | |||||