self.conn_setup.port = PORT_SSL
self.client_id = self.conn_setup.hostname
super().__init__(client_id=self.client_id, **kwargs)
- self._log = Logger(self._do_log)
+ self._log = Logger(self._do_log).add
self.update_login(nick_confirmed=False,
nickname=self.conn_setup.nickname)
- self._log.add(f'connecting {self.conn_setup}')
+ self._log(f'connecting {self.conn_setup}')
self.start_connecting()
def start_connecting(self) -> None:
client_id=self.client_id)
self._client_trigger('_on_connect')
except IrcConnAbortException as e:
- self._log.add(str(e), alert=True)
+ self._log(str(e), alert=True)
except Exception as e: # pylint: disable=broad-exception-caught
self._put(ExceptionEvent(e))
def _on_connect(self) -> None:
'Steps to perform right after connection.'
assert self.conn is not None
- self._log.add('connected to server (SSL: '
- f'{"yes" if self.conn.ssl else "no"})',
- stream=STREAM_ALL)
+ self._log('connected to server (SSL: '
+ f'{"yes" if self.conn.ssl else "no"})',
+ stream=STREAM_ALL)
self._caps.challenge('LS', '302')
self.send(IrcMessage(verb='USER',
params=(getuser(), '0', '*',
) -> None:
'Send line-separator-delimited message over socket.'
if not self.conn:
- self._log.add('cannot send, connection seems closed', alert=True,
- stream=stream)
+ self._log('cannot send, connection seems closed', alert=True,
+ stream=stream)
return
self.conn.send(msg)
if to_log:
- self._log.add(to_log, prefix='', stream=stream)
- self._log.add(msg.raw, prefix=_LOG_PREFIX_SEND_RAW, stream=STREAM_RAW)
+ self._log(to_log, prefix='', stream=stream)
+ self._log(msg.raw, prefix=_LOG_PREFIX_SEND_RAW, stream=STREAM_RAW)
def update_login(self, nick_confirmed: bool, nickname: str = '') -> None:
'''Manage conn_setup.nickname, .nick_confirmed.
verb = ('set' if first_run
else f'changed from "{self.conn_setup.nickname}"')
self.conn_setup.nickname = nickname
- self._log.add(f'{prefix} {verb} to "{nickname}"',
- stream=STREAM_ALL)
+ self._log(f'{prefix} {verb} to "{nickname}"', stream=STREAM_ALL)
if first_run or nick_confirmed != self.nick_confirmed:
self.nick_confirmed = nick_confirmed
if not first_run:
- self._log.add(f'{prefix} {"" if nick_confirmed else "un"}'
- 'confirmed')
+ self._log(
+ f'{prefix} {"" if nick_confirmed else "un"}confirmed')
def close(self) -> None:
'Close both recv Loop and socket.'
- self._log.add(msg='disconnecting from server', stream=STREAM_ALL)
+ self._log(msg='disconnecting from server', stream=STREAM_ALL)
self._caps.clear()
if self.conn:
self.conn.close()
def on_handled_loop_exception(self, e: IrcConnAbortException) -> None:
'Gracefully handle broken connection.'
- self._log.add(f'connection broken: {e}', alert=True)
+ self._log(f'connection broken: {e}', alert=True)
self.close()
def handle_msg(self, msg: IrcMessage) -> None:
'Process incoming msg towards appropriate client steps.'
- self._log.add(msg.raw, prefix=_LOG_PREFIX_RECV_RAW, stream=STREAM_RAW)
+ self._log(msg.raw, prefix=_LOG_PREFIX_RECV_RAW, stream=STREAM_RAW)
match msg.verb:
case 'PING':
self.send(IrcMessage(verb='PONG', params=(msg.params[0],)))
self.update_login(nickname=msg.params[0], nick_confirmed=True)
case 'PRIVMSG':
nickname = msg.source.split('!')[0]
- self._log.add(f'< [{nickname}] {msg.params[-1]}',
- stream=nickname,
- prefix=_LOG_PREFIX_PRIVMSG)
+ self._log(f'< [{nickname}] {msg.params[-1]}', stream=nickname,
+ prefix=_LOG_PREFIX_PRIVMSG)
case 'CAP':
if (result := self._caps.process_msg(msg.params[1:])):
if isinstance(result, str):
- self._log.add(result)
+ self._log(result)
else:
for line in (['server capabilities (enabled: "+"):']
+ [cap.str_for_log(c_name) for c_name, cap
in self._caps.dict.items()]):
- self._log.add(line)
+ self._log(line)
if self._caps.sasl_wait:
if self.conn_setup.password:
self.send(IrcMessage('AUTHENTICATE', ('PLAIN',)))
self.send(IrcMessage('AUTHENTICATE', (auth,)))
case '903' | '904':
if msg.verb == '904':
- self._log.add('SASL authentication failed', alert=True)
+ self._log('SASL authentication failed', alert=True)
self._caps.challenge('END')
self._new_window()
self._log = Logger(
lambda msg: # pylint: disable=unnecessary-lambda # to keep up-to…
- self.window.history.append(msg)) # …-date _what_ window's .history
+ self.window.history.append(msg) # …-date _what_…
+ ).add # …window's .history
self._set_screen()
signal(SIGWINCH, lambda *_: self._set_screen())
elif len(typed_in) == 1:
self.window.prompt.insert(typed_in)
else:
- self._log.add(f'unknown keyboard input: {typed_in}', alert=True)
+ self._log(f'unknown keyboard input: {typed_in}', alert=True)
self.redraw_affected()
def cmd__prompt_enter(self) -> None:
else:
alert = 'not prefixed by /'
if alert:
- self._log.add(f'invalid prompt command: {alert}', alert=True)
+ self._log(f'invalid prompt command: {alert}', alert=True)
def cmd__help(self) -> None:
'Print available commands.'
- self._log.add('commands available in this window:')
+ self._log('commands available in this window:')
to_log = []
for cmd_name, cmd_data in self._commands.items():
args = []
args += [arg]
to_log += [f'{cmd_name} {" ".join(args)}']
for item in sorted(to_log):
- self._log.add(f' /{item}')
+ self._log(f' /{item}')
def cmd__list(self) -> None:
'List available windows.'
- self._log.add('windows available via /window:')
+ self._log('windows available via /window:')
for win in self._windows:
- self._log.add(f' {win.status_title}')
+ self._log(f' {win.status_title}')
def cmd__quit(self) -> None:
'Trigger program exit.'