diff --git a/arsenic.py b/arsenic.py index 8e95360..ba8ed2d 100755 --- a/arsenic.py +++ b/arsenic.py @@ -10,6 +10,7 @@ import re import os import time import socket +import rp def esc(arg): return "'" + arg.replace("'", r"'\''") + "'" @@ -21,7 +22,7 @@ class Arsenic(firebot.FireBot, ProcBot): debug = False bindings = [] ping_interval = 120 - chatty = False # #x can't play nice + chatty = True # Maybe #x can play nice now def __init__(self, *args, **kwargs): firebot.FireBot.__init__(self, *args, **kwargs) @@ -44,12 +45,16 @@ class Arsenic(firebot.FireBot, ProcBot): runcmd)) def rp(self, sender, forum, addl, match): - command = 'rp' - argstr = match.group('args') - Finger(('db.nic.lanl.gov', 5833), - argstr, - lambda l: self.proc_cb('%s: ' % command, sender, forum, l, 0)) - bindings.append((re.compile(r"^(?Prp) +(?P.*)$"), + long = match.group('long') and True + conn = rp.make_connection() + rows = rp.rp(match.group('args').strip(), conn=conn) + ret = rp.format(rows, long=long) + if long: + forum.msg('[Sending privately]') + self.despool(sender, ret) + else: + self.despool(forum, ret) + bindings.append((re.compile(r"^rp +(?P(-l|--long) +)?(?P.*)$"), rp)) def finger(self, sender, forum, addl, match): @@ -66,21 +71,6 @@ class Arsenic(firebot.FireBot, ProcBot): bindings.append((re.compile(r"^\008[,: ]+ (what is the )?(server )?lag"), lag)) - def note(self, sender, forum, addl, match): - whom = match.group('whom') - what = match.group('what') - when = time.time() - key = '\013notes:%s' % whom - note = (when, sender.name(), what) - try: - n = self.db[key] - except KeyError: - n = [] - n.append(note) - self.db[key] = n - forum.msg(self.gettext('okay', sender=sender.name())) - bindings.append((re.compile(r"^\008[:, ]+note (to )?(?P[^: ]+):? +(?P.*)"), - note)) bindings.extend(firebot.FireBot.bindings) @@ -142,8 +132,11 @@ class Arsenic(firebot.FireBot, ProcBot): if __name__ == '__main__': import daemon + import sys - debug = True + debug = False + if "-d" in sys.argv: + debug = True if not debug: # Become a daemon diff --git a/bindingsbot.py b/bindingsbot.py index 6e835a7..bf9fdf4 100644 --- a/bindingsbot.py +++ b/bindingsbot.py @@ -2,6 +2,7 @@ import irc import re import random import types +import os class Match: """A wrapper around a regex match, to replace \008 with a word. @@ -38,21 +39,17 @@ class BindingsBot(irc.Bot): """Save the traceback for later inspection""" irc.Bot.err(self, exception) t,v,tb = exception - tbinfo = [] + info = [] while 1: - tbinfo.append (( - tb.tb_frame.f_code.co_filename, - tb.tb_frame.f_code.co_name, - str(tb.tb_lineno) - )) + info.append('%s:%d(%s)' % (os.path.basename(tb.tb_frame.f_code.co_filename), + tb.tb_lineno, + tb.tb_frame.f_code.co_name)) tb = tb.tb_next if not tb: break - # just to be safe - del tb - file, function, line = tbinfo[-1] - info = '[' + '] ['.join(map(lambda x: '|'.join(x), tbinfo)) + ']' - self.last_tb = '%s %s %s' % (t, v, info) + del tb # just to be safe + infostr = '[' + '] ['.join(info) + ']' + self.last_tb = '%s %s %s' % (t, v, infostr) print self.last_tb def matches(self, text): diff --git a/infobot.py b/infobot.py index cf256fb..a29e4b7 100644 --- a/infobot.py +++ b/infobot.py @@ -169,14 +169,14 @@ 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) 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):