API Reference¶
-
class
command4bot.CommandsManager(setup_reg: command4bot.setup.SetupRegistry = None, command_reg: command4bot.command.BaseCommandRegistry = None, fallback_reg: command4bot.fallback.FallbackRegistry = None, config: Optional[command4bot.manager.Config] = None, **kwargs)¶ -
close(name: str) → None¶ Mark a command or group as closed.
- Parameters
name (str) – The name of the command or group to close.
-
command(command_func: F) → F¶ -
command(command_func: None = '...', *, keywords: Iterable[str] = '...', groups: Iterable[str] = '...') → Callable[[F], F] Decorator to register a command handler.
The command handler is called with the rest of the input (that is, without keyword it self), and optional keywords passed to
CommandsManager.exec, when input matches its keywords.The first non-empty line of the function’s docstring will be used as brief help string of the command. And the whole docstring will be used as full help string.
- Parameters
keywords (Iterable[str], optional) – Keywords for command. A keyword is a leading word of text input, separated with the rest part by a space. Defaults to the name of the comamnd function
groups (Iterable[str], optional) – Group names of the command, defaults to
[]
-
exec(content: str, **kwargs) → Any¶ Execute given text input
content- Parameters
content (str) – content to execute
- Returns
execution result
- Return type
Any
-
fallback(fallback_func: F) → F¶ -
fallback(fallback_func: None = '...', *, priority: int = '...') → Callable[[F], F] Decorator to register a fallback handler.
The fallback handlers registered are called in order of priority, with the original text input (
payload) and all other keyword parameters passed to CommandsManager.exec, until the handler returns something other thanNone, when there is no command found to handle the input.- Parameters
priority (int, optional) – Fallback handlers with higher priority will be called first, defaults to 10
-
get_possible_keywords_help(keyword: str) → List[str]¶ Get the help of keywords similar to
keyword.Used by
help_with_similar.- Parameters
keyword (str) – The misspelled keyword to find similar keywrod for.
- Returns
Brief help string of the similar commands.
- Return type
List[str]
-
help_with_similar(content: str) → str¶ Return helps with similar commands hint.
This is the default fallback handler and will be registered in
__init__.- Parameters
content (str) – The text input
- Returns
Help message
- Return type
str
-
open(name: str) → None¶ Mark a command or group as open.
- Parameters
name (str) – The name of the command or group to open.
-
setup(setup_func: F) → F¶ -
setup(setup_func: None = '...', *, enable_cache: bool = '...') → Callable[[F], F] Decorator to register a setup (a.k.a. ommand dependency).
This decorator can be used with or without parentheses.
-