Skip to content

Commit

Permalink
use length in bytes of message/command to determine when to wrap IRC …
Browse files Browse the repository at this point in the history
…messages

previously, we used len(message)/len(command) to determine when to wrap, but that doesn't necessarily correlate to the number of bytes, which is what the IRC spec cares about
  • Loading branch information
antithalian authored and pbui committed Feb 23, 2024
1 parent d5e90bb commit eb01904
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/bobbit/protocol/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ async def send_message(self, message):
if isinstance(message, Message):
message = self.format_message(message)

if len(message) > MESSAGE_LENGTH_MAX:
# NOTE: use str.encode() to determine length of message/command since IRC only cares about number of bytes
if len(message.encode()) > MESSAGE_LENGTH_MAX:
command, message = message.split(' :', 1)
messages = [f'{command} :{m}' for m in textwrap.wrap(message, MESSAGE_LENGTH_MAX - len(command) - 2)]
messages = [f'{command} :{m}' for m in textwrap.wrap(message, MESSAGE_LENGTH_MAX - len(command.encode()) - 2)]
else:
messages = [message]

Expand Down

0 comments on commit eb01904

Please sign in to comment.