From 1edd7fc379c440267d7b96f2b7b114fc01abea1c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 19 Jul 2014 14:20:04 +0000 Subject: [PATCH] Karma: Delete record instead of resetting it to zero, and make @clear able to delete all records at once. --- plugins/Karma/plugin.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/Karma/plugin.py b/plugins/Karma/plugin.py index 3e4370a4a..eb6c177aa 100644 --- a/plugins/Karma/plugin.py +++ b/plugins/Karma/plugin.py @@ -175,12 +175,15 @@ class SqliteKarmaDB(object): cursor.execute(sql) return [(name, int(i)) for (name, i) in cursor.fetchall()] - def clear(self, channel, name): + def clear(self, channel, name=None): db = self._getDb(channel) cursor = db.cursor() - normalized = name.lower() - cursor.execute("""UPDATE karma SET subtracted=0, added=0 - WHERE normalized=?""", (normalized,)) + if name: + normalized = name.lower() + cursor.execute("""DELETE FROM karma + WHERE normalized=?""", (normalized,)) + else: + cursor.execute("""DELETE FROM karma""") db.commit() def dump(self, channel, filename): @@ -362,13 +365,14 @@ class Karma(callbacks.Plugin): @internationalizeDocstring def clear(self, irc, msg, args, channel, name): - """[] + """[] [] - Resets the karma of to 0. + Resets the karma of to 0. If is not given, resets + everything. """ - self.db.clear(channel, name) + self.db.clear(channel, name or None) irc.replySuccess() - clear = wrap(clear, [('checkChannelCapability', 'op'), 'text']) + clear = wrap(clear, [('checkChannelCapability', 'op'), optional('text')]) @internationalizeDocstring def dump(self, irc, msg, args, channel, filename):