Added clear command.

This commit is contained in:
Jeremy Fincher 2004-08-27 15:26:52 +00:00
parent 4c58c3995a
commit 9a7c64a359
2 changed files with 25 additions and 0 deletions

View File

@ -186,6 +186,14 @@ class SqliteKarmaDB(object):
cursor = db.cursor()
cursor.execute(sql)
return [(name, int(i)) for (name, i) in cursor.fetchall()]
def clear(self, channel, name):
db = self._getDb(channel)
cursor = db.cursor()
normalized = name.lower()
cursor.execute("""UPDATE karma SET subtracted=0, added=0
WHERE normalized=%s""", normalized)
db.commit()
def KarmaDB():
@ -276,6 +284,15 @@ class Karma(callbacks.PrivmsgCommandAndRegexp):
except (KeyError, ValueError):
raise callbacks.ArgumentError
def clear(self, irc, msg, args, channel):
"""[<channel>] <name>
Resets the karma of <name> to 0.
"""
name = privmsgs.getArgs(args)
self.db.clear(channel, name)
clear = privmsgs.checkChannelCapability(clear, 'op')
def increaseKarma(self, irc, msg, match):
r"^(\S+)\+\+(|\s+)$"
channel = msg.args[0]

View File

@ -179,6 +179,14 @@ if sqlite is not None:
def testIncreaseKarmaWithNickNotCallingInvalidCommand(self):
self.assertSnarfNoResponse('%s: foo++' % self.irc.nick, 3)
def testClear(self):
self.assertNoResponse('foo++', 1)
self.assertRegexp('karma foo', '1')
self.assertNotError('karma clear foo')
self.assertRegexp('karma foo', '0')
self.assertNotRegexp('karma foo', '1')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: