From 4bab1aea3094c2fa6cd8ba96a42eda905a933581 Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 9 Nov 2018 10:43:05 +0000 Subject: [PATCH] Add a way to more explicitly denote when a CAP handshake has ended early --- modules/line_handler.py | 10 ++++++---- modules/resume.py | 2 +- src/IRCServer.py | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/line_handler.py b/modules/line_handler.py index bdb0c70b..dc38e675 100644 --- a/modules/line_handler.py +++ b/modules/line_handler.py @@ -265,6 +265,7 @@ class Module(ModuleManager.BaseModule): is_multiline = len(event["args"]) > 2 and event["args"][2] == "*" if subcommand == "ls": + event["server"].cap_started = True event["server"].server_capabilities.update(capabilities) if not is_multiline: matched_capabilities = set(event["server" @@ -292,13 +293,14 @@ class Module(ModuleManager.BaseModule): elif subcommand == "ack": event["server"].capabilities.update(capabilities) if not is_multiline: - results = self.events.on("received.cap.ack").call( + self.events.on("received.cap.ack").call( capabilities=event["server"].capabilities, server=event["server"]) - if not False in results: - if not event["server"].waiting_for_capabilities(): - event["server"].send_capability_end() + if event["server"].cap_started and not event["server" + ].waiting_for_capabilities(): + event["server"].cap_started = False + event["server"].send_capability_end() elif subcommand == "nack": event["server"].send_capability_end() diff --git a/modules/resume.py b/modules/resume.py index 21fa83e8..676602a5 100644 --- a/modules/resume.py +++ b/modules/resume.py @@ -17,7 +17,7 @@ class Module(ModuleManager.BaseModule): username, token = self._get_token(event["server"]) if CAP in event["capabilities"] and username and token: event["server"].send("RESUME %s %s" % (username, token)) - return False + event["server"].cap_started = False @utils.hook("received.resume") def on_resume(self, event): diff --git a/src/IRCServer.py b/src/IRCServer.py index 8d1a366f..ad5d7451 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -26,6 +26,7 @@ class Server(IRCObject.Object): self.capabilities = set([]) # type: typing.Set[str] self.server_capabilities = {} # type: typing.Dict[str, str] self.batches = {} # type: typing.Dict[str, utils.irc.IRCLine] + self.cap_started = False self.write_buffer = b"" self.buffered_lines = [] # type: typing.List[bytes] @@ -361,7 +362,7 @@ class Server(IRCObject.Object): self._capabilities_waiting.add(capability) def capability_done(self, capability: str): self._capabilities_waiting.remove(capability) - if not self._capabilities_waiting: + if self.cap_started and not self._capabilities_waiting: self.send_capability_end() def send_pass(self, password: str):