Added most command.

This commit is contained in:
Jeremy Fincher 2003-12-01 23:47:37 +00:00
parent b39e1237fc
commit 9264b635e2
3 changed files with 63 additions and 3 deletions

View File

@ -1,3 +1,6 @@
* Added Karma.most for determining various "mosts" in the Karma
database.
* Changed Lookup so added lookups are added in the Lookup plugin
itself so there's no dependency on Alias, and so loaded lookups
can be seen via 'list Lookup'.

View File

@ -30,9 +30,11 @@
###
"""
Plugin for handling basic Karma stuff for a channel.
Plugin for handling Karma stuff for a channel.
"""
__revision__ = "$Id$"
import os
import sets
from itertools import imap
@ -40,7 +42,6 @@ from itertools import imap
import sqlite
import utils
__revision__ = "$Id$"
import plugins
import privmsgs
@ -169,7 +170,42 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
s = 'Highest karma: %s. Lowest karma: %s.' % \
(utils.commaAndify(highest), utils.commaAndify(lowest))
irc.reply(msg, s)
_mostAbbrev = utils.abbrev(['increased', 'decreased', 'active'])
def most(self, irc, msg, args):
"""[<channel>] {increased,decreased,active}
Returns the most increased, the most decreased, or the most active
(the sum of increased and decreased) karma things. <channel> is only
necessary if the message isn't sent in the channel itself.
"""
channel = privmsgs.getChannel(msg, args)
kind = privmsgs.getArgs(args)
try:
kind = self._mostAbbrev[kind]
if kind == 'increased':
orderby = 'added'
elif kind == 'decreased':
orderby = 'subtracted'
elif kind == 'active':
orderby = 'added+subtracted'
else:
self.log.error('Impossible condition in most: kind=%s' % kind)
irc.error(msg, conf.replyPossibleBug)
return
sql = "SELECT name, %s FROM karma ORDER BY %s DESC LIMIT 50" % \
(orderby, orderby)
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute(sql)
L = ['%s: %s' % (name, i) for (name, i) in cursor.fetchall()]
if L:
irc.reply(msg, utils.commaAndify(L))
else:
irc.error(msg, 'I have no karma for this channel.')
except KeyError:
raise callbacks.ArgumentError
def increaseKarma(self, irc, msg, match):
r"^(\S+)\+\+(|\s+)$"
name = match.group(1)

View File

@ -68,6 +68,27 @@ if sqlite is not None:
self.assertRegexp('karma MoO',
'Karma for \'MoO\'.*increased 1.*total.*1')
def testMost(self):
self.assertError('most increased')
self.assertError('most decreased')
self.assertError('most active')
self.assertHelp('most aldsfkj')
self.assertNoResponse('foo++', 1)
self.assertNoResponse('foo++', 1)
self.assertNoResponse('bar++', 1)
self.assertNoResponse('bar--', 1)
self.assertNoResponse('bar--', 1)
self.assertRegexp('karma most active', 'bar.*foo')
self.assertRegexp('karma most increased', 'foo.*bar')
self.assertRegexp('karma most decreased', 'bar.*foo')
self.assertNoResponse('foo--', 1)
self.assertNoResponse('foo--', 1)
self.assertNoResponse('foo--', 1)
self.assertNoResponse('foo--', 1)
self.assertRegexp('karma most active', 'foo.*bar')
self.assertRegexp('karma most increased', 'foo.*bar')
self.assertRegexp('karma most decreased', 'foo.*bar')
def testSimpleOutput(self):
self.assertNotError('karma config simple-output on')
self.assertNoResponse('foo++', 2)