mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +01:00
Added a configurable to determine the number of things shown in the ranking.
This commit is contained in:
parent
a63d175498
commit
4a6ac27406
@ -71,7 +71,10 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
1')"""),
|
||||
('karma-response', configurable.BoolType, False,
|
||||
"""Determines whether the bot will reply with a success message when
|
||||
something's karma is increased or decreased."""),]
|
||||
something's karma is increased or decreased."""),
|
||||
('karma-ranking-display', configurable.IntType, 3,
|
||||
"""Determines how many highest/lowest karma things are shown when
|
||||
karms is called with no arguments."""),]
|
||||
)
|
||||
def __init__(self):
|
||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||
@ -160,15 +163,16 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
||||
irc.reply(msg, 'I didn\'t know the karma for any '
|
||||
'of those things.')
|
||||
else: # No name was given. Return the top/bottom 3 karmas.
|
||||
limit = self.configurables.get('karma-ranking-display', channel)
|
||||
cursor.execute("""SELECT name, added-subtracted
|
||||
FROM karma
|
||||
ORDER BY added-subtracted DESC
|
||||
LIMIT 3""")
|
||||
LIMIT %s""", limit)
|
||||
highest = ['%r (%s)' % (t[0], t[1]) for t in cursor.fetchall()]
|
||||
cursor.execute("""SELECT name, added-subtracted
|
||||
FROM karma
|
||||
ORDER BY added-subtracted ASC
|
||||
LIMIT 3""")
|
||||
LIMIT %s""", limit)
|
||||
lowest = ['%r (%s)' % (t[0], t[1]) for t in cursor.fetchall()]
|
||||
if not (highest and lowest):
|
||||
irc.error(msg, 'I have no karma for this channel.')
|
||||
|
@ -68,6 +68,32 @@ if sqlite is not None:
|
||||
self.assertRegexp('karma MoO',
|
||||
'Karma for \'MoO\'.*increased 1.*total.*1')
|
||||
|
||||
def testKarmaRankingDisplayConfigurable(self):
|
||||
self.assertNotError('karma config karma-response on')
|
||||
self.assertNotError('foo++')
|
||||
self.assertNotError('foo++')
|
||||
self.assertNotError('foo++')
|
||||
self.assertNotError('foo++')
|
||||
self.assertNotError('bar++')
|
||||
self.assertNotError('bar++')
|
||||
self.assertNotError('bar++')
|
||||
self.assertNotError('baz++')
|
||||
self.assertNotError('baz++')
|
||||
self.assertNotError('quux++')
|
||||
self.assertNotError('xuuq--')
|
||||
self.assertNotError('zab--')
|
||||
self.assertNotError('zab--')
|
||||
self.assertNotError('rab--')
|
||||
self.assertNotError('rab--')
|
||||
self.assertNotError('rab--')
|
||||
self.assertNotError('oof--')
|
||||
self.assertNotError('oof--')
|
||||
self.assertNotError('oof--')
|
||||
self.assertNotError('oof--')
|
||||
self.assertRegexp('karma', 'foo.*bar.*baz.*oof.*rab.*zab')
|
||||
self.assertNotError('karma config karma-ranking-display 4')
|
||||
self.assertRegexp('karma', 'foo.*bar.*baz.*quux')
|
||||
|
||||
def testMost(self):
|
||||
self.assertError('most increased')
|
||||
self.assertError('most decreased')
|
||||
|
Loading…
x
Reference in New Issue
Block a user