summaryrefslogtreecommitdiff
path: root/sedbot.py
diff options
context:
space:
mode:
authorBrian Sherson <caretaker82@euclid.shersonb.net>2013-06-03 19:14:03 -0700
committerBrian Sherson <caretaker82@euclid.shersonb.net>2013-06-03 19:14:03 -0700
commitfc456d6660162f7ad3a278d00288865175b30281 (patch)
treee1694c8264089e857b7f28347a42125fb3a03389 /sedbot.py
parentad52f837364cbe239ee55c5f5d69b8adb048d551 (diff)
Long-needed update
Diffstat (limited to 'sedbot.py')
-rw-r--r--sedbot.py87
1 files changed, 41 insertions, 46 deletions
diff --git a/sedbot.py b/sedbot.py
index 962526e..fe34da4 100644
--- a/sedbot.py
+++ b/sedbot.py
@@ -9,61 +9,56 @@ class SED(object):
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]<time.time()-1800: del self.history[0]
+ self.replace(IRC, *data)
def onSend(self, IRC, line, data, origin):
if origin==self: return
#print data
(cmd, target, params, extinfo)=data
- if len(target) and target[0]=="#": target=IRC.channel(target)
- if cmd=="PRIVMSG":
+ self.replace(IRC, IRC.identity.nick, IRC.identity.idnt, IRC.identity.host, *data)
+ def replace(self, IRC, origin, ident, host, cmd, target, params, extinfo):
+ if len(target) and target[0]=="#" and cmd=="PRIVMSG":
+ target=IRC.channel(target)
matches=re.findall(self.pattern,extinfo)
- #print matches
if matches:
separator, find, replace, flags=matches[0]
- find=re.sub("\\\\(.)","\\1",find)
- replace=re.sub("\\\\(.)","\\1",replace)
+ #print matches
+ find=re.sub("\\\\([,/#\\\\])","\\1",find)
+ replace=re.sub("\\\\(,/#\\\\)","\\1",replace)
+ #print find, replace
match=False
+ #print self.history
+ #print find
+ #print replace
for t, IRC2, (origin2, ident2, host2, cmd2, target2, params2, extinfo2) in self.history.__reversed__():
- #print target
- #print target2
- #print IRC2.channel(target2)
- 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)
- #print sub
- 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
+ #print target, target2, origin2, extinfo2
+ if target!=target2: continue
+ action=re.findall("^\x01ACTION\\s+(.*)\x01$", extinfo2)
+ #print action
+ if action:
+ try:
+ if re.findall(find, action[0]):
+ sub=re.sub(find, replace, action[0], flags=re.I if "i" in flags else 0)
+ target.msg("What %s really meant was: *%s %s" % (origin2, origin2, sub), origin=self)
+ match=True
+ break
+ except:
+ target.msg("%s: Invalid syntax" % (origin), origin=self)
+ raise
+ else:
+ 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" % (IRC.identity.nick, find), origin=self)
+ 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, (IRC.identity.nick, IRC.identity.idnt, IRC.identity.host)+data))
+ #print "History",(origin, ident, host, cmd, target, params, extinfo)
+ self.history.append((time.time(), IRC, (origin, ident, host, cmd, target, params, extinfo)))
+ #print self.history
while len(self.history) and self.history[0][0]<time.time()-1800: del self.history[0]
+ #print self.history