From c4374913472d08539d44c0d7ed3dbc04455370db Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 27 Mar 2008 17:01:51 -0600 Subject: [PATCH] Fix things that use Yahoo! --- firebot.py | 36 +++++++++++++++++++----------------- gallium.py | 39 ++++++++++++++++++++++++++++++++------- infobot.py | 12 +++++++----- 3 files changed, 58 insertions(+), 29 deletions(-) diff --git a/firebot.py b/firebot.py index 0448694..0e0aae0 100755 --- a/firebot.py +++ b/firebot.py @@ -69,19 +69,6 @@ class FireBot(infobot.InfoBot, procbot.ProcBot): self.add_timer(self.ping_interval, self.send_ping) - def note(self, sender, forum, addl, match): - whom = match.group('whom') - what = match.group('what') - when = time.time() - note = "%f:%s:%s" % (when, sender.name(), what) - n = self.getall(whom, special="note") - n.append(note) - self.set(whom, n, special="note") - forum.msg(self.gettext('okay', sender=sender.name())) - bindings.append((re.compile(r"^\008[:, ]+note (to )?(?P[^: ]+):? +(?P.*)"), - note)) - bindings.append((re.compile(r"^\008[:, ]+later tell (?P[^: ]+):? +(?P.*)"), - note)) def cmd_privmsg(self, sender, forum, addl): infobot.InfoBot.cmd_privmsg(self, sender, forum, addl) @@ -168,10 +155,25 @@ class FireBot(infobot.InfoBot, procbot.ProcBot): f = forum.notice else: f = forum.msg + return True f('http://%s:%d/%d' % (URLSERVER[0], URLSERVER[1], idx)) bindings.append((re.compile(r".*\b(?P\b[a-z]+://[-a-z0-9_=!?#$@~%&*+/:;.,\w]+[-a-z0-9_=#$@~%&*+/\w])"), shorturl)) + def note(self, sender, forum, addl, match): + whom = match.group('whom') + what = match.group('what') + when = time.time() + note = "%f:%s:%s" % (when, sender.name(), what) + n = self.getall(whom, special="note") + n.append(note) + self.set(whom, n, special="note") + forum.msg(self.gettext('okay', sender=sender.name())) + bindings.append((re.compile(r"^\008[:, ]+note (to )?(?P[^: ]+):? +(?P.*)"), + note)) + bindings.append((re.compile(r"^\008[:, ]+later tell (?P[^: ]+):? +(?P.*)"), + note)) + def cdecl(self, sender, forum, addl, match): jibberish = match.group('jibberish') o, i = os.popen2('/usr/bin/cdecl') @@ -325,9 +327,9 @@ class FireBot(infobot.InfoBot, procbot.ProcBot): d) symbol = match.group('symbol') - WebRetriever('http://quote.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' % symbol, + WebRetriever('http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' % symbol, cb) - bindings.append((re.compile(r"^quote +(?P[.a-zA-Z]+)$"), + bindings.append((re.compile(r"^quote +(?P[-.a-zA-Z]+)$"), quote)) def currency(self, sender, forum, addl, match): @@ -352,7 +354,7 @@ class FireBot(infobot.InfoBot, procbot.ProcBot): forum.msg(('%0.4f %s = %0.4f %s') % (amt, frm, ans, to)) - WebRetriever(('http://quote.yahoo.com/d/quotes.csv?s=%s%s%%3DX&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' % + WebRetriever(('http://download.finance.yahoo.com/d/quotes.csv?s=%s%s%%3DX&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' % (frm, to)), cb) bindings.append((re.compile(r"^how much is (?P[0-9.]+) ?(?P[A-Z]{3}) in (?P[A-Z]{3})\??$"), @@ -377,7 +379,7 @@ class FireBot(infobot.InfoBot, procbot.ProcBot): else: amt = -1 self.whuffie_mod(nick, amt) - bindings.append((re.compile(r"^(?P\w+)(?P\+\+|\-\-)[? ]*$"), + bindings.append((re.compile(r"^(?P[-\w]+)(?P\+\+|\-\-)[? ]*$"), whuffie_modify)) msg_cat['whuffie whore'] = ("Nothing happens.", 'A hollow voice says, "Fool."') diff --git a/gallium.py b/gallium.py index 2b63fb0..0250f16 100755 --- a/gallium.py +++ b/gallium.py @@ -65,14 +65,34 @@ class Gallium(firebot.FireBot, ProcBot): bindings.append((re.compile(r"^u\+rand$"), randglyph)) + def rollthebones(self, sender, forum, addl, match): + what = match.group(0) + howmany = int(match.group(1)) + sides = int(match.group(2)) + mult = int(match.group(4) or 1) + dice = [] + acc = 0 + for i in range(howmany): + j = random.randint(1, sides) + dice.append(j) + acc += j + acc *= mult + if howmany > 1: + forum.msg('%s: %d %r' % (what, acc, dice)) + else: + forum.msg('%s: %d' % (what, acc)) + bindings.append((re.compile(r'\b([1-9][0-9]*)d([1-9][0-9]*)(x([1-9][0-9]*))?\b'), + rollthebones)) + 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) + self.add_timer(30, self.check_wiis) def check_wiis(self): d = feedparser.parse('http://www.wiitracker.com/rss.xml') @@ -81,7 +101,12 @@ class Wiibot(Gallium): for e in d.entries: t = e.title if 'no stock at this time' not in t: - nt.append(t) + try: + price = int(t[-3:]) + except: + price = 1 + if price < 450: + nt.append(t) if self.wiis != nt: if nt: for t in nt: @@ -92,7 +117,7 @@ class Wiibot(Gallium): except: pass - self.add_timer(27, self.check_wiis) + self.add_timer(23, self.check_wiis) if __name__ == '__main__': @@ -116,10 +141,10 @@ if __name__ == '__main__': us.getsockname()[1]) # gallium - gallium = Wiibot(('localhost', 6667), - ['gallium'], - "I'm a little printf, short and stdout", - ["#woozle", "#gallium"]) + gallium = Gallium(('localhost', 6667), + ['gallium'], + "I'm a little printf, short and stdout", + ["#woozle", "#gallium"]) gallium.shorturlnotice = False gallium.debug = debug diff --git a/infobot.py b/infobot.py index cf256fb..a0f780e 100644 --- a/infobot.py +++ b/infobot.py @@ -169,14 +169,16 @@ class InfoBot(BindingsBot): bindings.append((re.compile(r"^\008[,: ]+unlock (?P.+)$", re.IGNORECASE), unlock_entry)) - def forget_and_lock(self, sender, forum, addl, match): + def obliterate(self, sender, forum, addl, match): key = match.group('key') - self.unlock(key) - self.delete(key) + try: + self.delete(key) + except KeyError: + pass 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)) + bindings.append((re.compile(r"^\008[,: ]+obliterate (?P.+)$", re.IGNORECASE), + obliterate)) # Literal entry def literal(self, sender, forum, addl, match):