Browse Source

Fix crash on attempting to send to an unjoined channel

master
JustAnotherArchivist 2 years ago
parent
commit
ecfa851eed
1 changed files with 9 additions and 1 deletions
  1. +9
    -1
      http2irc.py

+ 9
- 1
http2irc.py View File

@@ -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_


Loading…
Cancel
Save