telegrinder 0.1.dev171__tar.gz → 0.2.0__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.1.dev171 → telegrinder-0.2.0}/PKG-INFO +1 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/pyproject.toml +2 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/__init__.py +2 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/api/__init__.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/api/api.py +3 -3
- telegrinder-0.2.0/telegrinder/api/token.py +36 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/__init__.py +12 -6
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/bot.py +12 -5
- telegrinder-0.2.0/telegrinder/bot/cute_types/__init__.py +17 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/base.py +7 -32
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/callback_query.py +5 -6
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/chat_join_request.py +4 -5
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/chat_member_updated.py +3 -4
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/inline_query.py +3 -4
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/message.py +9 -10
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/update.py +8 -9
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/utils.py +1 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/__init__.py +9 -9
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/abc.py +2 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/context.py +11 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/dispatch.py +18 -33
- telegrinder-0.2.0/telegrinder/bot/dispatch/handler/__init__.py +5 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/handler/abc.py +3 -3
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/handler/func.py +17 -12
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/handler/message_reply.py +6 -7
- telegrinder-0.2.0/telegrinder/bot/dispatch/middleware/__init__.py +3 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/process.py +30 -11
- telegrinder-0.2.0/telegrinder/bot/dispatch/return_manager/__init__.py +19 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/return_manager/callback_query.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/return_manager/inline_query.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/return_manager/message.py +1 -2
- telegrinder-0.2.0/telegrinder/bot/dispatch/view/__init__.py +22 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/abc.py +9 -4
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/box.py +2 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/callback_query.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/chat_join_request.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/chat_member.py +16 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/inline_query.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/message.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/view/raw.py +8 -10
- telegrinder-0.2.0/telegrinder/bot/dispatch/waiter_machine/__init__.py +10 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/waiter_machine/machine.py +10 -6
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/waiter_machine/short_state.py +2 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/polling/abc.py +1 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/polling/polling.py +3 -3
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/__init__.py +20 -20
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/abc.py +50 -40
- telegrinder-0.2.0/telegrinder/bot/rules/adapter/__init__.py +14 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/adapter/abc.py +6 -3
- telegrinder-0.2.0/telegrinder/bot/rules/adapter/errors.py +5 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/adapter/event.py +27 -15
- telegrinder-0.2.0/telegrinder/bot/rules/adapter/node.py +48 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/adapter/raw_update.py +13 -5
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/callback_data.py +4 -4
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/chat_join.py +4 -4
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/func.py +1 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/inline.py +3 -3
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/markup.py +3 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/message_entities.py +1 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/text.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/update.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/scenario/abc.py +2 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/scenario/checkbox.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/scenario/choice.py +1 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/model.py +6 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/msgspec_utils.py +55 -55
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/__init__.py +1 -3
- telegrinder-0.2.0/telegrinder/node/base.py +131 -0
- telegrinder-0.2.0/telegrinder/node/composer.py +185 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/container.py +3 -3
- telegrinder-0.2.0/telegrinder/node/event.py +68 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/polymorphic.py +12 -6
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/rule.py +1 -9
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/scope.py +9 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/source.py +11 -0
- telegrinder-0.2.0/telegrinder/node/update.py +15 -0
- telegrinder-0.2.0/telegrinder/rules.py +60 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/error_handler/abc.py +2 -2
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/error_handler/error_handler.py +5 -5
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/global_context/global_context.py +1 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/keyboard.py +1 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/loop_wrapper/loop_wrapper.py +9 -9
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/magic.py +64 -19
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/types/__init__.py +1 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/types/enums.py +1 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/types/methods.py +78 -11
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/types/objects.py +46 -24
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/verification_utils.py +1 -3
- telegrinder-0.1.dev171/telegrinder/api/abc.py +0 -79
- telegrinder-0.1.dev171/telegrinder/bot/cute_types/__init__.py +0 -17
- telegrinder-0.1.dev171/telegrinder/bot/dispatch/handler/__init__.py +0 -5
- telegrinder-0.1.dev171/telegrinder/bot/dispatch/middleware/__init__.py +0 -3
- telegrinder-0.1.dev171/telegrinder/bot/dispatch/return_manager/__init__.py +0 -19
- telegrinder-0.1.dev171/telegrinder/bot/dispatch/view/__init__.py +0 -22
- telegrinder-0.1.dev171/telegrinder/bot/dispatch/waiter_machine/__init__.py +0 -10
- telegrinder-0.1.dev171/telegrinder/bot/rules/adapter/__init__.py +0 -14
- telegrinder-0.1.dev171/telegrinder/bot/rules/adapter/errors.py +0 -4
- telegrinder-0.1.dev171/telegrinder/bot/rules/adapter/node.py +0 -42
- telegrinder-0.1.dev171/telegrinder/node/base.py +0 -203
- telegrinder-0.1.dev171/telegrinder/node/composer.py +0 -188
- telegrinder-0.1.dev171/telegrinder/node/event.py +0 -59
- telegrinder-0.1.dev171/telegrinder/node/update.py +0 -11
- telegrinder-0.1.dev171/telegrinder/rules.py +0 -1
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/LICENSE +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/readme.md +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/api/error.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/api/response.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/middleware/abc.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/return_manager/abc.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/dispatch/waiter_machine/middleware.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/polling/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/command.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/enum_text.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/fuzzy.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/integer.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/is_from.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/mention.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/message.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/node.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/regex.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/rule_enum.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/rules/start.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/scenario/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/client/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/client/abc.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/client/aiohttp.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/modules.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/msgspec_json.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/attachment.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/callback_query.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/command.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/me.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/message.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/text.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/tools/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/node/tools/generator.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/py.typed +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/buttons.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/error_handler/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/error_handler/error.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/formatting/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/formatting/html.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/formatting/links.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/formatting/spec_html_formats.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/global_context/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/global_context/abc.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/global_context/telegrinder_ctx.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/i18n/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/i18n/base.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/i18n/middleware/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/i18n/middleware/base.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/i18n/simple.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/kb_set/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/kb_set/base.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/kb_set/yaml.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/limited_dict.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/loop_wrapper/__init__.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/loop_wrapper/abc.py +0 -0
- {telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/tools/parse_mode.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "telegrinder"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "Modern visionary telegram bot framework."
|
|
5
5
|
authors = ["timoniq <tesseradecades@mail.ru>"]
|
|
6
6
|
maintainers = ["luwqz1 <howluwqz1@gmail.com>"]
|
|
@@ -54,7 +54,7 @@ fntypes = "^0.1.3"
|
|
|
54
54
|
|
|
55
55
|
[tool.poetry.group.dev.dependencies]
|
|
56
56
|
pre-commit = "^3.8.0"
|
|
57
|
-
ruff = "
|
|
57
|
+
ruff = ">=0.5,<0.7"
|
|
58
58
|
basedpyright = "^1.12.1"
|
|
59
59
|
sort-all = "1.2.0"
|
|
60
60
|
pytest = "^8.0.0"
|
|
@@ -34,7 +34,7 @@ bot.run_forever()
|
|
|
34
34
|
|
|
35
35
|
import typing
|
|
36
36
|
|
|
37
|
-
from .api import
|
|
37
|
+
from .api import API, APIError, APIResponse, Token
|
|
38
38
|
from .bot import (
|
|
39
39
|
ABCDispatch,
|
|
40
40
|
ABCHandler,
|
|
@@ -122,7 +122,7 @@ Bot: typing.TypeAlias = Telegrinder
|
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
__all__ = (
|
|
125
|
-
"
|
|
125
|
+
"API",
|
|
126
126
|
"ABCClient",
|
|
127
127
|
"ABCDispatch",
|
|
128
128
|
"ABCErrorHandler",
|
|
@@ -4,13 +4,13 @@ from functools import cached_property
|
|
|
4
4
|
import msgspec
|
|
5
5
|
from fntypes.result import Error, Ok, Result
|
|
6
6
|
|
|
7
|
+
from telegrinder.api.error import APIError
|
|
7
8
|
from telegrinder.api.response import APIResponse
|
|
9
|
+
from telegrinder.api.token import Token
|
|
8
10
|
from telegrinder.client import ABCClient, AiohttpClient
|
|
9
11
|
from telegrinder.model import DataConverter, decoder
|
|
10
12
|
from telegrinder.types.methods import APIMethods
|
|
11
13
|
|
|
12
|
-
from .abc import ABCAPI, APIError, Token
|
|
13
|
-
|
|
14
14
|
|
|
15
15
|
def compose_data(
|
|
16
16
|
client: ABCClient,
|
|
@@ -24,7 +24,7 @@ def compose_data(
|
|
|
24
24
|
)
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
class API(
|
|
27
|
+
class API(APIMethods):
|
|
28
28
|
"""Bot API with available API methods and http client."""
|
|
29
29
|
|
|
30
30
|
API_URL = "https://api.telegram.org/"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
import typing
|
|
3
|
+
from functools import cached_property
|
|
4
|
+
|
|
5
|
+
from envparse import env
|
|
6
|
+
|
|
7
|
+
from .error import InvalidTokenError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Token(str):
|
|
11
|
+
def __new__(cls, token: str) -> typing.Self:
|
|
12
|
+
if token.count(":") != 1 or not token.split(":")[0].isdigit():
|
|
13
|
+
raise InvalidTokenError("Invalid token, it should look like this '123:ABC'.")
|
|
14
|
+
return super().__new__(cls, token)
|
|
15
|
+
|
|
16
|
+
def __repr__(self) -> str:
|
|
17
|
+
return f"<Token: {self.bot_id}:{''.join(self.split(':')[-1])[:6]}...>"
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def from_env(
|
|
21
|
+
cls,
|
|
22
|
+
var_name: str = "BOT_TOKEN",
|
|
23
|
+
*,
|
|
24
|
+
is_read: bool = False,
|
|
25
|
+
path_to_envfile: str | pathlib.Path | None = None,
|
|
26
|
+
) -> typing.Self:
|
|
27
|
+
if not is_read:
|
|
28
|
+
env.read_envfile(path_to_envfile)
|
|
29
|
+
return cls(env.str(var_name))
|
|
30
|
+
|
|
31
|
+
@cached_property
|
|
32
|
+
def bot_id(self) -> int:
|
|
33
|
+
return int(self.split(":")[0])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
__all__ = ("Token",)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from .bot import Telegrinder
|
|
2
|
-
from .cute_types import (
|
|
1
|
+
from telegrinder.bot.bot import Telegrinder
|
|
2
|
+
from telegrinder.bot.cute_types import (
|
|
3
3
|
BaseCute,
|
|
4
4
|
CallbackQueryCute,
|
|
5
5
|
ChatJoinRequestCute,
|
|
@@ -8,7 +8,7 @@ from .cute_types import (
|
|
|
8
8
|
MessageCute,
|
|
9
9
|
UpdateCute,
|
|
10
10
|
)
|
|
11
|
-
from .dispatch import (
|
|
11
|
+
from telegrinder.bot.dispatch import (
|
|
12
12
|
ABCDispatch,
|
|
13
13
|
ABCHandler,
|
|
14
14
|
ABCMiddleware,
|
|
@@ -37,9 +37,15 @@ from .dispatch import (
|
|
|
37
37
|
clear_wm_storage_worker,
|
|
38
38
|
register_manager,
|
|
39
39
|
)
|
|
40
|
-
from .polling import ABCPolling, Polling
|
|
41
|
-
from .rules import
|
|
42
|
-
|
|
40
|
+
from telegrinder.bot.polling import ABCPolling, Polling
|
|
41
|
+
from telegrinder.bot.rules import (
|
|
42
|
+
ABCRule,
|
|
43
|
+
CallbackQueryRule,
|
|
44
|
+
ChatJoinRequestRule,
|
|
45
|
+
InlineQueryRule,
|
|
46
|
+
MessageRule,
|
|
47
|
+
)
|
|
48
|
+
from telegrinder.bot.scenario import ABCScenario, Checkbox, Choice
|
|
43
49
|
|
|
44
50
|
__all__ = (
|
|
45
51
|
"ABCDispatch",
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import typing_extensions as typing
|
|
2
2
|
|
|
3
|
-
from telegrinder.api import API
|
|
4
|
-
from telegrinder.bot.dispatch import ABCDispatch
|
|
5
|
-
from telegrinder.bot.
|
|
3
|
+
from telegrinder.api.api import API
|
|
4
|
+
from telegrinder.bot.dispatch.abc import ABCDispatch
|
|
5
|
+
from telegrinder.bot.dispatch.dispatch import Dispatch
|
|
6
|
+
from telegrinder.bot.polling.abc import ABCPolling
|
|
7
|
+
from telegrinder.bot.polling.polling import Polling
|
|
6
8
|
from telegrinder.modules import logger
|
|
7
|
-
from telegrinder.tools.loop_wrapper import ABCLoopWrapper
|
|
9
|
+
from telegrinder.tools.loop_wrapper import ABCLoopWrapper
|
|
10
|
+
from telegrinder.tools.loop_wrapper.loop_wrapper import LoopWrapper
|
|
8
11
|
|
|
9
12
|
DispatchT = typing.TypeVar("DispatchT", bound=ABCDispatch, default=Dispatch)
|
|
10
13
|
PollingT = typing.TypeVar("PollingT", bound=ABCPolling, default=Polling)
|
|
@@ -57,7 +60,11 @@ class Telegrinder(typing.Generic[DispatchT, PollingT, LoopWrapperT]):
|
|
|
57
60
|
|
|
58
61
|
async for updates in self.polling.listen():
|
|
59
62
|
for update in updates:
|
|
60
|
-
logger.debug(
|
|
63
|
+
logger.debug(
|
|
64
|
+
"Received update (update_id={}, update_type={!r})",
|
|
65
|
+
update.update_id,
|
|
66
|
+
update.update_type.name,
|
|
67
|
+
)
|
|
61
68
|
self.loop_wrapper.add_task(self.dispatch.feed(update, self.api))
|
|
62
69
|
|
|
63
70
|
def run_forever(self, *, offset: int = 0, skip_updates: bool = False) -> None:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from telegrinder.bot.cute_types.base import BaseCute
|
|
2
|
+
from telegrinder.bot.cute_types.callback_query import CallbackQueryCute
|
|
3
|
+
from telegrinder.bot.cute_types.chat_join_request import ChatJoinRequestCute
|
|
4
|
+
from telegrinder.bot.cute_types.chat_member_updated import ChatMemberUpdatedCute
|
|
5
|
+
from telegrinder.bot.cute_types.inline_query import InlineQueryCute
|
|
6
|
+
from telegrinder.bot.cute_types.message import MessageCute
|
|
7
|
+
from telegrinder.bot.cute_types.update import UpdateCute
|
|
8
|
+
|
|
9
|
+
__all__ = (
|
|
10
|
+
"BaseCute",
|
|
11
|
+
"CallbackQueryCute",
|
|
12
|
+
"ChatJoinRequestCute",
|
|
13
|
+
"ChatMemberUpdatedCute",
|
|
14
|
+
"InlineQueryCute",
|
|
15
|
+
"MessageCute",
|
|
16
|
+
"UpdateCute",
|
|
17
|
+
)
|
|
@@ -6,13 +6,13 @@ from functools import wraps
|
|
|
6
6
|
import typing_extensions
|
|
7
7
|
from fntypes.result import Result
|
|
8
8
|
|
|
9
|
-
from telegrinder.api import
|
|
9
|
+
from telegrinder.api.api import API
|
|
10
10
|
from telegrinder.model import Model, get_params
|
|
11
11
|
|
|
12
12
|
F = typing.TypeVar("F", bound=typing.Callable[..., typing.Any])
|
|
13
13
|
Cute = typing.TypeVar("Cute", bound="BaseCute")
|
|
14
14
|
Update = typing_extensions.TypeVar("Update", bound=Model)
|
|
15
|
-
CtxAPI = typing_extensions.TypeVar("CtxAPI", bound=
|
|
15
|
+
CtxAPI = typing_extensions.TypeVar("CtxAPI", bound=API, default=API)
|
|
16
16
|
|
|
17
17
|
Executor: typing.TypeAlias = typing.Callable[
|
|
18
18
|
[Cute, str, dict[str, typing.Any]],
|
|
@@ -22,10 +22,10 @@ Executor: typing.TypeAlias = typing.Callable[
|
|
|
22
22
|
if typing.TYPE_CHECKING:
|
|
23
23
|
|
|
24
24
|
class BaseCute(Model, typing.Generic[Update, CtxAPI]):
|
|
25
|
-
api:
|
|
25
|
+
api: API
|
|
26
26
|
|
|
27
27
|
@classmethod
|
|
28
|
-
def from_update(cls, update: Update, bound_api:
|
|
28
|
+
def from_update(cls, update: Update, bound_api: API) -> typing.Self: ...
|
|
29
29
|
|
|
30
30
|
@property
|
|
31
31
|
def ctx_api(self) -> CtxAPI: ...
|
|
@@ -55,29 +55,10 @@ if typing.TYPE_CHECKING:
|
|
|
55
55
|
...
|
|
56
56
|
|
|
57
57
|
else:
|
|
58
|
-
from fntypes.co import
|
|
59
|
-
from msgspec._utils import get_class_annotations as _get_class_annotations
|
|
58
|
+
from fntypes.co import Some, Variative
|
|
60
59
|
|
|
61
60
|
from telegrinder.msgspec_utils import Option, decoder
|
|
62
|
-
|
|
63
|
-
_DEFAULT_API_CLASS = API
|
|
64
|
-
|
|
65
|
-
def _get_ctx_api_class(cute_class):
|
|
66
|
-
if hasattr(cute_class, "__ctx_api_class__"):
|
|
67
|
-
return cute_class.__ctx_api_class__
|
|
68
|
-
|
|
69
|
-
ctx_api_class = _DEFAULT_API_CLASS
|
|
70
|
-
for base in cute_class.__dict__.get("__orig_bases__", ()):
|
|
71
|
-
if ctx_api_class is not _DEFAULT_API_CLASS:
|
|
72
|
-
break
|
|
73
|
-
if issubclass(typing.get_origin(base) or base, BaseCute):
|
|
74
|
-
for generic_type in typing.get_args(base):
|
|
75
|
-
if issubclass(typing.get_origin(generic_type) or generic_type, ABCAPI):
|
|
76
|
-
ctx_api_class = generic_type
|
|
77
|
-
break
|
|
78
|
-
|
|
79
|
-
cute_class.__ctx_api_class__ = ctx_api_class
|
|
80
|
-
return ctx_api_class
|
|
61
|
+
from telegrinder.msgspec_utils import get_class_annotations as _get_class_annotations
|
|
81
62
|
|
|
82
63
|
def _get_cute_from_args(args):
|
|
83
64
|
for hint in args:
|
|
@@ -86,9 +67,8 @@ else:
|
|
|
86
67
|
if not isinstance(hint, type):
|
|
87
68
|
continue
|
|
88
69
|
|
|
89
|
-
if hint
|
|
70
|
+
if hint in (Variative, Some, Option):
|
|
90
71
|
return _get_cute_from_args(typing.get_args(hint))
|
|
91
|
-
|
|
92
72
|
if issubclass(hint, BaseCute):
|
|
93
73
|
return hint
|
|
94
74
|
|
|
@@ -149,11 +129,6 @@ else:
|
|
|
149
129
|
|
|
150
130
|
@property
|
|
151
131
|
def ctx_api(self):
|
|
152
|
-
ctx_api_class = _get_ctx_api_class(self.__class__)
|
|
153
|
-
assert isinstance(
|
|
154
|
-
self.api,
|
|
155
|
-
ctx_api_class,
|
|
156
|
-
), f"Bound API of type {self.api.__class__.__name__!r} is incompatible with {ctx_api_class.__name__!r}."
|
|
157
132
|
return self.api
|
|
158
133
|
|
|
159
134
|
def to_dict(self, *, exclude_fields=None):
|
|
@@ -4,7 +4,9 @@ from contextlib import suppress
|
|
|
4
4
|
import msgspec
|
|
5
5
|
from fntypes.co import Nothing, Result, Some, Variative, unwrapping
|
|
6
6
|
|
|
7
|
-
from telegrinder.api import
|
|
7
|
+
from telegrinder.api import API, APIError
|
|
8
|
+
from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
|
|
9
|
+
from telegrinder.bot.cute_types.message import MediaType, MessageCute, ReplyMarkup, execute_method_edit
|
|
8
10
|
from telegrinder.model import get_params
|
|
9
11
|
from telegrinder.msgspec_utils import Option, decoder
|
|
10
12
|
from telegrinder.types.objects import (
|
|
@@ -21,12 +23,9 @@ from telegrinder.types.objects import (
|
|
|
21
23
|
User,
|
|
22
24
|
)
|
|
23
25
|
|
|
24
|
-
from .base import BaseCute, compose_method_params, shortcut
|
|
25
|
-
from .message import MediaType, MessageCute, ReplyMarkup, execute_method_edit
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
api: ABCAPI
|
|
27
|
+
class CallbackQueryCute(BaseCute[CallbackQuery], CallbackQuery, kw_only=True):
|
|
28
|
+
api: API
|
|
30
29
|
|
|
31
30
|
message: Option[Variative[MessageCute, InaccessibleMessage]] = Nothing()
|
|
32
31
|
"""Optional. Message sent by the bot with the callback button that originated
|
{telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/chat_join_request.py
RENAMED
|
@@ -2,15 +2,14 @@ import typing
|
|
|
2
2
|
|
|
3
3
|
from fntypes.result import Result
|
|
4
4
|
|
|
5
|
-
from telegrinder.api
|
|
5
|
+
from telegrinder.api import API, APIError
|
|
6
|
+
from telegrinder.bot.cute_types.base import BaseCute, shortcut
|
|
7
|
+
from telegrinder.bot.cute_types.chat_member_updated import ChatMemberShortcuts, chat_member_interaction
|
|
6
8
|
from telegrinder.types.objects import ChatJoinRequest, User
|
|
7
9
|
|
|
8
|
-
from .base import BaseCute, shortcut
|
|
9
|
-
from .chat_member_updated import ChatMemberShortcuts, chat_member_interaction
|
|
10
|
-
|
|
11
10
|
|
|
12
11
|
class ChatJoinRequestCute(BaseCute[ChatJoinRequest], ChatJoinRequest, ChatMemberShortcuts, kw_only=True):
|
|
13
|
-
api:
|
|
12
|
+
api: API
|
|
14
13
|
|
|
15
14
|
@property
|
|
16
15
|
def from_user(self) -> User:
|
{telegrinder-0.1.dev171 → telegrinder-0.2.0}/telegrinder/bot/cute_types/chat_member_updated.py
RENAMED
|
@@ -3,12 +3,11 @@ from datetime import datetime
|
|
|
3
3
|
|
|
4
4
|
from fntypes.result import Result
|
|
5
5
|
|
|
6
|
-
from telegrinder.api import
|
|
6
|
+
from telegrinder.api import API, APIError
|
|
7
|
+
from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
|
|
7
8
|
from telegrinder.model import get_params
|
|
8
9
|
from telegrinder.types.objects import ChatMemberUpdated, ChatPermissions, User
|
|
9
10
|
|
|
10
|
-
from .base import BaseCute, compose_method_params, shortcut
|
|
11
|
-
|
|
12
11
|
|
|
13
12
|
async def chat_member_interaction(
|
|
14
13
|
update: BaseCute[typing.Any],
|
|
@@ -234,7 +233,7 @@ class ChatMemberShortcuts:
|
|
|
234
233
|
class ChatMemberUpdatedCute(
|
|
235
234
|
BaseCute[ChatMemberUpdated], ChatMemberUpdated, ChatMemberShortcuts, kw_only=True
|
|
236
235
|
):
|
|
237
|
-
api:
|
|
236
|
+
api: API
|
|
238
237
|
|
|
239
238
|
@property
|
|
240
239
|
def from_user(self) -> User:
|
|
@@ -2,7 +2,8 @@ import typing
|
|
|
2
2
|
|
|
3
3
|
from fntypes.result import Result
|
|
4
4
|
|
|
5
|
-
from telegrinder.api import
|
|
5
|
+
from telegrinder.api import API, APIError
|
|
6
|
+
from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
|
|
6
7
|
from telegrinder.model import get_params
|
|
7
8
|
from telegrinder.types import (
|
|
8
9
|
InlineQuery,
|
|
@@ -11,11 +12,9 @@ from telegrinder.types import (
|
|
|
11
12
|
User,
|
|
12
13
|
)
|
|
13
14
|
|
|
14
|
-
from .base import BaseCute, compose_method_params, shortcut
|
|
15
|
-
|
|
16
15
|
|
|
17
16
|
class InlineQueryCute(BaseCute[InlineQuery], InlineQuery, kw_only=True):
|
|
18
|
-
api:
|
|
17
|
+
api: API
|
|
19
18
|
|
|
20
19
|
@property
|
|
21
20
|
def from_user(self) -> User:
|
|
@@ -5,7 +5,14 @@ import typing
|
|
|
5
5
|
import fntypes.option
|
|
6
6
|
from fntypes.co import Result, Some, Variative
|
|
7
7
|
|
|
8
|
-
from telegrinder.api import
|
|
8
|
+
from telegrinder.api import API, APIError
|
|
9
|
+
from telegrinder.bot.cute_types.base import BaseCute, compose_method_params, shortcut
|
|
10
|
+
from telegrinder.bot.cute_types.utils import (
|
|
11
|
+
compose_link_preview_options,
|
|
12
|
+
compose_reactions,
|
|
13
|
+
compose_reply_params,
|
|
14
|
+
input_media,
|
|
15
|
+
)
|
|
9
16
|
from telegrinder.model import get_params
|
|
10
17
|
from telegrinder.msgspec_utils import Nothing, Option
|
|
11
18
|
from telegrinder.types.objects import (
|
|
@@ -30,14 +37,6 @@ from telegrinder.types.objects import (
|
|
|
30
37
|
User,
|
|
31
38
|
)
|
|
32
39
|
|
|
33
|
-
from .base import BaseCute, compose_method_params, shortcut
|
|
34
|
-
from .utils import (
|
|
35
|
-
compose_link_preview_options,
|
|
36
|
-
compose_reactions,
|
|
37
|
-
compose_reply_params,
|
|
38
|
-
input_media,
|
|
39
|
-
)
|
|
40
|
-
|
|
41
40
|
if typing.TYPE_CHECKING:
|
|
42
41
|
from datetime import datetime
|
|
43
42
|
|
|
@@ -154,7 +153,7 @@ def get_entity_value(
|
|
|
154
153
|
|
|
155
154
|
|
|
156
155
|
class MessageCute(BaseCute[Message], Message, kw_only=True):
|
|
157
|
-
api:
|
|
156
|
+
api: API
|
|
158
157
|
|
|
159
158
|
reply_to_message: Option[MessageCute] = Nothing
|
|
160
159
|
"""Optional. For replies in the same chat and message thread, the original
|
|
@@ -2,22 +2,21 @@ import typing
|
|
|
2
2
|
|
|
3
3
|
from fntypes.co import Nothing, Some
|
|
4
4
|
|
|
5
|
-
from telegrinder.api import
|
|
5
|
+
from telegrinder.api import API
|
|
6
|
+
from telegrinder.bot.cute_types.base import BaseCute
|
|
7
|
+
from telegrinder.bot.cute_types.callback_query import CallbackQueryCute
|
|
8
|
+
from telegrinder.bot.cute_types.chat_join_request import ChatJoinRequestCute
|
|
9
|
+
from telegrinder.bot.cute_types.chat_member_updated import ChatMemberUpdatedCute
|
|
10
|
+
from telegrinder.bot.cute_types.inline_query import InlineQueryCute
|
|
11
|
+
from telegrinder.bot.cute_types.message import MessageCute
|
|
6
12
|
from telegrinder.msgspec_utils import Option
|
|
7
13
|
from telegrinder.types import Model, Update
|
|
8
14
|
|
|
9
|
-
from .base import BaseCute
|
|
10
|
-
from .callback_query import CallbackQueryCute
|
|
11
|
-
from .chat_join_request import ChatJoinRequestCute
|
|
12
|
-
from .chat_member_updated import ChatMemberUpdatedCute
|
|
13
|
-
from .inline_query import InlineQueryCute
|
|
14
|
-
from .message import MessageCute
|
|
15
|
-
|
|
16
15
|
ModelT = typing.TypeVar("ModelT", bound=Model)
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
class UpdateCute(BaseCute[Update], Update, kw_only=True):
|
|
20
|
-
api:
|
|
19
|
+
api: API
|
|
21
20
|
|
|
22
21
|
message: Option[MessageCute] = Nothing()
|
|
23
22
|
"""Optional. New incoming message of any kind - text, photo, sticker, etc."""
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
from .abc import ABCDispatch
|
|
2
|
-
from .context import Context
|
|
3
|
-
from .dispatch import Dispatch, TelegrinderContext
|
|
4
|
-
from .handler import ABCHandler, FuncHandler, MessageReplyHandler
|
|
5
|
-
from .middleware import ABCMiddleware
|
|
6
|
-
from .process import check_rule, process_inner
|
|
7
|
-
from .return_manager import (
|
|
1
|
+
from telegrinder.bot.dispatch.abc import ABCDispatch
|
|
2
|
+
from telegrinder.bot.dispatch.context import Context
|
|
3
|
+
from telegrinder.bot.dispatch.dispatch import Dispatch, TelegrinderContext
|
|
4
|
+
from telegrinder.bot.dispatch.handler import ABCHandler, FuncHandler, MessageReplyHandler
|
|
5
|
+
from telegrinder.bot.dispatch.middleware import ABCMiddleware
|
|
6
|
+
from telegrinder.bot.dispatch.process import check_rule, process_inner
|
|
7
|
+
from telegrinder.bot.dispatch.return_manager import (
|
|
8
8
|
ABCReturnManager,
|
|
9
9
|
BaseReturnManager,
|
|
10
10
|
CallbackQueryReturnManager,
|
|
@@ -13,7 +13,7 @@ from .return_manager import (
|
|
|
13
13
|
MessageReturnManager,
|
|
14
14
|
register_manager,
|
|
15
15
|
)
|
|
16
|
-
from .view import (
|
|
16
|
+
from telegrinder.bot.dispatch.view import (
|
|
17
17
|
ABCStateView,
|
|
18
18
|
ABCView,
|
|
19
19
|
BaseStateView,
|
|
@@ -26,7 +26,7 @@ from .view import (
|
|
|
26
26
|
RawEventView,
|
|
27
27
|
ViewBox,
|
|
28
28
|
)
|
|
29
|
-
from .waiter_machine import ShortState, WaiterMachine, clear_wm_storage_worker
|
|
29
|
+
from telegrinder.bot.dispatch.waiter_machine import ShortState, WaiterMachine, clear_wm_storage_worker
|
|
30
30
|
|
|
31
31
|
__all__ = (
|
|
32
32
|
"ABCDispatch",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
3
|
|
|
4
|
-
from telegrinder.api
|
|
4
|
+
from telegrinder.api import API
|
|
5
5
|
from telegrinder.tools.global_context.abc import ABCGlobalContext
|
|
6
6
|
from telegrinder.types.objects import Update
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ class ABCDispatch(ABC):
|
|
|
13
13
|
pass
|
|
14
14
|
|
|
15
15
|
@abstractmethod
|
|
16
|
-
async def feed(self, event: Update, api:
|
|
16
|
+
async def feed(self, event: Update, api: API) -> bool:
|
|
17
17
|
pass
|
|
18
18
|
|
|
19
19
|
@abstractmethod
|
|
@@ -68,13 +68,22 @@ class Context(dict[str, AnyValue]):
|
|
|
68
68
|
def set(self, key: Key, value: AnyValue) -> None:
|
|
69
69
|
self[key] = value
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
@typing.overload
|
|
72
|
+
def get(self, key: Key) -> AnyValue | None: ...
|
|
73
|
+
|
|
74
|
+
@typing.overload
|
|
75
|
+
def get(self, key: Key, default: T) -> T | AnyValue: ...
|
|
76
|
+
|
|
77
|
+
@typing.overload
|
|
78
|
+
def get(self, key: Key, default: None = None) -> AnyValue | None: ...
|
|
79
|
+
|
|
80
|
+
def get(self, key: Key, default: T | None = None) -> T | AnyValue | None:
|
|
72
81
|
return dict.get(self, key, default)
|
|
73
82
|
|
|
74
83
|
def get_or_set(self, key: Key, default: T) -> T:
|
|
75
84
|
if key not in self:
|
|
76
85
|
self.set(key, default)
|
|
77
|
-
return self.get(key)
|
|
86
|
+
return self.get(key, default)
|
|
78
87
|
|
|
79
88
|
def delete(self, key: Key) -> None:
|
|
80
89
|
del self[key]
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import asyncio
|
|
2
1
|
import dataclasses
|
|
3
2
|
import typing
|
|
4
3
|
|
|
5
4
|
from vbml.patcher import Patcher
|
|
6
5
|
|
|
7
|
-
from telegrinder.api
|
|
6
|
+
from telegrinder.api import API
|
|
8
7
|
from telegrinder.bot.cute_types.base import BaseCute
|
|
9
8
|
from telegrinder.bot.cute_types.update import UpdateCute
|
|
10
|
-
from telegrinder.bot.dispatch.
|
|
11
|
-
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
9
|
+
from telegrinder.bot.dispatch.abc import ABCDispatch
|
|
12
10
|
from telegrinder.bot.dispatch.handler.func import ErrorHandlerT, FuncHandler
|
|
13
|
-
from telegrinder.
|
|
14
|
-
from telegrinder.tools.error_handler.error_handler import ErrorHandler
|
|
15
|
-
from telegrinder.tools.global_context import TelegrinderContext
|
|
16
|
-
from telegrinder.types.enums import UpdateType
|
|
17
|
-
from telegrinder.types.objects import Update
|
|
18
|
-
|
|
19
|
-
from .abc import ABCDispatch
|
|
20
|
-
from .view.box import (
|
|
11
|
+
from telegrinder.bot.dispatch.view.box import (
|
|
21
12
|
CallbackQueryView,
|
|
22
13
|
ChatJoinRequestView,
|
|
23
14
|
ChatMemberView,
|
|
@@ -26,6 +17,11 @@ from .view.box import (
|
|
|
26
17
|
RawEventView,
|
|
27
18
|
ViewBox,
|
|
28
19
|
)
|
|
20
|
+
from telegrinder.modules import logger
|
|
21
|
+
from telegrinder.tools.error_handler.error_handler import ErrorHandler
|
|
22
|
+
from telegrinder.tools.global_context import TelegrinderContext
|
|
23
|
+
from telegrinder.types.enums import UpdateType
|
|
24
|
+
from telegrinder.types.objects import Update
|
|
29
25
|
|
|
30
26
|
if typing.TYPE_CHECKING:
|
|
31
27
|
from telegrinder.bot.rules.abc import ABCRule
|
|
@@ -49,10 +45,6 @@ class Dispatch(
|
|
|
49
45
|
RawEventView,
|
|
50
46
|
],
|
|
51
47
|
):
|
|
52
|
-
default_handlers: list[ABCHandler] = dataclasses.field(
|
|
53
|
-
init=False,
|
|
54
|
-
default_factory=lambda: [],
|
|
55
|
-
)
|
|
56
48
|
_global_context: TelegrinderContext = dataclasses.field(
|
|
57
49
|
init=False,
|
|
58
50
|
default_factory=lambda: TelegrinderContext(),
|
|
@@ -166,35 +158,28 @@ class Dispatch(
|
|
|
166
158
|
error_handler=error_handler or ErrorHandler(),
|
|
167
159
|
update_type=update_type,
|
|
168
160
|
)
|
|
169
|
-
self.
|
|
161
|
+
self.raw_event.handlers.append(handler)
|
|
170
162
|
return handler
|
|
171
163
|
|
|
172
164
|
return wrapper
|
|
173
165
|
|
|
174
|
-
async def feed(self, event: Update, api:
|
|
175
|
-
logger.debug(
|
|
176
|
-
|
|
177
|
-
|
|
166
|
+
async def feed(self, event: Update, api: API) -> bool:
|
|
167
|
+
logger.debug(
|
|
168
|
+
"Processing update (update_id={}, update_type={!r})",
|
|
169
|
+
event.update_id,
|
|
170
|
+
event.update_type.name,
|
|
171
|
+
)
|
|
178
172
|
for view in self.get_views().values():
|
|
179
173
|
if await view.check(event):
|
|
180
174
|
logger.debug(
|
|
181
|
-
"Update (update_id={}) matched view {!r}.",
|
|
175
|
+
"Update (update_id={}, update_type={!r}) matched view {!r}.",
|
|
182
176
|
event.update_id,
|
|
177
|
+
event.update_type.name,
|
|
183
178
|
view,
|
|
184
179
|
)
|
|
185
180
|
if await view.process(event, api):
|
|
186
181
|
return True
|
|
187
|
-
|
|
188
|
-
ctx = Context(raw_update=event)
|
|
189
|
-
loop = asyncio.get_running_loop()
|
|
190
|
-
found = False
|
|
191
|
-
for handler in self.default_handlers:
|
|
192
|
-
if await handler.check(api, event, ctx):
|
|
193
|
-
found = True
|
|
194
|
-
loop.create_task(handler.run(api, event, ctx))
|
|
195
|
-
if handler.is_blocking:
|
|
196
|
-
break
|
|
197
|
-
return found
|
|
182
|
+
return False
|
|
198
183
|
|
|
199
184
|
def load(self, external: typing.Self) -> None:
|
|
200
185
|
view_external = external.get_views()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
3
|
|
|
4
|
-
from telegrinder.api
|
|
4
|
+
from telegrinder.api import API
|
|
5
5
|
from telegrinder.bot.dispatch.context import Context
|
|
6
6
|
from telegrinder.model import Model
|
|
7
7
|
from telegrinder.types.objects import Update
|
|
@@ -13,11 +13,11 @@ class ABCHandler(ABC, typing.Generic[T]):
|
|
|
13
13
|
is_blocking: bool
|
|
14
14
|
|
|
15
15
|
@abstractmethod
|
|
16
|
-
async def check(self, api:
|
|
16
|
+
async def check(self, api: API, event: Update, ctx: Context | None = None) -> bool:
|
|
17
17
|
pass
|
|
18
18
|
|
|
19
19
|
@abstractmethod
|
|
20
|
-
async def run(self, api:
|
|
20
|
+
async def run(self, api: API, event: T, ctx: Context) -> typing.Any:
|
|
21
21
|
pass
|
|
22
22
|
|
|
23
23
|
|