telegrinder 0.2.0.post2__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of telegrinder might be problematic. Click here for more details.
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/PKG-INFO +3 -4
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/pyproject.toml +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/readme.md +2 -3
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/__init__.py +26 -7
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/__init__.py +16 -4
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/message.py +18 -11
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/__init__.py +18 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/abc.py +1 -1
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/context.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/dispatch.py +1 -1
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/__init__.py +21 -0
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/audio_reply.py +44 -0
- telegrinder-0.2.0.post2/telegrinder/bot/dispatch/handler/message_reply.py → telegrinder-0.2.2/telegrinder/bot/dispatch/handler/base.py +15 -17
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/document_reply.py +44 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/handler/func.py +3 -3
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/media_group_reply.py +43 -0
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/message_reply.py +36 -0
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/photo_reply.py +44 -0
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/sticker_reply.py +37 -0
- telegrinder-0.2.2/telegrinder/bot/dispatch/handler/video_reply.py +44 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/process.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/return_manager/abc.py +11 -8
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/return_manager/callback_query.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/return_manager/inline_query.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/return_manager/message.py +3 -3
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/__init__.py +2 -1
- telegrinder-0.2.2/telegrinder/bot/dispatch/view/abc.py +43 -0
- telegrinder-0.2.0.post2/telegrinder/bot/dispatch/view/abc.py → telegrinder-0.2.2/telegrinder/bot/dispatch/view/base.py +21 -43
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/callback_query.py +3 -3
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/chat_join_request.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/chat_member.py +2 -3
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/inline_query.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/message.py +5 -4
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/raw.py +4 -3
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/waiter_machine/machine.py +18 -7
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/waiter_machine/middleware.py +0 -8
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/waiter_machine/short_state.py +1 -1
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/polling/polling.py +5 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/__init__.py +5 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/abc.py +6 -5
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/integer.py +1 -1
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/is_from.py +19 -0
- telegrinder-0.2.2/telegrinder/bot/rules/state.py +37 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/scenario/checkbox.py +3 -3
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/scenario/choice.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/client/aiohttp.py +5 -7
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/model.py +1 -8
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/modules.py +16 -25
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/msgspec_utils.py +5 -5
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/base.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/composer.py +5 -9
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/container.py +6 -1
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/polymorphic.py +7 -7
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/rule.py +6 -4
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/source.py +4 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/tools/generator.py +7 -6
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/__init__.py +11 -7
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/loop_wrapper/loop_wrapper.py +4 -5
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/magic.py +17 -19
- telegrinder-0.2.2/telegrinder/tools/state_storage/__init__.py +4 -0
- telegrinder-0.2.2/telegrinder/tools/state_storage/abc.py +35 -0
- telegrinder-0.2.2/telegrinder/tools/state_storage/memory.py +25 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/types/__init__.py +1 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/types/methods.py +12 -4
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/types/objects.py +57 -6
- telegrinder-0.2.0.post2/telegrinder/bot/dispatch/handler/__init__.py +0 -5
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/LICENSE +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/api/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/api/api.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/api/error.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/api/response.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/api/token.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/bot.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/base.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/callback_query.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/chat_join_request.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/chat_member_updated.py +1 -1
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/inline_query.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/update.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/cute_types/utils.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/handler/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/middleware/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/middleware/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/return_manager/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/view/box.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/dispatch/waiter_machine/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/polling/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/polling/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/adapter/__init__.py +1 -1
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/adapter/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/adapter/errors.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/adapter/event.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/adapter/node.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/adapter/raw_update.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/callback_data.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/chat_join.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/command.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/enum_text.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/func.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/fuzzy.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/inline.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/markup.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/mention.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/message.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/message_entities.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/node.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/regex.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/rule_enum.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/start.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/text.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/rules/update.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/scenario/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/bot/scenario/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/client/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/client/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/msgspec_json.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/attachment.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/callback_query.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/command.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/event.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/me.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/message.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/scope.py +3 -3
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/text.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/tools/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/node/update.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/py.typed +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/rules.py +2 -2
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/buttons.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/error_handler/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/error_handler/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/error_handler/error.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/error_handler/error_handler.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/formatting/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/formatting/html.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/formatting/links.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/formatting/spec_html_formats.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/global_context/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/global_context/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/global_context/global_context.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/global_context/telegrinder_ctx.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/i18n/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/i18n/base.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/i18n/middleware/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/i18n/middleware/base.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/i18n/simple.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/kb_set/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/kb_set/base.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/kb_set/yaml.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/keyboard.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/limited_dict.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/loop_wrapper/__init__.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/loop_wrapper/abc.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/tools/parse_mode.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/types/enums.py +0 -0
- {telegrinder-0.2.0.post2 → telegrinder-0.2.2}/telegrinder/verification_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: telegrinder
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Modern visionary telegram bot framework.
|
|
5
5
|
Home-page: https://github.com/timoniq/telegrinder
|
|
6
6
|
License: MIT
|
|
@@ -45,6 +45,7 @@ Still in development.
|
|
|
45
45
|
* Ready to use scenarios and rules
|
|
46
46
|
* Fast models built on msgspec
|
|
47
47
|
* Both low-level and high-level API
|
|
48
|
+
* Support [optional dependecies](https://github.com/timoniq/telegrinder/blob/dev/docs/guide/optional_dependencies.md)
|
|
48
49
|
|
|
49
50
|
# Getting started
|
|
50
51
|
|
|
@@ -85,9 +86,7 @@ logger.set_level("INFO")
|
|
|
85
86
|
@bot.on.message(Text("/start"))
|
|
86
87
|
async def start(message: Message):
|
|
87
88
|
me = (await api.get_me()).unwrap()
|
|
88
|
-
await message.answer(
|
|
89
|
-
f"Hello, {message.from_user.full_name}! I'm {me.full_name}."
|
|
90
|
-
)
|
|
89
|
+
await message.answer(f"Hello, {message.from_user.full_name}! I'm {me.full_name}.")
|
|
91
90
|
|
|
92
91
|
|
|
93
92
|
bot.run_forever()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "telegrinder"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "Modern visionary telegram bot framework."
|
|
5
5
|
authors = ["timoniq <tesseradecades@mail.ru>"]
|
|
6
6
|
maintainers = ["luwqz1 <howluwqz1@gmail.com>"]
|
|
@@ -58,7 +58,7 @@ ruff = ">=0.5,<0.7"
|
|
|
58
58
|
basedpyright = "^1.12.1"
|
|
59
59
|
sort-all = "1.2.0"
|
|
60
60
|
pytest = "^8.0.0"
|
|
61
|
-
pytest-asyncio = "
|
|
61
|
+
pytest-asyncio = ">=0.23.5,<0.25.0"
|
|
62
62
|
pytest-cov = "^5.0.0"
|
|
63
63
|
pytest-mock = "^3.10.0"
|
|
64
64
|
|
|
@@ -9,6 +9,7 @@ Still in development.
|
|
|
9
9
|
* Ready to use scenarios and rules
|
|
10
10
|
* Fast models built on msgspec
|
|
11
11
|
* Both low-level and high-level API
|
|
12
|
+
* Support [optional dependecies](https://github.com/timoniq/telegrinder/blob/dev/docs/guide/optional_dependencies.md)
|
|
12
13
|
|
|
13
14
|
# Getting started
|
|
14
15
|
|
|
@@ -49,9 +50,7 @@ logger.set_level("INFO")
|
|
|
49
50
|
@bot.on.message(Text("/start"))
|
|
50
51
|
async def start(message: Message):
|
|
51
52
|
me = (await api.get_me()).unwrap()
|
|
52
|
-
await message.answer(
|
|
53
|
-
f"Hello, {message.from_user.full_name}! I'm {me.full_name}."
|
|
54
|
-
)
|
|
53
|
+
await message.answer(f"Hello, {message.from_user.full_name}! I'm {me.full_name}.")
|
|
55
54
|
|
|
56
55
|
|
|
57
56
|
bot.run_forever()
|
|
@@ -7,6 +7,7 @@ Modern visionary telegram bot framework.
|
|
|
7
7
|
* Ready to use scenarios and rules
|
|
8
8
|
* Fast models built on msgspec
|
|
9
9
|
* Both low-level and high-level API
|
|
10
|
+
* Support [optional dependecies](https://github.com/timoniq/telegrinder/blob/dev/docs/guide/optional_dependencies.md)
|
|
10
11
|
|
|
11
12
|
Basic example:
|
|
12
13
|
|
|
@@ -23,9 +24,7 @@ logger.set_level("INFO")
|
|
|
23
24
|
@bot.on.message(Text("/start"))
|
|
24
25
|
async def start(message: Message):
|
|
25
26
|
me = (await api.get_me()).unwrap()
|
|
26
|
-
await message.answer(
|
|
27
|
-
f"Hello, {message.from_user.full_name}! I'm {me.full_name}."
|
|
28
|
-
)
|
|
27
|
+
await message.answer(f"Hello, {message.from_user.full_name}! I'm {me.full_name}.")
|
|
29
28
|
|
|
30
29
|
|
|
31
30
|
bot.run_forever()
|
|
@@ -45,6 +44,7 @@ from .bot import (
|
|
|
45
44
|
ABCScenario,
|
|
46
45
|
ABCStateView,
|
|
47
46
|
ABCView,
|
|
47
|
+
AudioReplyHandler,
|
|
48
48
|
BaseCute,
|
|
49
49
|
BaseReturnManager,
|
|
50
50
|
BaseStateView,
|
|
@@ -60,25 +60,32 @@ from .bot import (
|
|
|
60
60
|
ChatMemberView,
|
|
61
61
|
Checkbox,
|
|
62
62
|
Choice,
|
|
63
|
+
Context,
|
|
63
64
|
Dispatch,
|
|
65
|
+
DocumentReplyHandler,
|
|
64
66
|
FuncHandler,
|
|
65
67
|
InlineQueryCute,
|
|
66
68
|
InlineQueryReturnManager,
|
|
67
69
|
InlineQueryRule,
|
|
70
|
+
MediaGroupReplyHandler,
|
|
68
71
|
MessageCute,
|
|
69
72
|
MessageReplyHandler,
|
|
70
73
|
MessageReturnManager,
|
|
71
74
|
MessageRule,
|
|
72
75
|
MessageView,
|
|
76
|
+
PhotoReplyHandler,
|
|
73
77
|
Polling,
|
|
74
78
|
RawEventView,
|
|
75
79
|
ShortState,
|
|
80
|
+
StickerReplyHandler,
|
|
76
81
|
Telegrinder,
|
|
77
82
|
UpdateCute,
|
|
83
|
+
VideoReplyHandler,
|
|
78
84
|
ViewBox,
|
|
79
85
|
WaiterMachine,
|
|
80
86
|
register_manager,
|
|
81
87
|
)
|
|
88
|
+
from .bot.rules import StateMeta
|
|
82
89
|
from .client import ABCClient, AiohttpClient
|
|
83
90
|
from .model import Model
|
|
84
91
|
from .modules import logger
|
|
@@ -86,6 +93,7 @@ from .tools import (
|
|
|
86
93
|
ABCErrorHandler,
|
|
87
94
|
ABCGlobalContext,
|
|
88
95
|
ABCLoopWrapper,
|
|
96
|
+
ABCStateStorage,
|
|
89
97
|
ABCTranslator,
|
|
90
98
|
ABCTranslatorMiddleware,
|
|
91
99
|
AnyMarkup,
|
|
@@ -104,10 +112,12 @@ from .tools import (
|
|
|
104
112
|
KeyboardSetYAML,
|
|
105
113
|
Lifespan,
|
|
106
114
|
LoopWrapper,
|
|
115
|
+
MemoryStateStorage,
|
|
107
116
|
ParseMode,
|
|
108
117
|
RowButtons,
|
|
109
118
|
SimpleI18n,
|
|
110
119
|
SimpleTranslator,
|
|
120
|
+
StateData,
|
|
111
121
|
ctx_var,
|
|
112
122
|
magic_bundle,
|
|
113
123
|
)
|
|
@@ -122,7 +132,6 @@ Bot: typing.TypeAlias = Telegrinder
|
|
|
122
132
|
|
|
123
133
|
|
|
124
134
|
__all__ = (
|
|
125
|
-
"API",
|
|
126
135
|
"ABCClient",
|
|
127
136
|
"ABCDispatch",
|
|
128
137
|
"ABCErrorHandler",
|
|
@@ -134,6 +143,7 @@ __all__ = (
|
|
|
134
143
|
"ABCReturnManager",
|
|
135
144
|
"ABCRule",
|
|
136
145
|
"ABCScenario",
|
|
146
|
+
"ABCStateStorage",
|
|
137
147
|
"ABCStateView",
|
|
138
148
|
"ABCTranslator",
|
|
139
149
|
"ABCTranslatorMiddleware",
|
|
@@ -152,17 +162,17 @@ __all__ = (
|
|
|
152
162
|
"CallbackQuery",
|
|
153
163
|
"CallbackQueryCute",
|
|
154
164
|
"CallbackQueryReturnManager",
|
|
165
|
+
"CallbackQueryRule",
|
|
155
166
|
"CallbackQueryView",
|
|
156
167
|
"ChatJoinRequest",
|
|
157
168
|
"ChatJoinRequestCute",
|
|
158
|
-
"CallbackQueryRule",
|
|
159
169
|
"ChatJoinRequestRule",
|
|
160
|
-
"InlineQueryRule",
|
|
161
170
|
"ChatJoinRequestView",
|
|
162
171
|
"ChatMemberUpdated",
|
|
163
172
|
"ChatMemberUpdatedCute",
|
|
164
173
|
"ChatMemberView",
|
|
165
174
|
"Checkbox",
|
|
175
|
+
"Choice",
|
|
166
176
|
"CtxVar",
|
|
167
177
|
"DelayedTask",
|
|
168
178
|
"Dispatch",
|
|
@@ -177,34 +187,43 @@ __all__ = (
|
|
|
177
187
|
"InlineQuery",
|
|
178
188
|
"InlineQueryCute",
|
|
179
189
|
"InlineQueryReturnManager",
|
|
190
|
+
"InlineQueryRule",
|
|
180
191
|
"Keyboard",
|
|
181
192
|
"KeyboardSetBase",
|
|
182
193
|
"KeyboardSetYAML",
|
|
183
194
|
"Lifespan",
|
|
184
195
|
"LoopWrapper",
|
|
196
|
+
"MediaGroupReplyHandler",
|
|
197
|
+
"MemoryStateStorage",
|
|
185
198
|
"Message",
|
|
186
199
|
"MessageCute",
|
|
187
200
|
"MessageReplyHandler",
|
|
201
|
+
"MessageReplyHandler",
|
|
188
202
|
"MessageReturnManager",
|
|
189
203
|
"MessageRule",
|
|
190
204
|
"MessageView",
|
|
191
205
|
"Model",
|
|
192
206
|
"ParseMode",
|
|
207
|
+
"PhotoReplyHandler",
|
|
193
208
|
"Polling",
|
|
194
209
|
"RawEventView",
|
|
195
210
|
"RowButtons",
|
|
196
211
|
"ShortState",
|
|
197
212
|
"SimpleI18n",
|
|
198
213
|
"SimpleTranslator",
|
|
199
|
-
"
|
|
214
|
+
"StateData",
|
|
215
|
+
"StateMeta",
|
|
216
|
+
"StickerReplyHandler",
|
|
200
217
|
"Telegrinder",
|
|
201
218
|
"Token",
|
|
202
219
|
"Update",
|
|
203
220
|
"UpdateCute",
|
|
221
|
+
"VideoReplyHandler",
|
|
204
222
|
"ViewBox",
|
|
205
223
|
"WaiterMachine",
|
|
206
224
|
"ctx_var",
|
|
207
225
|
"logger",
|
|
208
226
|
"magic_bundle",
|
|
209
227
|
"register_manager",
|
|
228
|
+
"Context",
|
|
210
229
|
)
|
|
@@ -15,6 +15,7 @@ from telegrinder.bot.dispatch import (
|
|
|
15
15
|
ABCReturnManager,
|
|
16
16
|
ABCStateView,
|
|
17
17
|
ABCView,
|
|
18
|
+
AudioReplyHandler,
|
|
18
19
|
BaseReturnManager,
|
|
19
20
|
BaseStateView,
|
|
20
21
|
BaseView,
|
|
@@ -24,14 +25,19 @@ from telegrinder.bot.dispatch import (
|
|
|
24
25
|
ChatMemberView,
|
|
25
26
|
Context,
|
|
26
27
|
Dispatch,
|
|
28
|
+
DocumentReplyHandler,
|
|
27
29
|
FuncHandler,
|
|
28
30
|
InlineQueryReturnManager,
|
|
29
31
|
Manager,
|
|
32
|
+
MediaGroupReplyHandler,
|
|
30
33
|
MessageReplyHandler,
|
|
31
34
|
MessageReturnManager,
|
|
32
35
|
MessageView,
|
|
36
|
+
PhotoReplyHandler,
|
|
33
37
|
RawEventView,
|
|
34
38
|
ShortState,
|
|
39
|
+
StickerReplyHandler,
|
|
40
|
+
VideoReplyHandler,
|
|
35
41
|
ViewBox,
|
|
36
42
|
WaiterMachine,
|
|
37
43
|
clear_wm_storage_worker,
|
|
@@ -57,6 +63,7 @@ __all__ = (
|
|
|
57
63
|
"ABCScenario",
|
|
58
64
|
"ABCStateView",
|
|
59
65
|
"ABCView",
|
|
66
|
+
"AudioReplyHandler",
|
|
60
67
|
"BaseCute",
|
|
61
68
|
"BaseReturnManager",
|
|
62
69
|
"BaseStateView",
|
|
@@ -65,32 +72,37 @@ __all__ = (
|
|
|
65
72
|
"CallbackQueryReturnManager",
|
|
66
73
|
"CallbackQueryRule",
|
|
67
74
|
"CallbackQueryView",
|
|
68
|
-
"ChatJoinRequestRule",
|
|
69
|
-
"InlineQueryRule",
|
|
70
75
|
"ChatJoinRequestCute",
|
|
76
|
+
"ChatJoinRequestRule",
|
|
71
77
|
"ChatJoinRequestView",
|
|
72
78
|
"ChatMemberUpdatedCute",
|
|
73
79
|
"ChatMemberView",
|
|
74
80
|
"Checkbox",
|
|
81
|
+
"Choice",
|
|
75
82
|
"Context",
|
|
76
83
|
"Dispatch",
|
|
84
|
+
"DocumentReplyHandler",
|
|
77
85
|
"FuncHandler",
|
|
78
86
|
"InlineQueryCute",
|
|
79
87
|
"InlineQueryReturnManager",
|
|
88
|
+
"InlineQueryRule",
|
|
80
89
|
"Manager",
|
|
90
|
+
"MediaGroupReplyHandler",
|
|
81
91
|
"MessageCute",
|
|
82
92
|
"MessageReplyHandler",
|
|
83
93
|
"MessageReturnManager",
|
|
84
94
|
"MessageRule",
|
|
85
95
|
"MessageView",
|
|
96
|
+
"PhotoReplyHandler",
|
|
86
97
|
"Polling",
|
|
87
98
|
"RawEventView",
|
|
88
99
|
"ShortState",
|
|
89
|
-
"
|
|
100
|
+
"StickerReplyHandler",
|
|
90
101
|
"Telegrinder",
|
|
91
102
|
"UpdateCute",
|
|
103
|
+
"VideoReplyHandler",
|
|
92
104
|
"ViewBox",
|
|
93
105
|
"WaiterMachine",
|
|
94
|
-
"register_manager",
|
|
95
106
|
"clear_wm_storage_worker",
|
|
107
|
+
"register_manager",
|
|
96
108
|
)
|
|
@@ -42,7 +42,6 @@ if typing.TYPE_CHECKING:
|
|
|
42
42
|
|
|
43
43
|
from telegrinder.bot.cute_types.callback_query import CallbackQueryCute
|
|
44
44
|
|
|
45
|
-
|
|
46
45
|
MediaType: typing.TypeAlias = typing.Literal[
|
|
47
46
|
"animation",
|
|
48
47
|
"audio",
|
|
@@ -50,6 +49,7 @@ MediaType: typing.TypeAlias = typing.Literal[
|
|
|
50
49
|
"photo",
|
|
51
50
|
"video",
|
|
52
51
|
]
|
|
52
|
+
InputMediaType: typing.TypeAlias = InputMedia | tuple[MediaType, InputFile | str]
|
|
53
53
|
ReplyMarkup: typing.TypeAlias = InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply
|
|
54
54
|
|
|
55
55
|
|
|
@@ -1676,14 +1676,14 @@ class MessageCute(BaseCute[Message], Message, kw_only=True):
|
|
|
1676
1676
|
)
|
|
1677
1677
|
async def answer_media_group(
|
|
1678
1678
|
self,
|
|
1679
|
-
media:
|
|
1679
|
+
media: InputMediaType | list[InputMediaType],
|
|
1680
1680
|
chat_id: int | str | None = None,
|
|
1681
1681
|
business_connection_id: str | None = None,
|
|
1682
1682
|
message_thread_id: int | None = None,
|
|
1683
1683
|
message_effect_id: str | None = None,
|
|
1684
|
-
caption: str | None = None,
|
|
1685
|
-
parse_mode: str | None = None,
|
|
1686
|
-
caption_entities: list[MessageEntity] | None = None,
|
|
1684
|
+
caption: str | list[str] | None = None,
|
|
1685
|
+
parse_mode: str | list[str] | None = None,
|
|
1686
|
+
caption_entities: list[MessageEntity] | list[list[MessageEntity]] | None = None,
|
|
1687
1687
|
disable_notification: bool | None = None,
|
|
1688
1688
|
protect_content: bool | None = None,
|
|
1689
1689
|
reply_parameters: ReplyParameters | dict[str, typing.Any] | None = None,
|
|
@@ -1724,7 +1724,14 @@ class MessageCute(BaseCute[Message], Message, kw_only=True):
|
|
|
1724
1724
|
|
|
1725
1725
|
:param reply_parameters: Description of the message to reply to."""
|
|
1726
1726
|
|
|
1727
|
+
media = [media] if not isinstance(media, list) else media
|
|
1727
1728
|
params = get_params(locals())
|
|
1729
|
+
caption_entities_lst = typing.cast(
|
|
1730
|
+
list[list[MessageEntity]],
|
|
1731
|
+
[caption_entities]
|
|
1732
|
+
if caption_entities and len(caption_entities) == 1 and not isinstance(caption_entities[0], list)
|
|
1733
|
+
else caption_entities,
|
|
1734
|
+
)
|
|
1728
1735
|
|
|
1729
1736
|
for i, m in enumerate(media[:]):
|
|
1730
1737
|
if isinstance(m, tuple):
|
|
@@ -1732,9 +1739,9 @@ class MessageCute(BaseCute[Message], Message, kw_only=True):
|
|
|
1732
1739
|
i,
|
|
1733
1740
|
input_media( # type: ignore
|
|
1734
1741
|
*media.pop(i), # type: ignore
|
|
1735
|
-
caption=caption,
|
|
1736
|
-
caption_entities=
|
|
1737
|
-
parse_mode=parse_mode,
|
|
1742
|
+
caption=caption if not isinstance(caption, list) else caption[i],
|
|
1743
|
+
caption_entities=caption_entities_lst[i] if caption_entities_lst else None,
|
|
1744
|
+
parse_mode=parse_mode if not isinstance(parse_mode, list) else parse_mode[i],
|
|
1738
1745
|
),
|
|
1739
1746
|
)
|
|
1740
1747
|
|
|
@@ -2873,13 +2880,13 @@ class MessageCute(BaseCute[Message], Message, kw_only=True):
|
|
|
2873
2880
|
)
|
|
2874
2881
|
async def reply_media_group(
|
|
2875
2882
|
self,
|
|
2876
|
-
media:
|
|
2883
|
+
media: InputMediaType | list[InputMediaType],
|
|
2877
2884
|
chat_id: int | str | None = None,
|
|
2878
2885
|
business_connection_id: str | None = None,
|
|
2879
2886
|
message_thread_id: int | None = None,
|
|
2880
2887
|
message_effect_id: str | None = None,
|
|
2881
|
-
caption: str | None = None,
|
|
2882
|
-
parse_mode: str | None = None,
|
|
2888
|
+
caption: str | list[str] | None = None,
|
|
2889
|
+
parse_mode: str | list[str] | None = None,
|
|
2883
2890
|
caption_entities: list[MessageEntity] | None = None,
|
|
2884
2891
|
disable_notification: bool | None = None,
|
|
2885
2892
|
protect_content: bool | None = None,
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
from telegrinder.bot.dispatch.abc import ABCDispatch
|
|
2
2
|
from telegrinder.bot.dispatch.context import Context
|
|
3
3
|
from telegrinder.bot.dispatch.dispatch import Dispatch, TelegrinderContext
|
|
4
|
-
from telegrinder.bot.dispatch.handler import
|
|
4
|
+
from telegrinder.bot.dispatch.handler import (
|
|
5
|
+
ABCHandler,
|
|
6
|
+
AudioReplyHandler,
|
|
7
|
+
DocumentReplyHandler,
|
|
8
|
+
FuncHandler,
|
|
9
|
+
MediaGroupReplyHandler,
|
|
10
|
+
MessageReplyHandler,
|
|
11
|
+
PhotoReplyHandler,
|
|
12
|
+
StickerReplyHandler,
|
|
13
|
+
VideoReplyHandler,
|
|
14
|
+
)
|
|
5
15
|
from telegrinder.bot.dispatch.middleware import ABCMiddleware
|
|
6
16
|
from telegrinder.bot.dispatch.process import check_rule, process_inner
|
|
7
17
|
from telegrinder.bot.dispatch.return_manager import (
|
|
@@ -35,6 +45,7 @@ __all__ = (
|
|
|
35
45
|
"ABCReturnManager",
|
|
36
46
|
"ABCStateView",
|
|
37
47
|
"ABCView",
|
|
48
|
+
"AudioReplyHandler",
|
|
38
49
|
"BaseReturnManager",
|
|
39
50
|
"BaseStateView",
|
|
40
51
|
"BaseView",
|
|
@@ -44,20 +55,25 @@ __all__ = (
|
|
|
44
55
|
"ChatMemberView",
|
|
45
56
|
"Context",
|
|
46
57
|
"Dispatch",
|
|
58
|
+
"DocumentReplyHandler",
|
|
47
59
|
"FuncHandler",
|
|
48
60
|
"InlineQueryReturnManager",
|
|
49
61
|
"InlineQueryView",
|
|
50
62
|
"Manager",
|
|
63
|
+
"MediaGroupReplyHandler",
|
|
51
64
|
"MessageReplyHandler",
|
|
52
65
|
"MessageReturnManager",
|
|
53
66
|
"MessageView",
|
|
67
|
+
"PhotoReplyHandler",
|
|
54
68
|
"RawEventView",
|
|
55
69
|
"ShortState",
|
|
70
|
+
"StickerReplyHandler",
|
|
56
71
|
"TelegrinderContext",
|
|
72
|
+
"VideoReplyHandler",
|
|
57
73
|
"ViewBox",
|
|
58
74
|
"WaiterMachine",
|
|
59
75
|
"check_rule",
|
|
76
|
+
"clear_wm_storage_worker",
|
|
60
77
|
"process_inner",
|
|
61
78
|
"register_manager",
|
|
62
|
-
"clear_wm_storage_worker",
|
|
63
79
|
)
|
|
@@ -2,7 +2,7 @@ import enum
|
|
|
2
2
|
import typing
|
|
3
3
|
from reprlib import recursive_repr
|
|
4
4
|
|
|
5
|
-
from telegrinder.types import Update
|
|
5
|
+
from telegrinder.types.objects import Update
|
|
6
6
|
|
|
7
7
|
T = typing.TypeVar("T")
|
|
8
8
|
|
|
@@ -63,7 +63,7 @@ class Context(dict[str, AnyValue]):
|
|
|
63
63
|
return key if isinstance(key, str) else str(key.value)
|
|
64
64
|
|
|
65
65
|
def copy(self) -> typing.Self:
|
|
66
|
-
return self.__class__(**self)
|
|
66
|
+
return self.__class__(**dict.copy(self))
|
|
67
67
|
|
|
68
68
|
def set(self, key: Key, value: AnyValue) -> None:
|
|
69
69
|
self[key] = value
|
|
@@ -3,7 +3,7 @@ import typing
|
|
|
3
3
|
|
|
4
4
|
from vbml.patcher import Patcher
|
|
5
5
|
|
|
6
|
-
from telegrinder.api import API
|
|
6
|
+
from telegrinder.api.api import API
|
|
7
7
|
from telegrinder.bot.cute_types.base import BaseCute
|
|
8
8
|
from telegrinder.bot.cute_types.update import UpdateCute
|
|
9
9
|
from telegrinder.bot.dispatch.abc import ABCDispatch
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
2
|
+
from telegrinder.bot.dispatch.handler.audio_reply import AudioReplyHandler
|
|
3
|
+
from telegrinder.bot.dispatch.handler.document_reply import DocumentReplyHandler
|
|
4
|
+
from telegrinder.bot.dispatch.handler.func import FuncHandler
|
|
5
|
+
from telegrinder.bot.dispatch.handler.media_group_reply import MediaGroupReplyHandler
|
|
6
|
+
from telegrinder.bot.dispatch.handler.message_reply import MessageReplyHandler
|
|
7
|
+
from telegrinder.bot.dispatch.handler.photo_reply import PhotoReplyHandler
|
|
8
|
+
from telegrinder.bot.dispatch.handler.sticker_reply import StickerReplyHandler
|
|
9
|
+
from telegrinder.bot.dispatch.handler.video_reply import VideoReplyHandler
|
|
10
|
+
|
|
11
|
+
__all__ = (
|
|
12
|
+
"ABCHandler",
|
|
13
|
+
"AudioReplyHandler",
|
|
14
|
+
"DocumentReplyHandler",
|
|
15
|
+
"FuncHandler",
|
|
16
|
+
"MediaGroupReplyHandler",
|
|
17
|
+
"MessageReplyHandler",
|
|
18
|
+
"PhotoReplyHandler",
|
|
19
|
+
"StickerReplyHandler",
|
|
20
|
+
"VideoReplyHandler",
|
|
21
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from telegrinder.api.api import API
|
|
4
|
+
from telegrinder.bot.cute_types.message import MessageCute
|
|
5
|
+
from telegrinder.bot.dispatch.context import Context
|
|
6
|
+
from telegrinder.bot.dispatch.handler.base import BaseReplyHandler
|
|
7
|
+
from telegrinder.bot.rules.abc import ABCRule
|
|
8
|
+
from telegrinder.types.objects import InputFile
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AudioReplyHandler(BaseReplyHandler):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
audio: InputFile | str,
|
|
15
|
+
*rules: ABCRule,
|
|
16
|
+
caption: str | None = None,
|
|
17
|
+
parse_mode: str | None = None,
|
|
18
|
+
is_blocking: bool = True,
|
|
19
|
+
as_reply: bool = False,
|
|
20
|
+
preset_context: Context | None = None,
|
|
21
|
+
**default_params: typing.Any,
|
|
22
|
+
) -> None:
|
|
23
|
+
self.audio = audio
|
|
24
|
+
self.parse_mode = parse_mode
|
|
25
|
+
self.caption = caption
|
|
26
|
+
super().__init__(
|
|
27
|
+
*rules,
|
|
28
|
+
is_blocking=is_blocking,
|
|
29
|
+
as_reply=as_reply,
|
|
30
|
+
preset_context=preset_context,
|
|
31
|
+
**default_params,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
async def run(self, _: API, event: MessageCute, __: Context) -> typing.Any:
|
|
35
|
+
method = event.answer_audio if not self.as_reply else event.reply_audio
|
|
36
|
+
await method(
|
|
37
|
+
audio=self.audio,
|
|
38
|
+
parse_mode=self.parse_mode,
|
|
39
|
+
caption=self.caption,
|
|
40
|
+
**self.default_params,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
__all__ = ("AudioReplyHandler",)
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
+
import abc
|
|
1
2
|
import typing
|
|
2
3
|
|
|
4
|
+
from fntypes.result import Result
|
|
5
|
+
|
|
3
6
|
from telegrinder.api.api import API
|
|
7
|
+
from telegrinder.api.error import APIError
|
|
4
8
|
from telegrinder.bot.cute_types.message import MessageCute
|
|
5
9
|
from telegrinder.bot.dispatch.context import Context
|
|
6
10
|
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
7
11
|
from telegrinder.bot.dispatch.process import check_rule
|
|
8
12
|
from telegrinder.bot.rules.abc import ABCRule
|
|
9
13
|
from telegrinder.modules import logger
|
|
10
|
-
from telegrinder.types.objects import
|
|
14
|
+
from telegrinder.types.objects import Update
|
|
15
|
+
|
|
16
|
+
APIMethod: typing.TypeAlias = typing.Callable[
|
|
17
|
+
typing.Concatenate[MessageCute, ...], typing.Awaitable[Result[typing.Any, APIError]]
|
|
18
|
+
]
|
|
11
19
|
|
|
12
20
|
|
|
13
|
-
class
|
|
21
|
+
class BaseReplyHandler(ABCHandler[MessageCute], abc.ABC):
|
|
14
22
|
def __init__(
|
|
15
23
|
self,
|
|
16
|
-
text: str,
|
|
17
24
|
*rules: ABCRule,
|
|
18
25
|
is_blocking: bool = True,
|
|
19
26
|
as_reply: bool = False,
|
|
20
27
|
preset_context: Context | None = None,
|
|
21
28
|
**default_params: typing.Any,
|
|
22
29
|
) -> None:
|
|
23
|
-
self.text = text
|
|
24
30
|
self.rules = list(rules)
|
|
25
31
|
self.as_reply = as_reply
|
|
26
32
|
self.is_blocking = is_blocking
|
|
@@ -28,12 +34,7 @@ class MessageReplyHandler(ABCHandler[MessageCute]):
|
|
|
28
34
|
self.preset_context = preset_context or Context()
|
|
29
35
|
|
|
30
36
|
def __repr__(self) -> str:
|
|
31
|
-
return "<{}
|
|
32
|
-
("blocking " if self.is_blocking else "") + self.__class__.__name__,
|
|
33
|
-
self.rules,
|
|
34
|
-
"answer text as reply" if self.as_reply else "answer text",
|
|
35
|
-
self.text,
|
|
36
|
-
)
|
|
37
|
+
return f"<{self.__class__.__qualname__}>"
|
|
37
38
|
|
|
38
39
|
async def check(self, api: API, event: Update, ctx: Context | None = None) -> bool:
|
|
39
40
|
ctx = Context(raw_update=event) if ctx is None else ctx
|
|
@@ -48,12 +49,9 @@ class MessageReplyHandler(ABCHandler[MessageCute]):
|
|
|
48
49
|
ctx |= temp_ctx
|
|
49
50
|
return True
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
reply_parameters=ReplyParameters(event.message_id) if self.as_reply else None,
|
|
55
|
-
**self.default_params,
|
|
56
|
-
)
|
|
52
|
+
@abc.abstractmethod
|
|
53
|
+
async def run(self, api: API, event: MessageCute, ctx: Context) -> typing.Any:
|
|
54
|
+
pass
|
|
57
55
|
|
|
58
56
|
|
|
59
|
-
__all__ = ("
|
|
57
|
+
__all__ = ("BaseReplyHandler",)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from telegrinder.api.api import API
|
|
4
|
+
from telegrinder.bot.cute_types.message import MessageCute
|
|
5
|
+
from telegrinder.bot.dispatch.context import Context
|
|
6
|
+
from telegrinder.bot.dispatch.handler.base import BaseReplyHandler
|
|
7
|
+
from telegrinder.bot.rules.abc import ABCRule
|
|
8
|
+
from telegrinder.types.objects import InputFile
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DocumentReplyHandler(BaseReplyHandler):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
document: InputFile | str,
|
|
15
|
+
*rules: ABCRule,
|
|
16
|
+
caption: str | None = None,
|
|
17
|
+
parse_mode: str | None = None,
|
|
18
|
+
is_blocking: bool = True,
|
|
19
|
+
as_reply: bool = False,
|
|
20
|
+
preset_context: Context | None = None,
|
|
21
|
+
**default_params: typing.Any,
|
|
22
|
+
) -> None:
|
|
23
|
+
self.document = document
|
|
24
|
+
self.parse_mode = parse_mode
|
|
25
|
+
self.caption = caption
|
|
26
|
+
super().__init__(
|
|
27
|
+
*rules,
|
|
28
|
+
is_blocking=is_blocking,
|
|
29
|
+
as_reply=as_reply,
|
|
30
|
+
preset_context=preset_context,
|
|
31
|
+
**default_params,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
async def run(self, _: API, event: MessageCute, __: Context) -> typing.Any:
|
|
35
|
+
method = event.answer_document if not self.as_reply else event.reply_document
|
|
36
|
+
await method(
|
|
37
|
+
document=self.document,
|
|
38
|
+
parse_mode=self.parse_mode,
|
|
39
|
+
caption=self.caption,
|
|
40
|
+
**self.default_params,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
__all__ = ("DocumentReplyHandler",)
|
|
@@ -3,7 +3,7 @@ from functools import cached_property
|
|
|
3
3
|
|
|
4
4
|
import typing_extensions as typing
|
|
5
5
|
|
|
6
|
-
from telegrinder.api import API
|
|
6
|
+
from telegrinder.api.api import API
|
|
7
7
|
from telegrinder.bot.cute_types import BaseCute, UpdateCute
|
|
8
8
|
from telegrinder.bot.dispatch.context import Context
|
|
9
9
|
from telegrinder.bot.dispatch.process import check_rule
|
|
@@ -72,7 +72,7 @@ class FuncHandler(ABCHandler[Event], typing.Generic[Event, F, ErrorHandlerT]):
|
|
|
72
72
|
if nodes:
|
|
73
73
|
result = await compose_nodes(nodes, ctx, data={Update: event, API: api})
|
|
74
74
|
if not result:
|
|
75
|
-
logger.debug(f"Cannot compose nodes for handler. {result.error}")
|
|
75
|
+
logger.debug(f"Cannot compose nodes for handler. Error: {result.error!r}")
|
|
76
76
|
return False
|
|
77
77
|
|
|
78
78
|
node_col = result.value
|
|
@@ -95,7 +95,7 @@ class FuncHandler(ABCHandler[Event], typing.Generic[Event, F, ErrorHandlerT]):
|
|
|
95
95
|
return True
|
|
96
96
|
|
|
97
97
|
async def run(self, api: API, event: Event, ctx: Context) -> typing.Any:
|
|
98
|
-
logger.debug(f"Running func handler {self.func}")
|
|
98
|
+
logger.debug(f"Running func handler {self.func.__qualname__!r}")
|
|
99
99
|
dataclass_type = typing.get_origin(self.dataclass) or self.dataclass
|
|
100
100
|
|
|
101
101
|
if dataclass_type is Update and (event_node := ctx.pop(EVENT_NODE_KEY, None)) is not None:
|