From 88c849b5b3b3d03591f3aa12c3e6daa1ea744dbf Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Mon, 2 Feb 2015 07:36:48 -0800 Subject: Basic interface for generic data persistence. --- cannon.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'cannon.py') diff --git a/cannon.py b/cannon.py index 0911245..f88f54d 100644 --- a/cannon.py +++ b/cannon.py @@ -6,20 +6,23 @@ import os class Cannon(object): - def __init__(self): - self.firecount = {} + def onAddonAdd(self, context, **kwargs): + if not getattr(context.data, "cannon", None): + context.data.cannon = dict() def onChanMsg(self, context, user, channel, targetprefix, msg): + firecount = context.data.cannon + matches = re.findall("^!fire\\s+(.*)$", msg) if matches: nickname = matches[0] if any([nickname.lower() == usr.nick.lower() for usr in channel.users]): vic = context.user(nickname) - if vic in self.firecount.keys(): - count = self.firecount[vic] + 1 + if vic in firecount.keys(): + count = firecount[vic] + 1 else: count = 1 - self.firecount[vic] = count + firecount[vic] = count if 10 <= count % 100 < 20: ordinal = "th" elif count % 10 == 1: -- cgit v1.2.3