diff options
author | Brian Sherson <caretaker82@euclid.shersonb.net> | 2013-12-04 01:35:44 -0800 |
---|---|---|
committer | Brian Sherson <caretaker82@euclid.shersonb.net> | 2013-12-04 01:35:44 -0800 |
commit | 0d802dab5b586d511a6291248702c910502acaf7 (patch) | |
tree | f370db15b1a29c2fa8b6699188d28923b1361462 /cannon.py | |
parent | 5cf8d2185f89aaf30e856bd0dbca88fbb51789ba (diff) |
Significant changes
Diffstat (limited to 'cannon.py')
-rw-r--r-- | cannon.py | 56 |
1 files changed, 27 insertions, 29 deletions
@@ -8,33 +8,31 @@ class Cannon(object): 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)) + def onChanMsg(self, IRC, user, channel, targetprefix, msg): + matches = re.findall("^!fire\\s+(.*)$", msg) + if matches: + nickname = matches[0] + if any([nickname.lower() == usr.nick.lower() for usr in channel.users]): + vic = IRC.user(nickname) + if vic in self.firecount.keys(): + count = self.firecount[vic]+1 else: - channel.msg("%s: I cannot fire %s out of a cannon, as he or she is not here."%(origin, nickname)) + count = 1 + self.firecount[vic] = 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." % + (vic.nick, count, ordinal)) + else: + channel.msg("%s: I cannot fire %s out of a cannon, as he or she is not here."%(user.nick, nickname)) + + def onSendChanMsg(self, IRC, origin, channel, targetprefix, msg): + self.onChanMsg(IRC, IRC.identity, channel, targetprefix, msg) |