def _cmd__prompt_enter(self) -> None:
if self._prompt:
- success = False
+ alert: Optional[str] = None
if len(self._prompt) > 1 and self._prompt[0] == '/':
toks = self._prompt[1:].split(maxsplit=1)
method_name = f'_cmd__{toks[0]}'
+ alert = f'{toks[0]} unknown'
if hasattr(self, method_name)\
and method_name != stack()[0].function:
method = getattr(self, method_name)
n_args_max = len(params)
n_args_min = len([p for p in params.values()
if p.default == inspect_empty])
+ alert = f'{toks[0]} needs {n_args_min} - {n_args_max} args'
if len(toks) == 1 and not n_args_min:
- success = method()
+ alert = method()
elif len(toks) > 1 and params\
and n_args_min <= len(toks[1].split()):
args = []
toks = toks[1].split(maxsplit=1)
args += [toks[0]]
n_args_max -= 1
- success = method(*args)
- if not success:
- self.broadcast('ALERT',
- f'invalid prompt command: {self._prompt}')
+ alert = method(*args)
+ else:
+ alert = 'not prefixed by /'
+ if alert:
+ self.broadcast('ALERT', f'invalid prompt command: {alert}')
self._prompt = ''
self._draw_prompt()
self._log.scroll_down()
self._draw_log()
- def _cmd__disconnect(self, quit_msg: str = 'ircplom says bye') -> bool:
+ def _cmd__disconnect(self, quit_msg: str = 'ircplom says bye') -> None:
self.broadcast('SEND', IrcMessage('QUIT', [quit_msg]))
- return True
- def _cmd__quit(self) -> bool:
+ def _cmd__quit(self) -> None:
self.broadcast('QUIT')
- return True
- def _cmd__buffer(self, buffer_idx_str: str) -> bool:
+ def _cmd__buffer(self, buffer_idx_str: str) -> Optional[str]:
if not buffer_idx_str.isdigit():
- return False
+ return f'not-integer buffer_idx: {buffer_idx_str}'
buffer_idx = int(buffer_idx_str)
- if 0 <= buffer_idx < len(self._logs):
- self._log_selected = buffer_idx
- self._draw_log()
- else:
- self.broadcast('ALERT', 'invalid buffer idx')
- return True
+ if buffer_idx < 0 or buffer_idx > len(self._logs):
+ return f'unavailable buffer idx: {buffer_idx}'
+ self._log_selected = buffer_idx
+ self._draw_log()
+ return None
def _calc_and_draw_all(self) -> None:
self._term.clear()