elif any(message.startswith(x) for x in (b'431 ', b'432 ', b'433 ', b'436 ')):
elif line.command in ('431', '432', '433', '436'):
self.logger.error(f'Failed to set nickname: {message!r}, terminating connection')
self.transport.close()
# USER errors
elif any(message.startswith(x) for x in (b'461 ', b'462 ')):
elif line.command in ('461', '462'):
self.logger.error(f'Failed to register: {message!r}, terminating connection')
self.transport.close()
# JOIN errors
elif any(message.startswith(x) for x in (b'405 ', b'471 ', b'473 ', b'474 ', b'475 ')):
elif line.command in ('405', '471', '473', '474', '475'):
self.logger.error(f'Failed to join channel: {message!r}, terminating connection')
self.transport.close()
# PART errors
elif message.startswith(b'442 '):
elif line.command == '442':
self.logger.error(f'Failed to part channel: {message!r}')
# JOIN/PART errors
elif message.startswith(b'403 '):
elif line.command == '403':
self.logger.error(f'Failed to join or part channel: {message!r}')
# PRIVMSG errors
elif any(message.startswith(x) for x in (b'401 ', b'404 ', b'407 ', b'411 ', b'412 ', b'413 ', b'414 ')):
self.logger.error(f'Failed to send message: {message!r}')
# Connection registration reply
elif message.startswith(b'001 '):
elif line.command == '001':
self.logger.info('IRC connection registered')
if self.sasl and not self.authenticated:
self.logger.error('IRC connection registered but not authenticated, terminating connection')
@@ -385,102 +376,6 @@ class IRCClientProtocol(asyncio.Protocol):
return
self._send_join_part(b'JOIN', self.channels)
# JOIN success
elif message.startswith(b'JOIN ') and not self.usermask:
# If this is my own join message, it should contain the usermask in the prefix
if rawMessage.startswith(b':' + self.config['irc']['nick'].encode('utf-8') + b'!') and b' ' in rawMessage:
usermask = rawMessage.split(b' ', 1)[0][1:]
self._maybe_set_usermask(usermask)
# Services host change
elif message.startswith(b'396 '):
words = message.split(b' ')
if len(words) >= 3:
# Sanity check inspired by irssi src/irc/core/irc-servers.c
if not any(x in words[2] for x in (b'*', b'?', b'!', b'#', b'&', b' ')) and not any(words[2].startswith(x) for x in (b'@', b':', b'-')) and words[2][-1:] != b'-':
if not hasPrefix or (decoded and hasPrefix and nick == self.config['irc']['nick']):
# Oh no, *I* am getting disconnected! :-(
# I'm not actually sure whether the prefix version can happen, but better safe than sorry...
# In this case, it should be logged to all channels as well as the general log. The extra 'general' entry triggers Storage's code to write a message to the general log.
# Side effect: if the connection dies before any channels were joined, this causes the quit to be logged everywhere. However, there won't be a JOIN in the log, so it would still be unambiguous.
# Also, the connection loss after the disconnect triggers another message to be written to the logs. ¯\_(ツ)_/¯