thinking about new karma commands

This commit is contained in:
Mike Bloy 2010-11-23 22:05:03 -06:00
parent 120dcc9fda
commit 647a2edb5c
1 changed files with 23 additions and 2 deletions

View File

@ -36,9 +36,13 @@ class Karma(Module):
pattern = "(?:(\S+)|\((.+)\))"
karmapattern = pattern + '(\+\+|--|\+-|-\+)' + '(\s+|$)'
querypattern = '^rank\s+(.*)'
reportpattern = '^karma\s+report\s+(highest|lowest)'
statpattern = '^karma\s+stat\s+(.*)'
self.karmare = re.compile(karmapattern)
self.queryre = re.compile(querypattern)
self.reportre = re.compile(reportpattern)
self.statre = re.compile(statpattern)
def db_init(self):
# need to init the database if karma tables don't already exist
@ -67,11 +71,28 @@ class Karma(Module):
sql = 'INSERT INTO drbotzo_modules VALUES (?,?)'
conn.execute(sql, (self.__class__.__name__, 1))
conn.commit()
version = 1
except sqlite3.Error as e:
conn.rollback()
print("sqlite error: " + str(e))
raise
if (version < 2):
conn = self.get_db()
try:
conn.execute('''
CREATE VIEW karma_users AS
SELECT who, COUNT(NULLIF(delta, -1)) AS pos,
COUNT(NULLIF(delta, 1)) AS neg
FROM karma_log GROUP BY who''')
sql = 'UPDATE drbotzo_modules SET version = ? WHERE module = ?'
conn.execute(sql, (2, self.__class__.__name__))
conn.commit()
version = 2
except sqlite3.Error as e:
conn.rollback()
print("sqlite error: " + str(e))
raise
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
"""look for karma strings at the start of messages"""
@ -79,7 +100,7 @@ class Karma(Module):
return self.handle_karma_change(connection, nick, userhost, replypath, what)
elif (self.queryre.search(what)):
return self.handle_karma_query(connection, nick, userhost, replypath, what)
def handle_karma_change(self, connection, nick, userhost, replypath, what):
"""
handle the karma change and storage.