From 88d896f783ae8dfaaa3b972bc1a66cd261c98635 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 12 Dec 2007 13:43:11 -0700 Subject: [PATCH] Including wii tracker --- arsenic.py | 5 +++-- firebot.py | 3 ++- gallium.py | 64 +++++++++++++++++++++++++++++++----------------------- infobot.py | 9 ++++++++ 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/arsenic.py b/arsenic.py index 55ef026..b62b908 100755 --- a/arsenic.py +++ b/arsenic.py @@ -33,8 +33,9 @@ class Arsenic(firebot.FireBot, ProcBot): def runcmd(self, sender, forum, addl, match): command = match.group('command') - args = lesc(match.group('args').split(' ')) + args = lesc(lesc(match.group('args').split(' '))) argstr = ' '.join(args) + print argstr Runner('%s %s' % (command, argstr), lambda l,r: self.proc_cb('%s: ' % command, sender, forum, l, r)) bindings.append((re.compile(r"^(?Pwhois) +(?P.*)$"), @@ -142,7 +143,7 @@ class Arsenic(firebot.FireBot, ProcBot): if __name__ == '__main__': import daemon - debug = False + debug = True if not debug: # Become a daemon diff --git a/firebot.py b/firebot.py index 9d6cf39..0448694 100755 --- a/firebot.py +++ b/firebot.py @@ -260,7 +260,8 @@ class FireBot(infobot.InfoBot, procbot.ProcBot): def generic_cmd(self, sender, forum, addl, match): cmd = match.group('cmd') args = match.group('args').split(' ') - argstr = ' '.join(procbot.lesc(args)) + args = procbot.lesc(args) + argstr = ' '.join(args) Runner('%s %s' % (cmd, argstr), lambda l,r: self.proc_cb(None, sender, forum, l, r)) bindings.append((re.compile(r"^(?Phost) (?P.+)$"), diff --git a/gallium.py b/gallium.py index a8341af..2b63fb0 100755 --- a/gallium.py +++ b/gallium.py @@ -6,14 +6,9 @@ import irc import re import os import random +import feedparser from procbot import ProcBot, Runner -def esc(arg): - return "'" + arg.replace("'", r"'\''") + "'" - -def lesc(args): - return [esc(arg) for arg in args] - class Gallium(firebot.FireBot, ProcBot): opall = False bindings = [] @@ -70,21 +65,36 @@ class Gallium(firebot.FireBot, ProcBot): bindings.append((re.compile(r"^u\+rand$"), randglyph)) - def runcmd(self, sender, forum, addl, match): - command = match.group('command') - args = match.group('args').split(' ') - args = [x.replace("'", "'\\''") for x in args] - argstr = ' '.join(args) - Runner('%s %s' % (command, argstr), - lambda l,r: self.proc_cb('%s: ' % command, sender, forum, l, r)) - bindings.append((re.compile(r"^(?Pwhois) +(?P.*)$"), - runcmd)) - bindings.append((re.compile(r"^(?Phost) +(?P.*)$"), - runcmd)) - bindings.extend(firebot.FireBot.bindings) +class Wiibot(Gallium): + def __init__(self, *args, **kwargs): + Gallium.__init__(self, *args, **kwargs) + self.wiis = [] + self.add_timer(27, self.check_wiis) + + def check_wiis(self): + d = feedparser.parse('http://www.wiitracker.com/rss.xml') + try: + nt = [] + for e in d.entries: + t = e.title + if 'no stock at this time' not in t: + nt.append(t) + if self.wiis != nt: + if nt: + for t in nt: + self.announce('[wii] ' + t) + else: + self.announce('[wii] No more wiis') + self.wiis = nt + except: + pass + + self.add_timer(27, self.check_wiis) + + if __name__ == '__main__': import shorturl import socket @@ -106,19 +116,19 @@ if __name__ == '__main__': us.getsockname()[1]) # gallium - gallium = Gallium(('fozzie.woozle.org', 6667), - ['gallium'], - "I'm a little printf, short and stdout", - ["#woozle", "#gallium"]) + gallium = Wiibot(('localhost', 6667), + ['gallium'], + "I'm a little printf, short and stdout", + ["#woozle", "#gallium"]) gallium.shorturlnotice = False gallium.debug = debug # fink - fink = Gallium(('irc.oftc.net', 6667), - ['fink'], - "Do you like my hat?", - ["#fast-food"], - dbname='fink.cdb') + fink = Wiibot(('irc.oftc.net', 6667), + ['fink'], + "Do you like my hat?", + ["#fast-food"], + dbname='fink.cdb') fink.debug = debug irc.run_forever(0.5) diff --git a/infobot.py b/infobot.py index b261eb3..cf256fb 100644 --- a/infobot.py +++ b/infobot.py @@ -169,6 +169,15 @@ class InfoBot(BindingsBot): bindings.append((re.compile(r"^\008[,: ]+unlock (?P.+)$", re.IGNORECASE), unlock_entry)) + def forget_and_lock(self, sender, forum, addl, match): + key = match.group('key') + self.unlock(key) + self.delete(key) + self.lock(key) + forum.msg(self.gettext('okay', key=key, sender=sender.name())) + bindings.append((re.compile(r"^\008[,: ]+forget and lock (?P.+)$", re.IGNORECASE), + forget_and_lock)) + # Literal entry def literal(self, sender, forum, addl, match): key = match.group('key')