self.db.recursive_set_and_report_change(update)
if not update.results:
return False
+
for scope, result in update.results:
log_kwargs: dict[str, Any] = {'scope': scope}
if scope in {LogScope.CHAT, LogScope.USER,
log_kwargs['is_notice'] = update.value.is_notice
else:
log_kwargs['log_target'] = update.full_path[1]
+
if isinstance(result, list):
msg = ''
for item in result:
content = str(nuh) if transform == 'NUH' else nuh.nick
msg += content
self.log(msg, **log_kwargs)
+
elif not update.full_path == ('message',):
log_path = ':'.join(update.full_path)
if result is None:
self.log(f' {item}', **log_kwargs)
else:
self.log(f'{announcement} [{result}]', **log_kwargs)
+
for win in [w for w in self.windows if isinstance(w, _ChatWindow)]:
win.set_prompt_prefix()
return bool([w for w in self.windows if w.tainted])
self._client_mngrs: dict[str, _ClientWindowsManager] = {}
def _log_target_wins(self, **kwargs) -> Sequence[Window]:
- scope = kwargs.get('scope', LogScope.SAME)
- if scope != LogScope.SAME:
+ if (scope := kwargs.get('scope', None)):
m = self._client_mngrs[kwargs['client_id']]
if scope == LogScope.ALL:
return [w for w in m.windows
'Forward todo to appropriate _ClientWindowsManager.'
if client_id not in self._client_mngrs:
self._client_mngrs[client_id] = _ClientWindowsManager(
- tui_log=lambda msg, **kw: self._log(
+ tui_log=lambda msg, **kw: self.log(
msg, client_id=client_id, **kw),
tui_new_window=lambda win_cls, **kw: self._new_window(
win_cls, _q_out=self._q_out, client_id=client_id, **kw))
class ClientKnowingTui(Client):
'Adapted to communicate with ClientTui.'
+ def _tui_trigger(self, method_name: str, **kwargs) -> None:
+ self._put(TuiEvent.affector(method_name).kw(**kwargs))
+
+ def _tui_alert_trigger(self, msg: str) -> None:
+ self._tui_trigger('log', msg=msg, prefix=_LOG_PREFIX_SERVER,
+ alert=True)
+
def _client_tui_trigger(self, todo: str, **kwargs) -> None:
- self._put(TuiEvent.affector('for_client_do').kw(
- client_id=self.client_id, todo=todo, **kwargs))
+ self._tui_trigger('for_client_do', client_id=self.client_id,
+ todo=todo, **kwargs)
def send_w_params_tuple(self, verb: str, params: tuple[str, ...]) -> None:
'Helper for ClientWindow to trigger .send, for it can only do kwargs.'
raise SendFail('not sending, since not in channel')
self.send('PRIVMSG', chat_target, msg)
except SendFail as e:
- self._log(f'{e}', scope=LogScope.SAME, alert=True)
+ self._tui_alert_trigger(f'{e}')
else:
self.db.messaging('').to(chat_target).privmsg = msg # type: ignore
def reconnect(self) -> None:
'Catch /reconnect, only initiate if not connected, else complain back.'
if self.conn:
- self._log('not re-connecting since already connected',
- scope=LogScope.SAME, alert=True)
+ self._tui_alert_trigger(
+ 'not re-connecting since already connected')
return
self.connect()
# separated to serve as hook for subclass window selection
return [self.window]
- def _log(self, msg: str, **kwargs) -> tuple[tuple[int, ...], str]:
+ def log(self, msg: str, **kwargs) -> tuple[tuple[int, ...], str]:
+ 'Write with timestamp, prefix to what window ._log_target_wins offers.'
prefix = kwargs.get('prefix', _LOG_PREFIX_DEFAULT)
if kwargs.get('alert', False):
prefix = _LOG_PREFIX_ALERT + prefix
elif len(typed_in) == 1:
self.window.prompt.insert(typed_in)
else:
- self._log(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(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('commands available in this window:')
+ self.log('commands available in this window:')
to_log = []
for cmd_name, cmd_data in self._commands.items():
to_print = [cmd_name]
to_print += [arg]
to_log += [' '.join(to_print)]
for item in sorted(to_log):
- self._log(f' /{item}')
+ self.log(f' /{item}')
def cmd__list(self) -> None:
'List available windows.'
- self._log('windows available via /window:')
+ self.log('windows available via /window:')
for win in self._windows:
- self._log(f' {win.idx}) {win.title}')
+ self.log(f' {win.idx}) {win.title}')
def cmd__quit(self) -> None:
'Trigger program exit.'