Make use of utils.truncate_encode, to avoid cutting utf8 sequences in half

This commit is contained in:
jesopo 2019-02-10 16:48:08 +00:00
parent f2c762a2d0
commit 7952d4c366

View file

@ -314,11 +314,10 @@ class Server(IRCObject.Object):
line = result
break
encoded = line.split("\n")[0].strip("\r").encode("utf8")
if len(encoded) > LINE_CUTOFF:
encoded = encoded[:LINE_CUTOFF]
line_stripped = line.split("\n", 1)[0].strip("\r")
encoded = utils.encode_truncate(line_stripped, "utf8", LINE_CUTOFF)
encoded = b"%s\r\n" % encoded
line_obj = IRCLine.Line(datetime.datetime.utcnow(), encoded)
self.queued_lines.append(line_obj)