Only request a CAP once. closes #66

This commit is contained in:
jesopo 2019-06-08 10:17:13 +01:00
parent d9321b87ec
commit 16b9361371
2 changed files with 14 additions and 4 deletions

View file

@ -85,15 +85,15 @@ def cap(events, event):
if subcommand == "ACK" or subcommand == "NAK": if subcommand == "ACK" or subcommand == "NAK":
ack = subcommand == "ACK" ack = subcommand == "ACK"
for capability in capabilities: for capability in capabilities:
cap_obj = event["server"].capability_queue[capability] cap_obj = event["server"].capabilities_requested[capability]
del event["server"].capability_queue[capability] del event["server"].capabilities_requested[capability]
if ack: if ack:
cap_obj.ack() cap_obj.ack()
else: else:
cap_obj.nak() cap_obj.nak()
if (event["server"].cap_started and if (event["server"].cap_started and
not event["server"].capability_queue and not event["server"].capabilities_requested and
not event["server"].waiting_for_capabilities()): not event["server"].waiting_for_capabilities()):
event["server"].cap_started = False event["server"].cap_started = False
event["server"].send_capability_end() event["server"].send_capability_end()

View file

@ -28,6 +28,9 @@ class Server(IRCObject.Object):
self.capability_queue = { self.capability_queue = {
} # type: typing.Dict[str, utils.irc.Capability] } # type: typing.Dict[str, utils.irc.Capability]
self.capabilities_requested = {
} # type: typing.Dict[str, utils.irc.Capability]
self._capabilities_waiting = set([]) # type: typing.Set[str] self._capabilities_waiting = set([]) # type: typing.Set[str]
self.agreed_capabilities = set([]) # type: typing.Set[str] self.agreed_capabilities = set([]) # type: typing.Set[str]
self.server_capabilities = {} # type: typing.Dict[str, str] self.server_capabilities = {} # type: typing.Dict[str, str]
@ -283,11 +286,18 @@ class Server(IRCObject.Object):
def send_capibility_ls(self) -> IRCLine.SentLine: def send_capibility_ls(self) -> 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 = [cap for cap in self.capability_queue.keys()] capability_queue = list(self.capability_queue.keys())
for i in range(0, len(capability_queue), 10): for i in range(0, len(capability_queue), 10):
capability_batch = capability_queue[i:i+10] capability_batch = capability_queue[i:i+10]
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)) self.send_capability_request(" ".join(capability_batch))
def send_capability_request(self, capability: str) -> IRCLine.SentLine: def send_capability_request(self, capability: str) -> IRCLine.SentLine:
return self.send(utils.irc.protocol.capability_request(capability)) return self.send(utils.irc.protocol.capability_request(capability))
def send_capability_end(self) -> IRCLine.SentLine: def send_capability_end(self) -> IRCLine.SentLine: