unColor is now working. Added a colorstrip outfilter to Filter to close RFE

#863599
This commit is contained in:
James Vega 2004-04-09 03:59:12 +00:00
parent 7f6040a160
commit b2153c83fb
4 changed files with 26 additions and 4 deletions

View File

@ -78,7 +78,7 @@ class Filter(callbacks.Privmsg):
_filterCommands = ['jeffk', 'leet', 'rot13', 'hexlify', 'binary', 'lithp',
'scramble', 'morse', 'reverse', 'colorize', 'squish',
'supa1337']
'supa1337', 'colorstrip']
def outfilter(self, irc, msg, args, channel):
"""[<channel>] [<command>]
@ -344,6 +344,14 @@ class Filter(callbacks.Privmsg):
L = [self._color(c) for c in text]
irc.reply(''.join(L))
def colorstrip(self, irc, msg, args):
"""<text>
Returns <text> stripped of all color codes.
"""
text = privmsgs.getArgs(args)
irc.reply(ircutils.unColor(text))
def jeffk(self, irc, msg, args):
"""<text>

View File

@ -315,7 +315,7 @@ def canonicalColor(s, bg=False, shift=0):
else:
return (fg, None)
_unColorRe = re.compile('(?:\x03\\d{1,2},\\d{1,2})|\x03\\d{1,2}|\x03|\x0F')
_unColorRe = re.compile(r'\x03(?:\d{1,2},\d{1,2}|\d{1,2}|,\d{1,2}|)')
def unColor(s):
"""Removes the color from a string."""
return _unColorRe.sub('', s)

View File

@ -81,6 +81,11 @@ class FilterTest(ChannelPluginTestCase, PluginDocumentation):
self.assertNotRegexp('colorize foobar', r'\s+')
self.assertRegexp('colorize foobar', r'\x03')
_strings = ('Supybot pwns!', '123456', 'A string with \x02bold\x15')
def testColorstrip(self):
for s in self._strings:
self.assertResponse('colorstrip [colorize %s]' % s, s)
def testOutfilter(self):
s = self.nick.encode('rot13')
self.assertNotError('outfilter rot13')
@ -102,7 +107,5 @@ class FilterTest(ChannelPluginTestCase, PluginDocumentation):
self.failUnless(ircmsgs.isAction(m))
s = ircmsgs.unAction(m)
self.assertEqual(s, 'sbbone')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -176,12 +176,23 @@ class FunctionsTestCase(SupyTestCase):
['+be-l', plusB[1], plusE[1]])
def testUnColor(self):
self.assertEqual(ircutils.unColor('\x02bold\x0302,04foo\x03bar\x0f'),
'\x02boldfoobar\x0f')
self.assertEqual(ircutils.unColor('\x03foo\x03'), 'foo')
self.assertEqual(ircutils.unColor('\x03foo\x0F'), 'foo')
self.assertEqual(ircutils.unColor('\x0312foo\x03'), 'foo')
self.assertEqual(ircutils.unColor('\x0312,14foo\x03'), 'foo')
self.assertEqual(ircutils.unColor('\x03,14foo\x03'), 'foo')
self.assertEqual(ircutils.unColor('\x03,foo\x03'), ',foo')
# These tests aren't going to pass until I decide how to handle
# stripping of \x0f. We don't want to just rampantly remove \x0f
# because it may be a clear code from some other formatting. Leaving
# it in doesn't adversely affect anything, so for now I'm not removing
# it.
self.assertEqual(ircutils.unColor('\x0312foo\x0F'), 'foo')
self.assertEqual(ircutils.unColor('\x0312,14foo\x0F'), 'foo')
self.assertEqual(ircutils.unColor('\x03,14foo\x0F'), 'foo')
self.assertEqual(ircutils.unColor('\x03,foo\x0F'), ',foo')
def testDccIpStuff(self):
def randomIP():