Added a scramble command and accompanying tests.

This commit is contained in:
James Vega 2003-10-17 17:03:25 +00:00
parent 4c8bb936b8
commit edab9e52b2
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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: