Added a colorize command

This commit is contained in:
James Vega 2003-11-07 18:49:26 +00:00
parent df88fc99d3
commit ca8ed7204b
2 changed files with 21 additions and 1 deletions

View File

@ -76,7 +76,8 @@ class Fun(callbacks.Privmsg):
return msg return msg
_filterCommands = ['jeffk', 'leet', 'rot13', 'hexlify', 'binary', 'lithp', _filterCommands = ['jeffk', 'leet', 'rot13', 'hexlify', 'binary', 'lithp',
'scramble', 'morse', 'reverse', 'urlquote', 'md5','sha'] 'scramble', 'morse', 'reverse', 'urlquote', 'md5','sha',
'colorize']
def outfilter(self, irc, msg, args, channel): def outfilter(self, irc, msg, args, channel):
"""[<channel>] [<command>] """[<channel>] [<command>]
@ -554,6 +555,21 @@ class Fun(callbacks.Privmsg):
text = privmsgs.getArgs(args) text = privmsgs.getArgs(args)
irc.reply(msg, text[::-1]) irc.reply(msg, text[::-1])
def _color(self, c):
if c == ' ':
return c
fg = random.randint(2, 15)
return '\x03%s%s' % (fg, c)
def colorize(self, irc, msg, args):
"""<text>
Returns <text> with each character randomly colorized.
"""
text = privmsgs.getArgs(args)
L = [self._color(c) for c in text]
irc.reply(msg, ''.join(L))
def jeffk(self, irc, msg, args): def jeffk(self, irc, msg, args):
"""<text> """<text>

View File

@ -97,6 +97,10 @@ class FunTest(ChannelPluginTestCase, PluginDocumentation):
s = 'the recalc1trant jam3ssan tests his scramble fun><tion' s = 'the recalc1trant jam3ssan tests his scramble fun><tion'
self.assertNotRegexp('scramble %s' % s, s) self.assertNotRegexp('scramble %s' % s, s)
def testColorize(self):
self.assertNotRegexp('colorize foobar', r'\s+')
self.assertRegexp('colorize foobar', r'\x03')
def testoutfilter(self): def testoutfilter(self):
s = self.nick.encode('rot13') s = self.nick.encode('rot13')
self.assertNotError('outfilter rot13') self.assertNotError('outfilter rot13')