From 2331205368629947b9a516e8b9a0c973899f25e3 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 16 Jan 2019 12:41:41 +0000 Subject: Don't ignore a color code when it's right at the end of a message (src/utils/irc.py) --- src/utils/irc.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/utils') diff --git a/src/utils/irc.py b/src/utils/irc.py index b897ee6e..25c170dd 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -160,27 +160,22 @@ def _format_tokens(s: str) -> typing.List[str]: is_background = False matches = [] # type: typing.List[str] - for char in s: + for i, char in enumerate(s): + last_char = i == len(s) if is_color: can_add = False current_color = background if is_background else foreground + color_finished = False if char.isdigit() and len(current_color) < 2: - if current_color: - next_color = int(current_color + char) - can_add = next_color <= 99 - else: - can_add = True - - if can_add: if is_background: background += char else: foreground += char - continue - elif char == "," and not is_background: + color_finished = (len(current_color)+1) == 2 + + if char == "," and not is_background: is_background = True - continue - else: + elif not char.isdigit() or (color_finished and last_char): color = foreground if background: color += ","+background -- cgit v1.3.1-10-gc9f91