mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-08 18:44:06 +01:00
Added clear command.
This commit is contained in:
parent
4c58c3995a
commit
9a7c64a359
@ -187,6 +187,14 @@ class SqliteKarmaDB(object):
|
|||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
return [(name, int(i)) for (name, i) in cursor.fetchall()]
|
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():
|
def KarmaDB():
|
||||||
return SqliteKarmaDB()
|
return SqliteKarmaDB()
|
||||||
@ -276,6 +284,15 @@ class Karma(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
raise callbacks.ArgumentError
|
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):
|
def increaseKarma(self, irc, msg, match):
|
||||||
r"^(\S+)\+\+(|\s+)$"
|
r"^(\S+)\+\+(|\s+)$"
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
|
@ -179,6 +179,14 @@ if sqlite is not None:
|
|||||||
def testIncreaseKarmaWithNickNotCallingInvalidCommand(self):
|
def testIncreaseKarmaWithNickNotCallingInvalidCommand(self):
|
||||||
self.assertSnarfNoResponse('%s: foo++' % self.irc.nick, 3)
|
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:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user