From a27bc2034097c0a52d11472b21b61201c2bc6c84 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Wed, 8 Dec 2021 01:52:45 +0000 Subject: [PATCH] Add support for INVITE after getting KICKed from a channel --- http2irc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/http2irc.py b/http2irc.py index d6cce6c..85a7d1c 100644 --- a/http2irc.py +++ b/http2irc.py @@ -360,6 +360,7 @@ class IRCClientProtocol(asyncio.Protocol): self.buffer = b'' self.connected = False self.channels = channels # Currently joined/supposed-to-be-joined channels; set(str) + self.kickedChannels = set() # Channels the bot got KICKed from (for re-INVITE purposes; reset on config reloading) self.unconfirmedMessages = [] self.pongReceivedEvent = asyncio.Event() self.sasl = bool(self.config['irc']['certfile'] and self.config['irc']['certkeyfile']) @@ -432,6 +433,7 @@ class IRCClientProtocol(asyncio.Protocol): channelsToPart = self.channels - channels channelsToJoin = channels - self.channels self.channels = channels + self.kickedChannels = set() if self.connected: if channelsToPart: @@ -710,6 +712,17 @@ class IRCClientProtocol(asyncio.Protocol): for channel in self.channels: if self.server.casefold(channel) == kickedChannel: self.channels.remove(channel) + self.kickedChannels.add(channel) # Non-folded version so the set comparison in update_channels doesn't break. + break + + # Bot getting INVITEd after a KICK + elif line.command == 'INVITE' and line.source and self.server.casefold(line.params[0]) == self.server.casefold(self.server.nickname): + invitedChannel = self.server.casefold(line.params[1]) + for channel in self.kickedChannels: + if self.server.casefold(channel) == invitedChannel: + self.channels.add(channel) + self.kickedChannels.remove(channel) + self._send_join_part(b'JOIN', {channel}) break # WHOX on successful JOIN if supported to fetch account information