From 7e37a90c80adeed3bd96ebd7fb470c4ef33bede6 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 16 Dec 2016 20:45:47 -0800 Subject: [PATCH] clientbot: delete channels on kick / part, or if a channel becomes empty after parting Closes #314. --- protocols/clientbot.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/protocols/clientbot.py b/protocols/clientbot.py index 2bd5321..1b61139 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -603,8 +603,18 @@ class ClientbotWrapperProtocol(Protocol): self.kick_queue[channel][1].cancel() del self.kick_queue[channel] - self.handle_part(target, 'KICK', [channel, reason]) - return {'channel': channel, 'target': target, 'text': reason} + # Statekeeping: remove the target from the channel they were previously in. + self.irc.channels[channel].removeuser(target) + try: + self.irc.users[target].channels.remove(channel) + except KeyError: + pass + + self.irc.callHooks([source, 'KICK', {'channel': channel, 'target': target, 'text': reason}]) + + # Delete channels that we were kicked from, for better state keeping. + if self.irc.pseudoclient and target == self.irc.pseudoclient.uid: + del self.irc.channels[channel] def handle_mode(self, source, command, args): """Handles MODE changes.""" @@ -667,7 +677,12 @@ class ClientbotWrapperProtocol(Protocol): self.irc.channels[channel].removeuser(source) self.irc.users[source].channels -= set(channels) - return {'channels': channels, 'text': reason} + self.irc.callHooks([source, 'PART', {'channels': channels, 'text': reason}]) + + # Clear channels that are empty, or that we're parting. + for channel in channels: + if (self.irc.pseudoclient and source == self.irc.pseudoclient.uid) or not self.irc.channels[channel].users: + del self.irc.channels[channel] def handle_ping(self, source, command, args): """