diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index 34c721098..c1bc16020 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -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): + """ + + 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 diff --git a/test/test_FunCommands.py b/test/test_FunCommands.py index c46df7db4..644e7eaf7 100644 --- a/test/test_FunCommands.py +++ b/test/test_FunCommands.py @@ -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>