From 90e8c108ef4780720d86e2d26aad7c57c9ca30cb Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 9 Dec 2019 21:21:15 +0200 Subject: [PATCH] Add docs for command filter --- docs/dispatcher/filters/command.md | 32 ++++++++++++++++++++++++++++++ docs/dispatcher/filters/index.md | 1 + mkdocs.yml | 1 + 3 files changed, 34 insertions(+) create mode 100644 docs/dispatcher/filters/command.md diff --git a/docs/dispatcher/filters/command.md b/docs/dispatcher/filters/command.md new file mode 100644 index 00000000..5ce340c9 --- /dev/null +++ b/docs/dispatcher/filters/command.md @@ -0,0 +1,32 @@ +# Command + +This filter can be helpful for handling commands from the text messages. + +Works only with [Message](../../api/types/message.md) events which have the `text`. + +## Specification +| Argument | Type | Description | +| --- | --- | --- | +| `commands` | `#!python3 List[CommandPatterType]` | List of commands (string or compiled regexp patterns) | +| `commands_prefix` | `#!python3 str` | Prefix for command. Prefix is always is single char but here you can pass all of allowed prefixes, for example: `"/!"` will work with commands prefixed by `"/"` or `"!"` (Default: `"/"`). | +| `commands_ignore_case` | `#!python3 bool` | Ignore case (Does not work with regexp, use flags instead. Default: `False`) | +| `commands_ignore_mention` | `#!python3 bool` | Ignore bot mention. By default bot can not handle commands intended for other bots (Default: `False`) | + + +## Usage + +1. Filter single variant of commands: `#!python3 Command(commands=["start"])` +1. Handle command by regexp pattern: `#!python3 Command(commands=[re.compile(r"item_(\d+)")])` +1. Match command by multiple variants: `#!python3 Command(commands=["item", re.compile(r"item_(\d+)")])` +1. Handle commands in public chats intended for other bots: `#!python3 Command(commands=["command"], commands)` +1. As keyword argument in registerer: `#!python3 @router.message_handler(commands=["help"])` + +!!! warning + Command cannot include spaces or any whitespace + +## Allowed handlers + +Allowed update types for this filter: + +- `message` +- `edited_message` diff --git a/docs/dispatcher/filters/index.md b/docs/dispatcher/filters/index.md index 233bd767..5abe9eb4 100644 --- a/docs/dispatcher/filters/index.md +++ b/docs/dispatcher/filters/index.md @@ -12,6 +12,7 @@ Here is list of builtin filters and event types where it can be used: | Filter | update | message | edited_message | channel_post | edited_channel_post | inline_query | chosen_inline_result | callback_query | shipping_query | pre_checkout_query | poll | | --------------------------- |:------:|:-------:|:--------------:|:------------:|:-------------------:|:------------:|:--------------------:|:--------------:|:--------------:|:------------------:|:----:| | [Text](text.md) | | + | + | + | + | + | | + | | | + | +| [Command](command.md) | | + | | | | | | | | | | | | | | | | | | | | | | | diff --git a/mkdocs.yml b/mkdocs.yml index 4785f845..de32210b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -225,6 +225,7 @@ nav: - Filters: - dispatcher/filters/index.md - dispatcher/filters/text.md + - dispatcher/filters/command.md - Class based handlers: - dispatcher/class_based_handlers/basics.md - dispatcher/class_based_handlers/message.md