mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Added most command.
This commit is contained in:
parent
b39e1237fc
commit
9264b635e2
@ -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
|
* Changed Lookup so added lookups are added in the Lookup plugin
|
||||||
itself so there's no dependency on Alias, and so loaded lookups
|
itself so there's no dependency on Alias, and so loaded lookups
|
||||||
can be seen via 'list Lookup'.
|
can be seen via 'list Lookup'.
|
||||||
|
@ -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 os
|
||||||
import sets
|
import sets
|
||||||
from itertools import imap
|
from itertools import imap
|
||||||
@ -40,7 +42,6 @@ from itertools import imap
|
|||||||
import sqlite
|
import sqlite
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
__revision__ = "$Id$"
|
|
||||||
|
|
||||||
import plugins
|
import plugins
|
||||||
import privmsgs
|
import privmsgs
|
||||||
@ -170,6 +171,41 @@ class Karma(callbacks.PrivmsgCommandAndRegexp,
|
|||||||
(utils.commaAndify(highest), utils.commaAndify(lowest))
|
(utils.commaAndify(highest), utils.commaAndify(lowest))
|
||||||
irc.reply(msg, s)
|
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):
|
def increaseKarma(self, irc, msg, match):
|
||||||
r"^(\S+)\+\+(|\s+)$"
|
r"^(\S+)\+\+(|\s+)$"
|
||||||
name = match.group(1)
|
name = match.group(1)
|
||||||
|
@ -68,6 +68,27 @@ if sqlite is not None:
|
|||||||
self.assertRegexp('karma MoO',
|
self.assertRegexp('karma MoO',
|
||||||
'Karma for \'MoO\'.*increased 1.*total.*1')
|
'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):
|
def testSimpleOutput(self):
|
||||||
self.assertNotError('karma config simple-output on')
|
self.assertNotError('karma config simple-output on')
|
||||||
self.assertNoResponse('foo++', 2)
|
self.assertNoResponse('foo++', 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user