mirror of https://github.com/Mikaela/Limnoria.git
Fixed bugs, added tests, etc.
This commit is contained in:
parent
9a43f04248
commit
1979f5ad35
|
@ -28,6 +28,7 @@
|
||||||
###
|
###
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import math
|
||||||
import types
|
import types
|
||||||
|
|
||||||
import supybot.log as log
|
import supybot.log as log
|
||||||
|
@ -274,6 +275,7 @@ class ChannelStats(callbacks.Plugin):
|
||||||
stats = wrap(stats, ['channeldb', additional('something')])
|
stats = wrap(stats, ['channeldb', additional('something')])
|
||||||
|
|
||||||
_env = {'__builtins__': types.ModuleType('__builtins__')}
|
_env = {'__builtins__': types.ModuleType('__builtins__')}
|
||||||
|
_env.update(math.__dict__)
|
||||||
def rank(self, irc, msg, args, channel, expr):
|
def rank(self, irc, msg, args, channel, expr):
|
||||||
"""[<channel>] <stat expression>
|
"""[<channel>] <stat expression>
|
||||||
|
|
||||||
|
@ -288,11 +290,9 @@ class ChannelStats(callbacks.Plugin):
|
||||||
if expr != expr.translate(utils.str.chars, '_[]'):
|
if expr != expr.translate(utils.str.chars, '_[]'):
|
||||||
irc.error('There\'s really no reason why you should have '
|
irc.error('There\'s really no reason why you should have '
|
||||||
'underscores or brackets in your mathematical '
|
'underscores or brackets in your mathematical '
|
||||||
'expression. Please remove them.')
|
'expression. Please remove them.', Raise=True)
|
||||||
return
|
|
||||||
if 'lambda' in expr:
|
if 'lambda' in expr:
|
||||||
irc.error('You can\'t use lambda in this command.')
|
irc.error('You can\'t use lambda in this command.', Raise=True)
|
||||||
return
|
|
||||||
expr = expr.lower()
|
expr = expr.lower()
|
||||||
users = []
|
users = []
|
||||||
for ((c, id), stats) in self.db.items():
|
for ((c, id), stats) in self.db.items():
|
||||||
|
@ -305,11 +305,9 @@ class ChannelStats(callbacks.Plugin):
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
v = float('inf')
|
v = float('inf')
|
||||||
except NameError, e:
|
except NameError, e:
|
||||||
irc.error('You referenced an invalid stat variable:',
|
irc.errorInvalid('stat variable', str(e).split()[1])
|
||||||
str(e).split()[1], Raise=True)
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
irc.error(utils.exnToString(e), Raise=True)
|
irc.error(utils.exnToString(e), Raise=True)
|
||||||
else:
|
|
||||||
users.append((v, ircdb.users.getUser(id).name))
|
users.append((v, ircdb.users.getUser(id).name))
|
||||||
users.sort()
|
users.sort()
|
||||||
users.reverse()
|
users.reverse()
|
||||||
|
|
|
@ -83,8 +83,9 @@ class ChannelStatsTestCase(ChannelPluginTestCase):
|
||||||
self.assertNotError('channelstats stats %s' % self.nick)
|
self.assertNotError('channelstats stats %s' % self.nick)
|
||||||
self.assertNotError('channelstats stats %s' % self.nick.upper())
|
self.assertNotError('channelstats stats %s' % self.nick.upper())
|
||||||
self.assertNotError('channelstats stats')
|
self.assertNotError('channelstats stats')
|
||||||
|
|
||||||
self.assertNotError('channelstats rank chars / msgs')
|
self.assertNotError('channelstats rank chars / msgs')
|
||||||
|
self.assertNotError('channelstats rank kicks/kicked') # Tests inf
|
||||||
|
self.assertNotError('channelstats rank log(msgs)')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
|
Loading…
Reference in New Issue