diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b3b6796..f450179d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Changed: - IRCv3: CAP REQ streamline for modules - IRCv3: SASL failure defaults to being "hard" (disconnect/crash) - `auto-title`, `auto-youtube`, `auto-imgur` etc now work in `/me` +- Move truncation logic from `SentLine` to `ParsedLine` Fixed: - `KeyError` when sts `port` key not present diff --git a/src/IRCLine.py b/src/IRCLine.py index 37b08e42..666977f9 100644 --- a/src/IRCLine.py +++ b/src/IRCLine.py @@ -80,9 +80,11 @@ class ParsedLine(object): return "@%s" % ";".join(tag_pieces) return "" - def format(self) -> str: + def _format(self) -> typing.Tuple[str, str]: pieces = [] + tags = "" if self.tags: + tags = self._tag_str(self.tags) pieces.append(self._tag_str(self.tags)) if self.source: @@ -98,7 +100,13 @@ class ParsedLine(object): else: pieces.append(arg) - return " ".join(pieces).split("\n")[0].strip("\r") + return tags, " ".join(pieces).split("\n")[0].strip("\r") + def format(self) -> str: + tags, line = self._format() + if tags: + return "%s %s" % (tags, line) + else: + return line def _line_max(self, hostmask: str) -> int: return LINE_MAX-len((":%s " % hostmask).encode("utf8")) @@ -108,8 +116,8 @@ class ParsedLine(object): line_max = self._line_max(hostmask) - formatted = self.format() - for i, char in enumerate(formatted): + tags_formatted, line_formatted = self._format() + for i, char in enumerate(line_formatted): encoded_char = char.encode("utf8") if len(valid_bytes)+len(encoded_char) > line_max: break @@ -118,7 +126,12 @@ class ParsedLine(object): valid_index = i valid_index += 1 - return formatted[:valid_index], formatted[valid_index:] + valid = line_formatted[:valid_index] + if tags_formatted: + valid = "%s %s" % (tags_formatted, line_formatted) + overflow = line_formatted[valid_index:] + + return valid, overflow class SentLine(IRCObject.Object): def __init__(self, events: "EventManager.EventHook",