Add a way to more explicitly denote when a CAP handshake has ended early

This commit is contained in:
jesopo 2018-11-09 10:43:05 +00:00
parent a2292eb439
commit 4bab1aea30
3 changed files with 9 additions and 6 deletions

View file

@ -265,6 +265,7 @@ class Module(ModuleManager.BaseModule):
is_multiline = len(event["args"]) > 2 and event["args"][2] == "*" is_multiline = len(event["args"]) > 2 and event["args"][2] == "*"
if subcommand == "ls": if subcommand == "ls":
event["server"].cap_started = True
event["server"].server_capabilities.update(capabilities) event["server"].server_capabilities.update(capabilities)
if not is_multiline: if not is_multiline:
matched_capabilities = set(event["server" matched_capabilities = set(event["server"
@ -292,12 +293,13 @@ class Module(ModuleManager.BaseModule):
elif subcommand == "ack": elif subcommand == "ack":
event["server"].capabilities.update(capabilities) event["server"].capabilities.update(capabilities)
if not is_multiline: if not is_multiline:
results = self.events.on("received.cap.ack").call( self.events.on("received.cap.ack").call(
capabilities=event["server"].capabilities, capabilities=event["server"].capabilities,
server=event["server"]) server=event["server"])
if not False in results: if event["server"].cap_started and not event["server"
if not event["server"].waiting_for_capabilities(): ].waiting_for_capabilities():
event["server"].cap_started = False
event["server"].send_capability_end() event["server"].send_capability_end()
elif subcommand == "nack": elif subcommand == "nack":
event["server"].send_capability_end() event["server"].send_capability_end()

View file

@ -17,7 +17,7 @@ class Module(ModuleManager.BaseModule):
username, token = self._get_token(event["server"]) username, token = self._get_token(event["server"])
if CAP in event["capabilities"] and username and token: if CAP in event["capabilities"] and username and token:
event["server"].send("RESUME %s %s" % (username, token)) event["server"].send("RESUME %s %s" % (username, token))
return False event["server"].cap_started = False
@utils.hook("received.resume") @utils.hook("received.resume")
def on_resume(self, event): def on_resume(self, event):

View file

@ -26,6 +26,7 @@ class Server(IRCObject.Object):
self.capabilities = set([]) # type: typing.Set[str] self.capabilities = set([]) # type: typing.Set[str]
self.server_capabilities = {} # type: typing.Dict[str, str] self.server_capabilities = {} # type: typing.Dict[str, str]
self.batches = {} # type: typing.Dict[str, utils.irc.IRCLine] self.batches = {} # type: typing.Dict[str, utils.irc.IRCLine]
self.cap_started = False
self.write_buffer = b"" self.write_buffer = b""
self.buffered_lines = [] # type: typing.List[bytes] self.buffered_lines = [] # type: typing.List[bytes]
@ -361,7 +362,7 @@ class Server(IRCObject.Object):
self._capabilities_waiting.add(capability) self._capabilities_waiting.add(capability)
def capability_done(self, capability: str): def capability_done(self, capability: str):
self._capabilities_waiting.remove(capability) self._capabilities_waiting.remove(capability)
if not self._capabilities_waiting: if self.cap_started and not self._capabilities_waiting:
self.send_capability_end() self.send_capability_end()
def send_pass(self, password: str): def send_pass(self, password: str):