Updated to use commands.wrap.

This commit is contained in:
Jeremy Fincher 2004-10-26 23:22:02 +00:00
parent ba1bb34729
commit 114d625ff5

View File

@ -44,10 +44,10 @@ from itertools import imap
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins import supybot.plugins as plugins
import supybot.ircmsgs as ircmsgs import supybot.ircmsgs as ircmsgs
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
@ -276,7 +276,7 @@ class Karma(callbacks.Privmsg):
if thing[-2:] in ('++', '--'): if thing[-2:] in ('++', '--'):
self._doKarma(irc, channel, thing) self._doKarma(irc, channel, thing)
def karma(self, irc, msg, args): def karma(self, irc, msg, args, channel, things):
"""[<channel>] [<thing> [<thing> ...]] """[<channel>] [<thing> [<thing> ...]]
Returns the karma of <text>. If <thing> is not given, returns the top Returns the karma of <text>. If <thing> is not given, returns the top
@ -285,9 +285,8 @@ class Karma(callbacks.Privmsg):
total karma of each of the the things. <channel> is only necessary if total karma of each of the the things. <channel> is only necessary if
the message isn't sent on the channel itself. the message isn't sent on the channel itself.
""" """
channel = privmsgs.getChannel(msg, args) if len(things) == 1:
if len(args) == 1: name = things[0]
name = args[0]
t = self.db.get(channel, name) t = self.db.get(channel, name)
if t is None: if t is None:
irc.reply('%s has neutral karma.' % name) irc.reply('%s has neutral karma.' % name)
@ -302,8 +301,8 @@ class Karma(callbacks.Privmsg):
(utils.quoted(name), utils.nItems('time', added), (utils.quoted(name), utils.nItems('time', added),
utils.nItems('time', subtracted), total) utils.nItems('time', subtracted), total)
irc.reply(s) irc.reply(s)
elif len(args) > 1: elif len(things) > 1:
(L, neutrals) = self.db.gets(channel, args) (L, neutrals) = self.db.gets(channel, things)
if L: if L:
s = utils.commaAndify(['%s: %s' % t for t in L]) s = utils.commaAndify(['%s: %s' % t for t in L])
if neutrals: if neutrals:
@ -334,19 +333,16 @@ class Karma(callbacks.Privmsg):
s = 'Highest karma: %s. Lowest karma: %s.%s' % \ s = 'Highest karma: %s. Lowest karma: %s.%s' % \
(utils.commaAndify(highest), utils.commaAndify(lowest), rankS) (utils.commaAndify(highest), utils.commaAndify(lowest), rankS)
irc.reply(s) irc.reply(s)
karma = wrap(karma, ['channel', many('something')])
_mostAbbrev = utils.abbrev(['increased', 'decreased', 'active']) _mostAbbrev = utils.abbrev(['increased', 'decreased', 'active'])
def most(self, irc, msg, args): def most(self, irc, msg, args, channel, kind):
"""[<channel>] {increased,decreased,active} """[<channel>] {increased,decreased,active}
Returns the most increased, the most decreased, or the most active Returns the most increased, the most decreased, or the most active
(the sum of increased and decreased) karma things. <channel> is only (the sum of increased and decreased) karma things. <channel> is only
necessary if the message isn't sent in the channel itself. 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]
L = self.db.most(channel, kind, L = self.db.most(channel, kind,
self.registryValue('mostDisplay', channel)) self.registryValue('mostDisplay', channel))
if L: if L:
@ -354,18 +350,17 @@ class Karma(callbacks.Privmsg):
irc.reply(utils.commaAndify(L)) irc.reply(utils.commaAndify(L))
else: else:
irc.error('I have no karma for this channel.') irc.error('I have no karma for this channel.')
except (KeyError, ValueError): most = wrap(most, ['channel',
raise callbacks.ArgumentError ('literal', ['increased', 'decreased', 'active'])])
def clear(self, irc, msg, args, channel): def clear(self, irc, msg, args, channel, name):
"""[<channel>] <name> """[<channel>] <name>
Resets the karma of <name> to 0. Resets the karma of <name> to 0.
""" """
name = privmsgs.getArgs(args)
self.db.clear(channel, name) self.db.clear(channel, name)
irc.replySuccess() irc.replySuccess()
clear = privmsgs.checkChannelCapability(clear, 'op') clear = wrap(clear, [('checkChannelCapability', 'op'), 'text'])
def getName(self, nick, msg, match): def getName(self, nick, msg, match):
addressed = callbacks.addressed(nick, msg) addressed = callbacks.addressed(nick, msg)