3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 03:33:10 +01:00

clientbot: delete channels on kick / part, or if a channel becomes empty after parting

Closes #314.
This commit is contained in:
James Lu 2016-12-16 20:45:47 -08:00
parent e7a005b685
commit 7e37a90c80

View File

@ -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):
"""