Make send_capability_queue split 'CAP REQ' message based on string length.

Instead of sending caps by groups of 10.
This commit is contained in:
Valentin Lorentz 2019-10-23 21:09:19 +02:00
parent 062290704c
commit d8c48fa98f

View file

@ -1,4 +1,4 @@
import collections, datetime, sys, time, typing import collections, datetime, sys, textwrap, time, typing
from src import EventManager, IRCBot, IRCChannel, IRCChannels, IRCLine from src import EventManager, IRCBot, IRCChannel, IRCChannels, IRCLine
from src import IRCObject, IRCSocket, IRCUser, utils from src import IRCObject, IRCSocket, IRCUser, utils
@ -305,17 +305,13 @@ class Server(IRCObject.Object):
def send_capibility_ls(self) -> typing.Optional[IRCLine.SentLine]: def send_capibility_ls(self) -> typing.Optional[IRCLine.SentLine]:
return self.send(utils.irc.protocol.capability_ls()) return self.send(utils.irc.protocol.capability_ls())
def send_capability_queue(self): def send_capability_queue(self):
capability_queue = list(self.capability_queue.keys()) # textwrap works here because in ASCII, all chars are 1 bytes:
capabilities = " ".join(self.capability_queue.keys())
capability_batches = textwrap.wrap(capabilities,
IRCLine.LINE_MAX-len("CAP REQ :"))
for i in range(0, len(capability_queue), 10): for capability_batch in capability_batches:
capability_batch = capability_queue[i:i+10] self.send_capability_request(capability_batch)
for cap_name in capability_batch:
cap = self.capability_queue[cap_name]
del self.capability_queue[cap_name]
self.capabilities_requested[cap_name] = cap
self.send_capability_request(" ".join(capability_batch))
def send_capability_request(self, capability: str def send_capability_request(self, capability: str
) -> typing.Optional[IRCLine.SentLine]: ) -> typing.Optional[IRCLine.SentLine]: