mirror of https://github.com/Mikaela/Limnoria.git
Fixed a few bugs in the new rank command.
This commit is contained in:
parent
479c11e71b
commit
8fefeaa11f
|
@ -43,8 +43,8 @@ import supybot.ircutils as ircutils
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
class ChannelStat(irclib.IrcCommandDispatcher):
|
class ChannelStat(irclib.IrcCommandDispatcher):
|
||||||
self._values = ['actions', 'chars', 'frowns', 'joins', 'kicks','modes',
|
_values = ['actions', 'chars', 'frowns', 'joins', 'kicks','modes',
|
||||||
'msgs', 'parts', 'quits', 'smileys', 'topics', 'words']
|
'msgs', 'parts', 'quits', 'smileys', 'topics', 'words']
|
||||||
def __init__(self, actions=0, chars=0, frowns=0, joins=0, kicks=0, modes=0,
|
def __init__(self, actions=0, chars=0, frowns=0, joins=0, kicks=0, modes=0,
|
||||||
msgs=0, parts=0, quits=0, smileys=0, topics=0, words=0):
|
msgs=0, parts=0, quits=0, smileys=0, topics=0, words=0):
|
||||||
self.actions = actions
|
self.actions = actions
|
||||||
|
@ -278,10 +278,10 @@ class ChannelStats(callbacks.Plugin):
|
||||||
"""[<channel>] <stat expression>
|
"""[<channel>] <stat expression>
|
||||||
|
|
||||||
Returns the ranking of users according to the given stat expression.
|
Returns the ranking of users according to the given stat expression.
|
||||||
Valid variables in the stat expression include 'chars', 'words',
|
Valid variables in the stat expression include 'msgs', 'chars',
|
||||||
'smileys', 'frowns', 'actions', 'joins', 'parts', 'quits', 'kicks',
|
'words', 'smileys', 'frowns', 'actions', 'joins', 'parts', 'quits',
|
||||||
'kicked', 'topics', and 'modes'. Any simple mathematical expression
|
'kicks', 'kicked', 'topics', and 'modes'. Any simple mathematical
|
||||||
involving those variables is permitted.
|
expression involving those variables is permitted.
|
||||||
"""
|
"""
|
||||||
# XXX I could do this the right way, and abstract out a safe eval,
|
# XXX I could do this the right way, and abstract out a safe eval,
|
||||||
# or I could just copy/paste from the Math plugin.
|
# or I could just copy/paste from the Math plugin.
|
||||||
|
@ -302,15 +302,19 @@ class ChannelStats(callbacks.Plugin):
|
||||||
e[attr] = float(getattr(stats, attr))
|
e[attr] = float(getattr(stats, attr))
|
||||||
try:
|
try:
|
||||||
v = eval(expr, e, e)
|
v = eval(expr, e, e)
|
||||||
users.append((v, ircdb.users.getUser(id).name))
|
except ZeroDivisionError:
|
||||||
|
v = float('inf')
|
||||||
except NameError, e:
|
except NameError, e:
|
||||||
irc.error('You referenced an invalid stat variable:',
|
irc.error('You referenced an invalid stat variable:',
|
||||||
str(e).split()[1])
|
str(e).split()[1], raise=True)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
irc.error(utils.exnToString(e))
|
irc.error(utils.exnToString(e), raise=True)
|
||||||
|
finally:
|
||||||
|
users.append((v, ircdb.users.getUser(id).name))
|
||||||
users.sort()
|
users.sort()
|
||||||
users.reverse()
|
users.reverse()
|
||||||
s = utils.str.commaAndify(['%s (%.2f)' % (u, v) for (v, u) in users])
|
s = utils.str.commaAndify(['#%s %s (%.3g)' % (i, u, v)
|
||||||
|
for (i, (v, u)) in enumerate(users)])
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
rank = wrap(rank, ['channeldb', 'text'])
|
rank = wrap(rank, ['channeldb', 'text'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue