thinking about new karma commands
This commit is contained in:
parent
120dcc9fda
commit
647a2edb5c
|
@ -36,9 +36,13 @@ class Karma(Module):
|
||||||
pattern = "(?:(\S+)|\((.+)\))"
|
pattern = "(?:(\S+)|\((.+)\))"
|
||||||
karmapattern = pattern + '(\+\+|--|\+-|-\+)' + '(\s+|$)'
|
karmapattern = pattern + '(\+\+|--|\+-|-\+)' + '(\s+|$)'
|
||||||
querypattern = '^rank\s+(.*)'
|
querypattern = '^rank\s+(.*)'
|
||||||
|
reportpattern = '^karma\s+report\s+(highest|lowest)'
|
||||||
|
statpattern = '^karma\s+stat\s+(.*)'
|
||||||
|
|
||||||
self.karmare = re.compile(karmapattern)
|
self.karmare = re.compile(karmapattern)
|
||||||
self.queryre = re.compile(querypattern)
|
self.queryre = re.compile(querypattern)
|
||||||
|
self.reportre = re.compile(reportpattern)
|
||||||
|
self.statre = re.compile(statpattern)
|
||||||
|
|
||||||
def db_init(self):
|
def db_init(self):
|
||||||
# need to init the database if karma tables don't already exist
|
# 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 (?,?)'
|
sql = 'INSERT INTO drbotzo_modules VALUES (?,?)'
|
||||||
conn.execute(sql, (self.__class__.__name__, 1))
|
conn.execute(sql, (self.__class__.__name__, 1))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
version = 1
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
conn.rollback()
|
conn.rollback()
|
||||||
print("sqlite error: " + str(e))
|
print("sqlite error: " + str(e))
|
||||||
raise
|
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):
|
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||||
"""look for karma strings at the start of messages"""
|
"""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)
|
return self.handle_karma_change(connection, nick, userhost, replypath, what)
|
||||||
elif (self.queryre.search(what)):
|
elif (self.queryre.search(what)):
|
||||||
return self.handle_karma_query(connection, nick, userhost, replypath, what)
|
return self.handle_karma_query(connection, nick, userhost, replypath, what)
|
||||||
|
|
||||||
def handle_karma_change(self, connection, nick, userhost, replypath, what):
|
def handle_karma_change(self, connection, nick, userhost, replypath, what):
|
||||||
"""
|
"""
|
||||||
handle the karma change and storage.
|
handle the karma change and storage.
|
||||||
|
|
Loading…
Reference in New Issue