mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Made karma return the highest/lowest karmas when given no arguments.
This commit is contained in:
parent
577e7517af
commit
98b0acb942
@ -286,26 +286,40 @@ class ChannelDB(callbacks.PrivmsgCommandAndRegexp, ChannelDBHandler):
|
|||||||
message isn't sent on the channel itself.
|
message isn't sent on the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT added, subtracted
|
if name:
|
||||||
FROM karma
|
cursor.execute("""SELECT added, subtracted
|
||||||
WHERE name=%s""", name)
|
FROM karma
|
||||||
if cursor.rowcount == 0:
|
WHERE name=%s""", name)
|
||||||
irc.reply(msg, '%s has no karma.' % name)
|
if cursor.rowcount == 0:
|
||||||
else:
|
irc.reply(msg, '%s has no karma.' % name)
|
||||||
(added, subtracted) = map(int, cursor.fetchone())
|
else:
|
||||||
total = added - subtracted
|
(added, subtracted) = map(int, cursor.fetchone())
|
||||||
irc.reply(msg, '%s\'s karma has been increased %s %s ' \
|
total = added - subtracted
|
||||||
'and decreased %s %s for a total karma of %s.' % \
|
s = 'Karma for %r has been increased %s %s ' \
|
||||||
(name, added, added == 1 and 'time' or 'times',
|
'and decreased %s %s for a total karma of %s.' % \
|
||||||
subtracted, subtracted == 1 and 'time' or 'times',
|
(name, added, added == 1 and 'time' or 'times',
|
||||||
total))
|
subtracted, subtracted == 1 and 'time' or 'times', total)
|
||||||
|
irc.reply(msg, s)
|
||||||
|
else: # No name was given. Return the top/bottom 3 karmas.
|
||||||
|
cursor.execute("""SELECT name, added-subtracted
|
||||||
|
FROM karma
|
||||||
|
ORDER BY added-subtracted DESC
|
||||||
|
LIMIT 3""")
|
||||||
|
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""")
|
||||||
|
lowest = ['%r (%s)' % (t[0], t[1]) for t in cursor.fetchall()]
|
||||||
|
s = 'Highest karma: %s. Lowest karma: %s.' % \
|
||||||
|
(utils.commaAndify(highest), utils.commaAndify(lowest))
|
||||||
|
irc.reply(msg, s)
|
||||||
|
|
||||||
def increaseKarma(self, irc, msg, match):
|
def increaseKarma(self, irc, msg, match):
|
||||||
r"^(.)(.*)\+\+$"
|
r"^(.)(.*)\+\+$"
|
||||||
debug.printf('increaseKarma')
|
|
||||||
(first, rest) = match.groups()
|
(first, rest) = match.groups()
|
||||||
if first in conf.prefixChars:
|
if first in conf.prefixChars:
|
||||||
name = rest
|
name = rest
|
||||||
@ -318,7 +332,6 @@ class ChannelDB(callbacks.PrivmsgCommandAndRegexp, ChannelDBHandler):
|
|||||||
|
|
||||||
def decreaseKarma(self, irc, msg, match):
|
def decreaseKarma(self, irc, msg, match):
|
||||||
r"^(.)(.*)--$"
|
r"^(.)(.*)--$"
|
||||||
debug.printf('decreaseKarma')
|
|
||||||
(first, rest) = match.groups()
|
(first, rest) = match.groups()
|
||||||
if first in conf.prefixChars:
|
if first in conf.prefixChars:
|
||||||
name = rest
|
name = rest
|
||||||
|
Loading…
Reference in New Issue
Block a user