mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 07:34:08 +01:00
Fixed bug #846220.
This commit is contained in:
parent
6f93426d66
commit
43c594661c
@ -34,6 +34,7 @@ Plugin for handling basic Karma stuff for a channel.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sets
|
||||||
from itertools import imap
|
from itertools import imap
|
||||||
|
|
||||||
import sqlite
|
import sqlite
|
||||||
@ -78,11 +79,13 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
|
|||||||
return db
|
return db
|
||||||
|
|
||||||
def karma(self, irc, msg, args):
|
def karma(self, irc, msg, args):
|
||||||
"""[<channel>] [<text>]
|
"""[<channel>] [<thing> [<thing> ...]]
|
||||||
|
|
||||||
Returns the karma of <text>. If <text> is not given, returns the top
|
Returns the karma of <text>. If <thing> is not given, returns the top
|
||||||
three and bottom three karmas. <channel> is only necessary if the
|
three and bottom three karmas. If one <thing> is given, returns the
|
||||||
message isn't sent on the channel itself.
|
details of its karma; if more than one <thing> is given, returns the
|
||||||
|
total karma of each of the the things. <channel> is only necessary if
|
||||||
|
the message isn't sent on the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
@ -104,15 +107,25 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
|
|||||||
subtracted, utils.pluralize(subtracted, 'time'), total)
|
subtracted, utils.pluralize(subtracted, 'time'), total)
|
||||||
irc.reply(msg, s)
|
irc.reply(msg, s)
|
||||||
elif len(args) > 1:
|
elif len(args) > 1:
|
||||||
normalizedArgs = imap(str.lower, args)
|
normalizedArgs = sets.Set(imap(str.lower, args))
|
||||||
criteria = ' OR '.join(['normalized=%s'] * len(args))
|
criteria = ' OR '.join(['normalized=%s'] * len(normalizedArgs))
|
||||||
sql = """SELECT name, added-subtracted
|
sql = """SELECT name, added-subtracted
|
||||||
FROM karma WHERE %s
|
FROM karma WHERE %s
|
||||||
ORDER BY added-subtracted DESC""" % criteria
|
ORDER BY added-subtracted DESC""" % criteria
|
||||||
cursor.execute(sql, *normalizedArgs)
|
cursor.execute(sql, *normalizedArgs)
|
||||||
if cursor.rowcount > 0:
|
if cursor.rowcount > 0:
|
||||||
s = utils.commaAndify(['%s: %s' % (n, t)
|
L = []
|
||||||
for (n,t) in cursor.fetchall()])
|
for (n, t) in cursor.fetchall():
|
||||||
|
L.append('%s: %s' % (n, t))
|
||||||
|
normalizedArgs.remove(n.lower())
|
||||||
|
if normalizedArgs:
|
||||||
|
if len(normalizedArgs) == 1:
|
||||||
|
L.append('%s has no karma' % normalizedArgs.pop())
|
||||||
|
else:
|
||||||
|
LL = list(normalizedArgs)
|
||||||
|
LL.sort()
|
||||||
|
L.append('%s have no karma' % utils.commaAndify(LL))
|
||||||
|
s = utils.commaAndify(L)
|
||||||
irc.reply(msg, s + '.')
|
irc.reply(msg, s + '.')
|
||||||
else:
|
else:
|
||||||
irc.reply(msg, 'I didn\'t know the karma for any '
|
irc.reply(msg, 'I didn\'t know the karma for any '
|
||||||
|
@ -60,6 +60,7 @@ if sqlite is not None:
|
|||||||
self.assertRegexp('karma FOO BAR FOOBAR', '.*foo.*foobar.*bar.*')
|
self.assertRegexp('karma FOO BAR FOOBAR', '.*foo.*foobar.*bar.*')
|
||||||
self.assertRegexp('karma FOO BAR FOOBAR',
|
self.assertRegexp('karma FOO BAR FOOBAR',
|
||||||
'.*FOO.*foobar.*BAR.*', flags=0)
|
'.*FOO.*foobar.*BAR.*', flags=0)
|
||||||
|
self.assertRegexp('karma foo bar foobar asdfjkl', 'asdfjkl')
|
||||||
# Test case-insensitive
|
# Test case-insensitive
|
||||||
self.assertNoResponse('MOO++', 2)
|
self.assertNoResponse('MOO++', 2)
|
||||||
self.assertRegexp('karma moo',
|
self.assertRegexp('karma moo',
|
||||||
|
Loading…
Reference in New Issue
Block a user