mirror of https://github.com/Mikaela/Limnoria.git
Utilities: add 'sample' command, a basic interface to random.sample()
Also add tests for it.
This commit is contained in:
parent
9d7287a436
commit
6381266cfd
|
@ -1,7 +1,7 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Supybot-fr\n"
|
"Project-Id-Version: Supybot-fr\n"
|
||||||
"POT-Creation-Date: 2010-10-20 09:39+CEST\n"
|
"POT-Creation-Date: 2011-02-20 11:27+CET\n"
|
||||||
"PO-Revision-Date: \n"
|
"PO-Revision-Date: \n"
|
||||||
"Last-Translator: Valentin Lorentz <progval@gmail.com>\n"
|
"Last-Translator: Valentin Lorentz <progval@gmail.com>\n"
|
||||||
"Language-Team: Supybot-fr <progval@gmail.com>\n"
|
"Language-Team: Supybot-fr <progval@gmail.com>\n"
|
||||||
|
@ -71,7 +71,7 @@ msgstr ""
|
||||||
msgid ""
|
msgid ""
|
||||||
"<arg> [<arg> ...]\n"
|
"<arg> [<arg> ...]\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Shuffles the arguments given it.\n"
|
" Shuffles the arguments given.\n"
|
||||||
" "
|
" "
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"<argument> [<argument> ...]\n"
|
"<argument> [<argument> ...]\n"
|
||||||
|
@ -80,6 +80,17 @@ msgstr ""
|
||||||
|
|
||||||
#: plugin.py:109
|
#: plugin.py:109
|
||||||
msgid ""
|
msgid ""
|
||||||
|
"<num> <arg> [<arg> ...]\n"
|
||||||
|
"\n"
|
||||||
|
" Randomly chooses <num> items out of the arguments given.\n"
|
||||||
|
" "
|
||||||
|
msgstr ""
|
||||||
|
"<nombre> <argument> [<argument> ...]\n"
|
||||||
|
"\n"
|
||||||
|
"Choisi de façon aléatoire un certain <nombre> d'<argument>s."
|
||||||
|
|
||||||
|
#: plugin.py:122
|
||||||
|
msgid ""
|
||||||
"<command> <text>\n"
|
"<command> <text>\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Tokenizes <text> and calls <command> with the resulting arguments.\n"
|
" Tokenizes <text> and calls <command> with the resulting arguments.\n"
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"POT-Creation-Date: 2010-10-20 09:39+CEST\n"
|
"POT-Creation-Date: 2011-02-20 11:27+CET\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -66,13 +66,22 @@ msgstr ""
|
||||||
msgid ""
|
msgid ""
|
||||||
"<arg> [<arg> ...]\n"
|
"<arg> [<arg> ...]\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Shuffles the arguments given it.\n"
|
" Shuffles the arguments given.\n"
|
||||||
" "
|
" "
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: plugin.py:109
|
#: plugin.py:109
|
||||||
#, docstring
|
#, docstring
|
||||||
msgid ""
|
msgid ""
|
||||||
|
"<num> <arg> [<arg> ...]\n"
|
||||||
|
"\n"
|
||||||
|
" Randomly chooses <num> items out of the arguments given.\n"
|
||||||
|
" "
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: plugin.py:122
|
||||||
|
#, docstring
|
||||||
|
msgid ""
|
||||||
"<command> <text>\n"
|
"<command> <text>\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Tokenizes <text> and calls <command> with the resulting arguments.\n"
|
" Tokenizes <text> and calls <command> with the resulting arguments.\n"
|
||||||
|
|
|
@ -98,12 +98,25 @@ class Utilities(callbacks.Plugin):
|
||||||
def shuffle(self, irc, msg, args, things):
|
def shuffle(self, irc, msg, args, things):
|
||||||
"""<arg> [<arg> ...]
|
"""<arg> [<arg> ...]
|
||||||
|
|
||||||
Shuffles the arguments given it.
|
Shuffles the arguments given.
|
||||||
"""
|
"""
|
||||||
random.shuffle(things)
|
random.shuffle(things)
|
||||||
irc.reply(' '.join(things))
|
irc.reply(' '.join(things))
|
||||||
shuffle = wrap(shuffle, [many('anything')])
|
shuffle = wrap(shuffle, [many('anything')])
|
||||||
|
|
||||||
|
@internationalizeDocstring
|
||||||
|
def sample(self, irc, msg, args, num, things):
|
||||||
|
"""<num> <arg> [<arg> ...]
|
||||||
|
|
||||||
|
Randomly chooses <num> items out of the arguments given.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
samp = random.sample(things, num)
|
||||||
|
irc.reply(' '.join(samp))
|
||||||
|
except ValueError, e:
|
||||||
|
irc.error('%s' % (e,))
|
||||||
|
sample = wrap(sample, ['positiveInt', many('anything')])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def apply(self, irc, msg, args, command, rest):
|
def apply(self, irc, msg, args, command, rest):
|
||||||
"""<command> <text>
|
"""<command> <text>
|
||||||
|
|
|
@ -59,4 +59,10 @@ class UtilitiesTestCase(PluginTestCase):
|
||||||
def testShuffle(self):
|
def testShuffle(self):
|
||||||
self.assertResponse('shuffle a', 'a')
|
self.assertResponse('shuffle a', 'a')
|
||||||
|
|
||||||
|
def testSample(self):
|
||||||
|
self.assertResponse('sample 1 a', 'a')
|
||||||
|
self.assertError('sample moo')
|
||||||
|
self.assertError('sample 5 moo')
|
||||||
|
self.assertRegexp('sample 2 a b c', '^[a-c] [a-c]$')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
|
Loading…
Reference in New Issue