From e6c98ac30b8fb2f7a8ebc7bdbe7393d50f5bf3dd Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 25 Apr 2011 23:45:04 -0400 Subject: [PATCH] work in RC class: adding (somewhat basic) color to get_pretty, some other minor changes --- config/watcher.py | 1 + irc/rc.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/config/watcher.py b/config/watcher.py index 5830c99..875dbcf 100644 --- a/config/watcher.py +++ b/config/watcher.py @@ -5,6 +5,7 @@ import re +# 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). 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" diff --git a/irc/rc.py b/irc/rc.py index 109e77e..1dc6a6b 100644 --- a/irc/rc.py +++ b/irc/rc.py @@ -4,7 +4,7 @@ import re -class RC: +class RC(object): def __init__(self, msg): """store data on an individual event received from our IRC watcher""" self.msg = msg @@ -15,6 +15,7 @@ class RC: msg = re.sub("\x03([0-9]{1,2}(,[0-9]{1,2})?)?", "", msg) # strip IRC color codes; we don't want/need 'em msg = msg.strip() self.msg = msg + self.is_edit = True # page name of the modified page # 'M' for minor edit, 'B' for bot edit, 'create' for a user creation log entry... @@ -22,12 +23,33 @@ class RC: page, flags, url, user, comment = re.findall("\A\[\[(.*?)\]\]\s(.*?)\s(http://.*?)\s\*\s(.*?)\s\*\s(.*?)\Z", msg)[0] except IndexError: # we're probably missing the http:// part, because it's a log entry, which lacks a url page, flags, user, comment = re.findall("\A\[\[(.*?)\]\]\s(.*?)\s\*\s(.*?)\s\*\s(.*?)\Z", msg)[0] - url = "http://en.wikipedia.org/wiki/%s" % page + url = "http://en.wikipedia.org/wiki/{}".format(page) flags = flags.strip() # flag tends to have a extraneous whitespace character at the end when it's a log entry + self.is_edit = False # this is a log entry, not edit self.page, self.flags, self.url, self.user, self.comment = page, flags, url, user, comment def get_pretty(self): - """make a nice, colorful message from self.msg to send to the front-end""" - pretty = self.msg + """make a nice, colorful message from self.msg to send to the front-end""" + event_type = flags # "New :" if we don't know exactly what happened + if "N" in flags: + event_type = "page" # "New page:" + elif flags == "delete": + event_type = "deletion" # "New deletion:" + elif flags == "protect": + event_type = "protection" # "New protection:" + elif flags == "create": + event_type = "user" # "New user:" + else: + event_type = "edit" # "New edit:" + if "B" in flags: + event_type = "bot {}".format(event_type) # "New bot edit:" + if "M" in flags: + event_type = "minor {}".format(event_type) # "New minor edit:" OR "New minor bot edit:" + + if self.is_edit: + pretty = "\x02New {0}\x0F: \x0314[[\x0307{1}\x0314]]\x0306 *\x0303 {2}\x0306 *\x0302 {3}\x0306 *\x0310 {4}".format(event_type, page, user, url, comment) + else: + pretty = "\x02New {0}\x0F: \x0303{1}\x0306 *\x0302 {2}\x0306 *\x0310 {3}".format(event_type, user, url, comment) + return pretty