diff options
author | Brian Sherson <caretaker82@euclid.shersonb.net> | 2013-08-27 23:47:24 -0700 |
---|---|---|
committer | Brian Sherson <caretaker82@euclid.shersonb.net> | 2013-08-27 23:47:24 -0700 |
commit | 2011bf9bbd042bba4a649f9e52a52c1149ff09c8 (patch) | |
tree | 5e2a4b26105a13a7c4ee383870516bd03d489651 /cannon.py | |
parent | 7a015d666c81f5dd44507b69728e774c15c72f6d (diff) |
Diffstat (limited to 'cannon.py')
-rw-r--r-- | cannon.py | 62 |
1 files changed, 36 insertions, 26 deletions
@@ -1,30 +1,40 @@ #!/usr/bin/python -import re, os +import re +import 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)) + def __init__(self): + self.firecount = {} + + def onRecv(self, IRC, line, data): + if data is 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)) |