diff --git a/modules/Karma.py b/modules/Karma.py index d992112..a4f3457 100644 --- a/modules/Karma.py +++ b/modules/Karma.py @@ -102,6 +102,8 @@ class Karma(Module): return self.handle_karma_query(connection, nick, userhost, replypath, what) elif (self.statre.search(what)): return self.handle_stat_query(connection, nick, userhost, replypath, what) + elif (self.reportre.search(what)): + return self.handle_report_query(connection, nick, userhost, replypath, what) def handle_karma_change(self, connection, nick, userhost, replypath, what): """ @@ -137,7 +139,41 @@ class Karma(Module): except sqlite3.Error as e: conn.rollback() return self.reply(connection, replypath, "sqlite error: " + str(e)) - + + def handle_report_query(self, connection, nick, userhost, replypath, what): + match = self.reportre.search(what) + report = match.group(1) + + message = '{nick}: the desired report is not yet implemented'.format(nick=nick) + query = None + header = None + if (report == 'highest'): + query = 'SELECT key, value FROM karma_values ORDER BY value DESC LIMIT 5' + header = 'Top 5 karma recipients:' + elif (report == 'lowest'): + query = 'SELECT key, value FROM karma_values ORDER BY value ASC LIMIT 5' + header = 'Bottom 5 karma recipients:' + elif (report == 'positive'): + pass + elif (report == 'negative'): + pass + + if (query != None): + conn = self.get_db() + list = [] + try: + cursor = conn.execute(query) + result = cursor.fetchone() + while (result != None): + list.append("{key} ({value})".format(key=result[0], value=result[1])) + result = cursor.fetchone() + list = ', '.join(list) + message = '{header} {list}'.format(header=header, list=list) + except sqlite3.Error as e: + conn.rollback() + return self.reply(connection, replypath, "sqlite error: " + str(e)) + return self.reply(connection, replypath, message); + def handle_stat_query(self, connection, nick, userhost, replypath, what): match = self.statre.search(what) statnick = match.group(1)