Pārlūkot izejas kodu

work in RC class: adding (somewhat basic) color to get_pretty, some other minor changes

tags/v0.1
Ben Kurtovic pirms 13 gadiem
vecāks
revīzija
e6c98ac30b
2 mainītis faili ar 27 papildinājumiem un 4 dzēšanām
  1. +1
    -0
      config/watcher.py
  2. +26
    -4
      irc/rc.py

+ 1
- 0
config/watcher.py Parādīt failu

@@ -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"



+ 26
- 4
irc/rc.py Parādīt failu

@@ -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 <event>:" 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

Notiek ielāde…
Atcelt
Saglabāt