From d01e79721967518283116f8cd1513a08249bb0a8 Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 29 Jun 2017 21:56:56 -0700 Subject: [PATCH] Merge handle_part into IRCS2SProtocol (#454) --- protocols/ircs2s_common.py | 22 ++++++++++++++++++++++ protocols/p10.py | 26 -------------------------- protocols/ts6_common.py | 19 ------------------- 3 files changed, 22 insertions(+), 45 deletions(-) diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index 307201a..7121f1f 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -327,6 +327,28 @@ class IRCS2SProtocol(IRCCommonProtocol): self._remove_client(numeric) return {'text': args[0]} + def handle_part(self, source, command, args): + """Handles incoming PART commands.""" + channels = self.toLower(args[0]).split(',') + + for channel in channels: + self.channels[channel].removeuser(source) + try: + self.users[source].channels.discard(channel) + except KeyError: + log.debug("(%s) handle_part: KeyError trying to remove %r from %r's channel list?", self.name, channel, source) + + try: + reason = args[1] + except IndexError: + reason = '' + + # Clear empty non-permanent channels. + if not (self.channels[channel].users or ((self.cmodes.get('permanent'), None) in self.channels[channel].modes)): + del self.channels[channel] + + return {'channels': channels, 'text': reason} + def handle_time(self, numeric, command, args): """Handles incoming /TIME requests.""" return {'target': args[0]} diff --git a/protocols/p10.py b/protocols/p10.py index 96da4a0..fa590bb 100644 --- a/protocols/p10.py +++ b/protocols/p10.py @@ -1144,32 +1144,6 @@ class P10Protocol(IRCS2SProtocol): # OPMODE is like SAMODE on other IRCds, and it follows the same modesetting syntax. handle_opmode = handle_mode - def handle_part(self, source, command, args): - """Handles user parts.""" - # <- ABAAA L #test,#test2 - # <- ABAAA L #test :test - - channels = self.toLower(args[0]).split(',') - for channel in channels: - # We should only get PART commands for channels that exist, right?? - self.channels[channel].removeuser(source) - - try: - self.users[source].channels.discard(channel) - except KeyError: - log.debug("(%s) handle_part: KeyError trying to remove %r from %r's channel list?", - self.name, channel, source) - try: - reason = args[1] - except IndexError: - reason = '' - - # Clear empty non-permanent channels. - if not self.channels[channel].users: - del self.channels[channel] - - return {'channels': channels, 'text': reason} - def handle_kick(self, source, command, args): """Handles incoming KICKs.""" # <- ABAAA K #TEST AyAAA :PyLink-devel diff --git a/protocols/ts6_common.py b/protocols/ts6_common.py index 20d25e1..65bf741 100644 --- a/protocols/ts6_common.py +++ b/protocols/ts6_common.py @@ -353,25 +353,6 @@ class TS6BaseProtocol(IRCS2SProtocol): return {'channel': channel, 'setter': numeric, 'text': topic, 'oldtopic': oldtopic} - def handle_part(self, source, command, args): - """Handles incoming PART commands.""" - channels = self.toLower(args[0]).split(',') - for channel in channels: - # We should only get PART commands for channels that exist, right?? - self.channels[channel].removeuser(source) - try: - self.users[source].channels.discard(channel) - except KeyError: - log.debug("(%s) handle_part: KeyError trying to remove %r from %r's channel list?", self.name, channel, source) - try: - reason = args[1] - except IndexError: - reason = '' - # Clear empty non-permanent channels. - if not (self.channels[channel].users or ((self.cmodes.get('permanent'), None) in self.channels[channel].modes)): - del self.channels[channel] - return {'channels': channels, 'text': reason} - def handle_svsnick(self, source, command, args): """Handles SVSNICK (forced nickname change attempts).""" # InspIRCd: