mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-14 14:49:21 +01:00
Utilities: Use number comparison for integers and floats in @sort.
This commit is contained in:
parent
bfa45a6da8
commit
bfb305e2b8
@ -110,8 +110,10 @@ class Utilities(callbacks.Plugin):
|
||||
|
||||
Sorts the arguments given.
|
||||
"""
|
||||
irc.reply(' '.join(sorted(things)))
|
||||
sort = wrap(sort, [many('anything')])
|
||||
irc.reply(' '.join(map(str, sorted(things))))
|
||||
# Keep ints as ints, floats as floats, without comparing between numbers
|
||||
# and strings.
|
||||
sort = wrap(sort, [first(many(first('int', 'float')), many('anything'))])
|
||||
|
||||
@internationalizeDocstring
|
||||
def sample(self, irc, msg, args, num, things):
|
||||
@ -148,7 +150,7 @@ class Utilities(callbacks.Plugin):
|
||||
tokens = callbacks.tokenize(text)
|
||||
allTokens = commands + tokens
|
||||
self.Proxy(irc, msg, allTokens)
|
||||
apply = wrap(apply, ['something', many('anything')])
|
||||
apply = wrap(apply, ['something', many('something')])
|
||||
|
||||
|
||||
Class = Utilities
|
||||
|
@ -64,6 +64,8 @@ class UtilitiesTestCase(PluginTestCase):
|
||||
|
||||
def testSort(self):
|
||||
self.assertResponse('sort abc cab cba bca', 'abc bca cab cba')
|
||||
self.assertResponse('sort 2 12 42 7 2', '2 2 7 12 42')
|
||||
self.assertResponse('sort 2 8 12.2 12.11 42 7 2', '2 2 7 8 12.11 12.2 42')
|
||||
|
||||
def testSample(self):
|
||||
self.assertResponse('sample 1 a', 'a')
|
||||
|
@ -243,7 +243,7 @@ def _int(s):
|
||||
try:
|
||||
return int(s, base)
|
||||
except ValueError:
|
||||
if base == 10:
|
||||
if base == 10 and '.' not in s:
|
||||
try:
|
||||
return int(float(s))
|
||||
except OverflowError:
|
||||
|
Loading…
Reference in New Issue
Block a user