summaryrefslogtreecommitdiff
path: root/cannon.py
diff options
context:
space:
mode:
authorBrian Sherson <caretaker82@euclid.shersonb.net>2013-04-30 19:16:41 -0700
committerBrian Sherson <caretaker82@euclid.shersonb.net>2013-04-30 19:16:41 -0700
commitad52f837364cbe239ee55c5f5d69b8adb048d551 (patch)
tree40226974d78c847f8e2ab5dd8eb2fee307a616fd /cannon.py
First Commit\!
Diffstat (limited to 'cannon.py')
-rw-r--r--cannon.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/cannon.py b/cannon.py
new file mode 100644
index 0000000..3af725e
--- /dev/null
+++ b/cannon.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+
+import re, os
+
+class Cannon(object):
+ def __init__(self):
+ self.firecount={}
+ def onRecv(self, IRC, line, data):
+ if data==None: return
+ (origin, ident, host, cmd, target, params, extinfo)=data
+ if len(target) and target[0]=="#" and cmd=="PRIVMSG":
+ channel=IRC.channel(target)
+ matches=re.findall("^!fire\\s+(.*)$",extinfo)
+ if matches:
+ nickname=matches[0]
+ if any([nickname.lower()==user.nick.lower() for user in channel.users]):
+ user=IRC.user(nickname)
+ if user in self.firecount.keys():
+ count=self.firecount[user]+1
+ else:
+ count=1
+ self.firecount[user]=count
+ if 10<=count%100<20: ordinal="th"
+ elif count%10==1: ordinal="st"
+ elif count%10==2: ordinal="nd"
+ elif count%10==3: ordinal="rd"
+ else: ordinal="th"
+ channel.me("fires %s out of a cannon for the %d%s time."%(user.nick, count, ordinal))
+ else:
+ channel.msg("%s: I cannot fire %s out of a cannon, as he or she is not here."%(origin, nickname))