diff --git a/http2irc.py b/http2irc.py index 6ce47a6..79bdd58 100644 --- a/http2irc.py +++ b/http2irc.py @@ -445,11 +445,19 @@ class IRCClientProtocol(asyncio.Protocol): command, channels, message = data.decode('utf-8').split(' ', 2) for channel in channels.split(','): assert channel.startswith('#') or channel.startswith('&'), f'invalid channel: {channel!r}' + try: + modes = self.get_mode_chars(self.server.channels[self.server.casefold(channel)].users.get(self.server.casefold(self.server.nickname))) + except KeyError: + # E.g. when kicked from a channel in the config + # If the target channel isn't in self.server.channels, this *should* mean that the bot is not in the channel. + # Therefore, don't send this to the broadcaster either. + # TODO: Use echo-message instead and forward that to the broadcaster instead of emulating it here. Requires support from the network though... + continue user = { 'nick': self.server.nickname, 'hostmask': f'{self.server.nickname}!{self.server.username}@{self.server.hostname}', 'account': self.server.account, - 'modes': self.get_mode_chars(self.server.channels[self.server.casefold(channel)].users.get(self.server.casefold(self.server.nickname))), + 'modes': modes, } self.irc2httpBroadcaster.send(channel, {'time': time_, 'command': command, 'channel': channel, 'user': user, 'message': message}) return time_