mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Added a scramble command and accompanying tests.
This commit is contained in:
parent
4c8bb936b8
commit
edab9e52b2
@ -480,7 +480,22 @@ class FunCommands(callbacks.Privmsg):
|
||||
"""
|
||||
irc.reply(msg, random.choice(self._eightballs))
|
||||
|
||||
_scrambleRe = re.compile(r'(?:\b|(?![a-zA-Z]))([a-zA-Z])([a-zA-Z]*)'\
|
||||
'([a-zA-Z])(?:\b|(?![a-zA-Z]))')
|
||||
def _subber(self, m):
|
||||
s = list(m.group(2))
|
||||
random.shuffle(s)
|
||||
return '%s%s%s' % (m.group(1), ''.join(s), m.group(3))
|
||||
|
||||
def scramble(self, irc, msg, args):
|
||||
"""<text>
|
||||
|
||||
Replies a string whose inner letters are randomly shuffled.
|
||||
"""
|
||||
text = privmsgs.getArgs(args)
|
||||
if text is not None:
|
||||
s = self._scrambleRe.sub(self._subber, text)
|
||||
irc.reply(msg, s)
|
||||
|
||||
Class = FunCommands
|
||||
|
||||
|
@ -77,5 +77,10 @@ class FunCommandsTest(PluginTestCase, PluginDocumentation):
|
||||
i = ord(c)
|
||||
self.assertResponse('ord %s' % utils.dqrepr(c), str(i))
|
||||
|
||||
def testScramble(self):
|
||||
s = 'the recalcitrant jamessan tests his scramble function'
|
||||
self.assertNotRegexp('scramble %s' % s, s)
|
||||
s = 'the recalc1trant jam3ssan tests his scramble fun><tion'
|
||||
self.assertNotRegexp('scramble %s' % s, s)
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user