From ad52f837364cbe239ee55c5f5d69b8adb048d551 Mon Sep 17 00:00:00 2001 From: Brian Sherson Date: Tue, 30 Apr 2013 19:16:41 -0700 Subject: First Commit\! --- sedbot.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 sedbot.py (limited to 'sedbot.py') diff --git a/sedbot.py b/sedbot.py new file mode 100644 index 0000000..962526e --- /dev/null +++ b/sedbot.py @@ -0,0 +1,69 @@ +#!/usr/bin/python +import os, re, time + +class SED(object): + def __init__(self): + self.__name__="SED Bot" + self.__version__="0.0.1" + self.history=[] + self.pattern=r"^!s([,/#])((?:.|\\\1)*)\1((?:.|\\\1)*)\1([ig]*)$" + def onRecv(self, IRC, line, data): + if data==None: return + (origin, ident, host, cmd, target, params, extinfo)=data + if len(target) and target[0]=="#": target=IRC.channel(target) + if cmd=="PRIVMSG": + matches=re.findall(self.pattern,extinfo) + if matches: + separator, find, replace, flags=matches[0] + find=re.sub("\\\\([,/#\\\\])","\\1",find) + replace=re.sub("\\\\(,/#\\\\)","\\1",replace) + match=False + for t, IRC2, (origin2, ident2, host2, cmd2, target2, params2, extinfo2) in self.history.__reversed__(): + if target!=IRC2.channel(target2): continue + try: + if re.findall(find, extinfo2): + sub=re.sub(find, replace, extinfo2, flags=re.I if "i" in flags else 0) + target.msg("What %s really meant to say was: %s" % (origin2, sub), origin=self) + match=True + break + except: + target.msg("%s: Invalid syntax" % (origin), origin=self) + raise + if not match: + target.msg("%s: I tried. I really tried! But I could not find the pattern: %s" % (origin, find), origin=self) + else: + self.history.append((time.time(), IRC, data)) + while len(self.history) and self.history[0][0]