def on_command(self, *args: Sequence[str], rest: str=None) -> Callable[[Callable], Callable]:
"""
Register a handler that's called when (the beginning of) a `IrcMessage` matches.
The handler is called with the `IrcMessage` as argument, must be a coroutine
and is run blocking, i.e. you cannot use `await_command` in it!
:param args: commands args that must match (the actual command is the first arg)
:param rest: match the rest (after the " :") of the `IrcMessage`
"""
def decorator(fn: Callable[[self.IrcMessage], None]):
ch = self.CommandHandler(args, rest, fn)
self._on_command_handlers.append(ch)
self._log.debug("Added command handler {}".format(ch))
return fn
return decorator
评论列表
文章目录