Strip colour before applying new colour in Filter.rainbow and colorize

This makes them work much better when the input text already contains colour.

(cherry picked from commit jacksonmj/Limnoria@be83befabf)
This commit is contained in:
jacksonmj 2015-08-31 15:52:45 +00:00 committed by James Lu
parent bc19a9fc7f
commit 61f2df5cc3
1 changed files with 6 additions and 0 deletions

View File

@ -393,7 +393,12 @@ class Filter(callbacks.Plugin):
Returns <text> with each character randomly colorized.
"""
if minisix.PY2:
text = text.decode('utf-8')
text = ircutils.stripColor(text)
L = [self._color(c) for c in text]
if minisix.PY2:
L = [c.encode('utf-8') for c in L]
irc.reply('%s%s' % (''.join(L), '\x03'))
colorize = wrap(colorize, ['text'])
@ -405,6 +410,7 @@ class Filter(callbacks.Plugin):
"""
if minisix.PY2:
text = text.decode('utf-8')
text = ircutils.stripColor(text)
colors = utils.iter.cycle(['05', '04', '07', '08', '09', '03', '11',
'10', '12', '02', '06', '13'])
L = [self._color(c, fg=next(colors)) for c in text]