From 61d95c19cc71af95f09d33b89121103419409627 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 15 Aug 2015 23:29:40 -0700 Subject: [PATCH] protocols: delete empty non-permanent channels --- protocols/inspircd.py | 9 ++++++++- protocols/ts6.py | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/protocols/inspircd.py b/protocols/inspircd.py index c2d407a..2144caf 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -122,8 +122,12 @@ def removeClient(irc, numeric): Removes a client from our internal databases, regardless of whether it's one of our pseudoclients or not.""" - for v in irc.channels.values(): + for c, v in irc.channels.copy().items(): v.removeuser(numeric) + # Clear empty non-permanent channels. + if not (irc.channels[c].users or ((irc.cmodes.get('permanent'), None) in irc.channels[c].modes)): + del irc.channels[c] + sid = numeric[:3] log.debug('Removing client %s from irc.users', numeric) del irc.users[numeric] @@ -366,6 +370,9 @@ def handle_part(irc, source, command, args): reason = args[1] except IndexError: reason = '' + # Clear empty non-permanent channels. + if not (irc.channels[channel].users or ((irc.cmodes.get('permanent'), None) in irc.channels[channel].modes)): + del irc.channels[channel] return {'channels': channels, 'text': reason} def handle_error(irc, numeric, command, args): diff --git a/protocols/ts6.py b/protocols/ts6.py index 6dad4ca..745f47b 100644 --- a/protocols/ts6.py +++ b/protocols/ts6.py @@ -378,9 +378,10 @@ def handle_part(irc, source, command, args): reason = args[1] except IndexError: reason = '' + if not (irc.channels[channel].users or ((irc.cmodes.get('permanent'), None) in irc.channels[channel].modes)): + del irc.channels[channel] return {'channels': channels, 'text': reason} - def handle_sjoin(irc, servernumeric, command, args): # parameters: channelTS, channel, simple modes, opt. mode parameters..., nicklist channel = args[1].lower()