def set_and_check_for_change(self, update: _Update
) -> Optional[tuple[LogScope, Any]]:
- msg: str | dict[str, tuple[str, ...]]
- if update.path == ('user_ids',):
- assert isinstance(update.value, tuple)
- msg = {}
- if not self.user_ids:
- msg['nicks:residents'] = tuple(update.value)
- else:
- msg['nuhs:joining'] = tuple(id_ for id_ in update.value
- if id_ not in self.user_ids)
+ scope = self._scope(update.path)
+ if update.path[-1] == 'topic':
+ if super().set_and_check_for_change(update):
+ return (scope,
+ f'RAW:{self.topic.who} set topic: {self.topic.what}')
+ return None
+ assert update.path[-1] == 'user_ids'
+ assert isinstance(update.value, tuple)
+ d = {'nuhs:joining': tuple(id_ for id_ in update.value
+ if id_ not in self.user_ids)
+ } if self.user_ids else {'nicks:residents': tuple(update.value)}
if super().set_and_check_for_change(update):
- if update.path == ('topic',):
- msg = f'raw:{self.topic.who} set topic to: {self.topic.what}'
- return self._scope(update.path), msg
+ return scope, d
return None
def set_and_check_for_change(self, update: _Update
) -> Optional[tuple[LogScope, Any]]:
- if update.path == ('exit_msg',):
- assert isinstance(update.value, str)
- if super().set_and_check_for_change(update) and update.value:
- return self._scope(update.path), {
- 'user': str(self),
- 'msg': (f': {update.value[1:]}' if len(update.value) > 1
- else ''),
- 'verb': 'quits' if update.value[0] == 'Q' else 'parts'}
- return None
- return super().set_and_check_for_change(update)
+ assert isinstance(update.value, str)
+ if update.path[-1] == 'modes':
+ return super().set_and_check_for_change(update)
+ if super().set_and_check_for_change(update):
+ scope = self._scope(update.path)
+ msg = f'RAW:{self} '
+ if update.path[-1] == 'nick':
+ return scope, msg + f'renames {update.value}'
+ if update.path[-1] == 'exit_msg' and update.value:
+ msg += 'quits' if update.value[0] == 'Q' else 'parts'
+ if len(update.value) > 1:
+ msg += ': ' + update.value[1:]
+ return scope, msg
+ return None
@property
def prev(self) -> str:
log_kwargs |= {'target': update.path[1]}
if value is None:
self.log(f'{log_path} cleared', **log_kwargs)
- elif scope is LogScope.USER:
- if update.path[-1] == 'nick':
- msg = f'{self.db.users[update.path[1]].prev} renames {value}'
- elif update.path[-1] == 'exit_msg':
- msg = f'{value["user"]} {value["verb"]}{value["msg"]}'
- self.log(msg, **log_kwargs)
elif isinstance(value, dict):
for verb, item in [(k, v) for k, v in value.items() if v]:
toks = verb.split(':', maxsplit=1)
(str(nuh) if transform == 'nuhs' else nuh.nick)
for nuh in nuhs])
self.log(f'{verb}: {item}', **log_kwargs)
- elif isinstance(value, str) and value.startswith('raw:'):
+ elif isinstance(value, str) and value.startswith('RAW:'):
self.log(value.split(':', maxsplit=1)[1], **log_kwargs)
else:
announcement = f'{log_path} set to:'