diff options
| author | 2021-10-10 02:34:44 +0000 | |
|---|---|---|
| committer | 2021-10-10 02:34:44 +0000 | |
| commit | ecfa851eed987302bb381f8fcff71fc605fa8c5c (patch) | |
| tree | 1a03f3cf986e4e6140bd01e1d64602f183278eee /http2irc.py | |
| parent | Gracefully handle channel bans and other join errors (diff) | |
| signature | ||
Fix crash on attempting to send to an unjoined channel
Diffstat (limited to 'http2irc.py')
| -rw-r--r-- | http2irc.py | 10 |
1 files changed, 9 insertions, 1 deletions
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_ |
