Просмотр исходного кода

Fix usermask length calculation

Didn't account for the ! and @ symbols, so in certain cases, two bytes at the ends of lines vanished.
master
JustAnotherArchivist 2 лет назад
Родитель
Сommit
1e69a42eae
1 измененных файлов: 2 добавлений и 2 удалений
  1. +2
    -2
      http2irc.py

+ 2
- 2
http2irc.py Просмотреть файл

@@ -516,7 +516,7 @@ class IRCClientProtocol(asyncio.Protocol):
def _self_usermask_length(self): def _self_usermask_length(self):
if not self.server.nickname or not self.server.username or not self.server.hostname: if not self.server.nickname or not self.server.username or not self.server.hostname:
return 100 return 100
return len(self.server.nickname) + len(self.server.username) + len(self.server.hostname)
return len(self.server.nickname) + 1 + len(self.server.username) + 1 + len(self.server.hostname) # nickname!username@hostname


async def send_messages(self): async def send_messages(self):
while self.connected: while self.connected:
@@ -527,7 +527,7 @@ class IRCClientProtocol(asyncio.Protocol):
break break
channelB = channel.encode('utf-8') channelB = channel.encode('utf-8')
messageB = message.encode('utf-8') messageB = message.encode('utf-8')
usermaskPrefixLength = 1 + self._self_usermask_length() + 1
usermaskPrefixLength = 1 + self._self_usermask_length() + 1 # :usermask<SP>
if usermaskPrefixLength + len(b'PRIVMSG ' + channelB + b' :' + messageB) > 510: if usermaskPrefixLength + len(b'PRIVMSG ' + channelB + b' :' + messageB) > 510:
# Message too long, need to split or truncate. First try to split on spaces, then on codepoints. Ideally, would use graphemes between, but that's too complicated. # Message too long, need to split or truncate. First try to split on spaces, then on codepoints. Ideally, would use graphemes between, but that's too complicated.
self.logger.debug(f'Message too long, overlongmode = {overlongmode}') self.logger.debug(f'Message too long, overlongmode = {overlongmode}')


Загрузка…
Отмена
Сохранить