irc: Add PART command
patch 524dd6f7c12b54f938923345e56a313df81213f4
Author: E. Bosch <presidev@AT@gmail.com>
Date: Wed Mar 31 03:21:58 CEST 2021
* irc: Add PART command
hunk ./irc.py 33
+IRC_PART_RX = re.compile(PREFIX + r'PART( +|\n)(?P<channels>[^ ]+|)( +:| +|\n|)(?P<reason>[^\n]+|)')
hunk ./irc.py 112
+ (IRC_PART_RX, self.handle_irc_part, True, 1),
hunk ./irc.py 184
- #part all
- pass
+ for channel in self.irc_channels.keys():
+ if user.irc_nick in self.irc_channels[channel]:
+ await self.part_irc_channel(user, channel, '')
hunk ./irc.py 194
+ async def handle_irc_part(self, user, channels, reason):
+ self.logger.debug('Handling PART: %s, %s', channels, reason)
+
+ for channel in channels.split(','):
+ chan = channel.lower()
+ if chan in self.irc_channels.keys():
+ if user.irc_nick in self.irc_channels[chan]:
+ await self.part_irc_channel(user, channel, reason)
+ else:
+ await self.reply_code(user, 'ERR_NOTONCHANNEL', (channel,))
+ else:
+ await self.reply_code(user, 'ERR_NOSUCHCHANNEL', (channel,))
+
hunk ./irc.py 419
+ async def part_irc_channel(self, user, channel, reason):
+ chan = channel.lower()
+ real_chan = self.get_realcaps_name(chan)
+
+ # Notify IRC users in this channel
+ for usr in [self.users[x.lower()] for x in self.irc_channels[chan] if self.users[x.lower()].stream]:
+ await self.reply_command(usr, user, 'PART', (real_chan, reason))
+
+ self.irc_channels[chan].remove(user.irc_nick)
+ self.irc_channels_ops[chan].discard(user.irc_nick)
+ self.irc_channels_founder[chan].discard(user.irc_nick)
+
hunk ./irc.py 446
- async def part_irc_channel(self, user, channel):
- self.irc_channels[channel].remove(user.irc_nick)
- await self.send_irc_command(user, ':{} PART {} :'.format(
- user.get_irc_mask(), channel
- ))
-
hunk ./irc_replies.py 51
- 'ERR_NOTONCHANNEL': ('442', 'Not on channel'),
+ 'ERR_NOTONCHANNEL': ('442', '{} :Not on channel'),