def __init__(self, path_logs: Optional[Path], **kwargs) -> None:
self._path_logs = path_logs
super().__init__(**kwargs)
- self._title = f'{self.client_id} :DEBUG'
+ self._title = ':DEBUG'
+
+ @property
+ def title(self) -> str:
+ return f'{self.client_id} {self._title}'
def log(self, msg: str) -> None:
super().log(msg)
if self._path_logs is None:
return
- escaped = ''
- for char in self._title:
- if (char.isalpha() and char.isascii()) or char in '-.':
- escaped += char
- else:
- escaped += '_'
- escaped += '.'.join(str(int(b)) for b in char.encode('utf8'))
- escaped += '_'
- ldir = _PATH_LOGS.joinpath(escaped)
- if not ldir.exists():
- ldir.mkdir(parents=True)
- assert ldir.is_dir()
- with ldir.joinpath(f'{self._last_today}.txt'
- ).open('a', encoding='utf8') as f:
+
+ def escaped(word: str) -> str:
+ ret = ''
+ for char in word:
+ if (char.isalpha() and char.isascii()) or char in '-.':
+ ret += char
+ else:
+ ret += '_'
+ ret += '.'.join(str(int(b)) for b in char.encode('utf8'))
+ ret += '_'
+ return ret
+ client_path = _PATH_LOGS.joinpath(escaped(self.client_id))
+ chat_path = client_path.joinpath(escaped(self._title))
+ if not chat_path.exists():
+ chat_path.mkdir(parents=True)
+ with chat_path.joinpath(f'{self._last_today}.txt'
+ ).open('a', encoding='utf8') as f:
f.write(msg + '\n')
def _send_msg(self, verb: str, params: tuple[str, ...]) -> None:
def __init__(self, chatname: str, get_nick_data: Callable, **kwargs
) -> None:
- self.chatname = chatname
self._get_nick_data = get_nick_data
super().__init__(**kwargs)
- self._title = f'{self.client_id} {self.chatname}'
+ self._title = chatname
self.set_prompt_prefix()
+ @property
+ def chatname(self) -> str:
+ 'Name of channel or user with whom we chat.'
+ return self._title
+
def set_prompt_prefix(self) -> None:
'Look up relevant DB data to update prompt prefix.'
self.prompt.set_prefix_data(self._get_nick_data())