telegrinder 0.3.0.post2__py3-none-any.whl → 0.3.2__py3-none-any.whl
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/__init__.py +144 -144
- telegrinder/api/__init__.py +8 -8
- telegrinder/api/api.py +93 -93
- telegrinder/api/error.py +16 -16
- telegrinder/api/response.py +20 -20
- telegrinder/api/token.py +36 -36
- telegrinder/bot/__init__.py +66 -66
- telegrinder/bot/bot.py +76 -76
- telegrinder/bot/cute_types/__init__.py +11 -11
- telegrinder/bot/cute_types/base.py +258 -234
- telegrinder/bot/cute_types/callback_query.py +382 -382
- telegrinder/bot/cute_types/chat_join_request.py +61 -61
- telegrinder/bot/cute_types/chat_member_updated.py +160 -160
- telegrinder/bot/cute_types/inline_query.py +53 -53
- telegrinder/bot/cute_types/message.py +2631 -2631
- telegrinder/bot/cute_types/update.py +75 -75
- telegrinder/bot/cute_types/utils.py +92 -92
- telegrinder/bot/dispatch/__init__.py +55 -55
- telegrinder/bot/dispatch/abc.py +77 -77
- telegrinder/bot/dispatch/context.py +92 -92
- telegrinder/bot/dispatch/dispatch.py +202 -201
- telegrinder/bot/dispatch/handler/__init__.py +13 -13
- telegrinder/bot/dispatch/handler/abc.py +24 -24
- telegrinder/bot/dispatch/handler/audio_reply.py +44 -44
- telegrinder/bot/dispatch/handler/base.py +57 -57
- telegrinder/bot/dispatch/handler/document_reply.py +44 -44
- telegrinder/bot/dispatch/handler/func.py +128 -123
- telegrinder/bot/dispatch/handler/media_group_reply.py +43 -43
- telegrinder/bot/dispatch/handler/message_reply.py +36 -36
- telegrinder/bot/dispatch/handler/photo_reply.py +44 -44
- telegrinder/bot/dispatch/handler/sticker_reply.py +37 -37
- telegrinder/bot/dispatch/handler/video_reply.py +44 -44
- telegrinder/bot/dispatch/middleware/__init__.py +3 -3
- telegrinder/bot/dispatch/middleware/abc.py +16 -16
- telegrinder/bot/dispatch/process.py +132 -132
- telegrinder/bot/dispatch/return_manager/__init__.py +13 -13
- telegrinder/bot/dispatch/return_manager/abc.py +108 -108
- telegrinder/bot/dispatch/return_manager/callback_query.py +20 -20
- telegrinder/bot/dispatch/return_manager/inline_query.py +15 -15
- telegrinder/bot/dispatch/return_manager/message.py +36 -36
- telegrinder/bot/dispatch/view/__init__.py +13 -13
- telegrinder/bot/dispatch/view/abc.py +41 -41
- telegrinder/bot/dispatch/view/base.py +200 -211
- telegrinder/bot/dispatch/view/box.py +129 -129
- telegrinder/bot/dispatch/view/callback_query.py +17 -17
- telegrinder/bot/dispatch/view/chat_join_request.py +16 -16
- telegrinder/bot/dispatch/view/chat_member.py +39 -39
- telegrinder/bot/dispatch/view/inline_query.py +17 -17
- telegrinder/bot/dispatch/view/message.py +44 -44
- telegrinder/bot/dispatch/view/raw.py +114 -118
- telegrinder/bot/dispatch/waiter_machine/__init__.py +17 -17
- telegrinder/bot/dispatch/waiter_machine/actions.py +13 -13
- telegrinder/bot/dispatch/waiter_machine/hasher/__init__.py +8 -8
- telegrinder/bot/dispatch/waiter_machine/hasher/callback.py +57 -57
- telegrinder/bot/dispatch/waiter_machine/hasher/hasher.py +57 -57
- telegrinder/bot/dispatch/waiter_machine/hasher/message.py +53 -53
- telegrinder/bot/dispatch/waiter_machine/hasher/state.py +19 -19
- telegrinder/bot/dispatch/waiter_machine/machine.py +168 -170
- telegrinder/bot/dispatch/waiter_machine/middleware.py +89 -89
- telegrinder/bot/dispatch/waiter_machine/short_state.py +65 -65
- telegrinder/bot/polling/__init__.py +4 -4
- telegrinder/bot/polling/abc.py +25 -25
- telegrinder/bot/polling/polling.py +131 -131
- telegrinder/bot/rules/__init__.py +62 -62
- telegrinder/bot/rules/abc.py +238 -233
- telegrinder/bot/rules/adapter/__init__.py +9 -9
- telegrinder/bot/rules/adapter/abc.py +29 -29
- telegrinder/bot/rules/adapter/errors.py +5 -5
- telegrinder/bot/rules/adapter/event.py +76 -76
- telegrinder/bot/rules/adapter/node.py +48 -48
- telegrinder/bot/rules/adapter/raw_update.py +30 -30
- telegrinder/bot/rules/callback_data.py +171 -171
- telegrinder/bot/rules/chat_join.py +48 -48
- telegrinder/bot/rules/command.py +126 -126
- telegrinder/bot/rules/enum_text.py +36 -33
- telegrinder/bot/rules/func.py +26 -26
- telegrinder/bot/rules/fuzzy.py +24 -24
- telegrinder/bot/rules/inline.py +60 -60
- telegrinder/bot/rules/integer.py +20 -20
- telegrinder/bot/rules/is_from.py +146 -146
- telegrinder/bot/rules/markup.py +43 -43
- telegrinder/bot/rules/mention.py +14 -14
- telegrinder/bot/rules/message.py +17 -17
- telegrinder/bot/rules/message_entities.py +35 -35
- telegrinder/bot/rules/node.py +27 -27
- telegrinder/bot/rules/regex.py +37 -37
- telegrinder/bot/rules/rule_enum.py +72 -72
- telegrinder/bot/rules/start.py +42 -42
- telegrinder/bot/rules/state.py +37 -37
- telegrinder/bot/rules/text.py +33 -33
- telegrinder/bot/rules/update.py +15 -15
- telegrinder/bot/scenario/__init__.py +5 -5
- telegrinder/bot/scenario/abc.py +19 -19
- telegrinder/bot/scenario/checkbox.py +167 -139
- telegrinder/bot/scenario/choice.py +46 -44
- telegrinder/client/__init__.py +4 -4
- telegrinder/client/abc.py +75 -75
- telegrinder/client/aiohttp.py +130 -130
- telegrinder/model.py +244 -244
- telegrinder/modules.py +237 -237
- telegrinder/msgspec_json.py +14 -14
- telegrinder/msgspec_utils.py +410 -410
- telegrinder/node/__init__.py +20 -20
- telegrinder/node/attachment.py +92 -92
- telegrinder/node/base.py +143 -144
- telegrinder/node/callback_query.py +14 -14
- telegrinder/node/command.py +33 -33
- telegrinder/node/composer.py +196 -184
- telegrinder/node/container.py +27 -27
- telegrinder/node/event.py +71 -73
- telegrinder/node/me.py +16 -16
- telegrinder/node/message.py +14 -14
- telegrinder/node/polymorphic.py +48 -52
- telegrinder/node/rule.py +76 -76
- telegrinder/node/scope.py +38 -38
- telegrinder/node/source.py +71 -71
- telegrinder/node/text.py +21 -21
- telegrinder/node/tools/__init__.py +3 -3
- telegrinder/node/tools/generator.py +40 -40
- telegrinder/node/update.py +15 -15
- telegrinder/rules.py +0 -0
- telegrinder/tools/__init__.py +74 -74
- telegrinder/tools/buttons.py +79 -79
- telegrinder/tools/error_handler/__init__.py +7 -7
- telegrinder/tools/error_handler/abc.py +33 -33
- telegrinder/tools/error_handler/error.py +9 -9
- telegrinder/tools/error_handler/error_handler.py +193 -193
- telegrinder/tools/formatting/__init__.py +46 -46
- telegrinder/tools/formatting/html.py +308 -308
- telegrinder/tools/formatting/links.py +33 -33
- telegrinder/tools/formatting/spec_html_formats.py +111 -111
- telegrinder/tools/functional.py +12 -12
- telegrinder/tools/global_context/__init__.py +7 -7
- telegrinder/tools/global_context/abc.py +63 -63
- telegrinder/tools/global_context/global_context.py +412 -412
- telegrinder/tools/global_context/telegrinder_ctx.py +27 -27
- telegrinder/tools/i18n/__init__.py +12 -12
- telegrinder/tools/i18n/abc.py +32 -32
- telegrinder/tools/i18n/middleware/__init__.py +3 -3
- telegrinder/tools/i18n/middleware/abc.py +25 -25
- telegrinder/tools/i18n/simple.py +43 -43
- telegrinder/tools/kb_set/__init__.py +4 -4
- telegrinder/tools/kb_set/base.py +15 -15
- telegrinder/tools/kb_set/yaml.py +63 -63
- telegrinder/tools/keyboard.py +128 -128
- telegrinder/tools/limited_dict.py +37 -37
- telegrinder/tools/loop_wrapper/__init__.py +4 -4
- telegrinder/tools/loop_wrapper/abc.py +15 -15
- telegrinder/tools/loop_wrapper/loop_wrapper.py +216 -216
- telegrinder/tools/magic.py +168 -164
- telegrinder/tools/parse_mode.py +6 -6
- telegrinder/tools/state_storage/__init__.py +4 -4
- telegrinder/tools/state_storage/abc.py +35 -35
- telegrinder/tools/state_storage/memory.py +25 -25
- telegrinder/types/__init__.py +6 -6
- telegrinder/types/enums.py +672 -672
- telegrinder/types/methods.py +4633 -4633
- telegrinder/types/objects.py +6317 -6317
- telegrinder/verification_utils.py +32 -32
- {telegrinder-0.3.0.post2.dist-info → telegrinder-0.3.2.dist-info}/LICENSE +22 -22
- {telegrinder-0.3.0.post2.dist-info → telegrinder-0.3.2.dist-info}/METADATA +1 -1
- telegrinder-0.3.2.dist-info/RECORD +164 -0
- telegrinder-0.3.0.post2.dist-info/RECORD +0 -164
- {telegrinder-0.3.0.post2.dist-info → telegrinder-0.3.2.dist-info}/WHEEL +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
from telegrinder.bot.dispatch.view.abc import ABCStateView, ABCView
|
|
2
|
-
from telegrinder.bot.dispatch.view.base import BaseStateView, BaseView
|
|
3
|
-
from telegrinder.bot.dispatch.view.box import ViewBox
|
|
4
|
-
from telegrinder.bot.dispatch.view.callback_query import CallbackQueryView
|
|
5
|
-
from telegrinder.bot.dispatch.view.chat_join_request import ChatJoinRequestView
|
|
6
|
-
from telegrinder.bot.dispatch.view.chat_member import ChatMemberView
|
|
7
|
-
from telegrinder.bot.dispatch.view.inline_query import InlineQueryView
|
|
8
|
-
from telegrinder.bot.dispatch.view.message import MessageView
|
|
9
|
-
from telegrinder.bot.dispatch.view.raw import RawEventView
|
|
10
|
-
|
|
11
|
-
__all__ = (
|
|
1
|
+
from telegrinder.bot.dispatch.view.abc import ABCStateView, ABCView
|
|
2
|
+
from telegrinder.bot.dispatch.view.base import BaseStateView, BaseView
|
|
3
|
+
from telegrinder.bot.dispatch.view.box import ViewBox
|
|
4
|
+
from telegrinder.bot.dispatch.view.callback_query import CallbackQueryView
|
|
5
|
+
from telegrinder.bot.dispatch.view.chat_join_request import ChatJoinRequestView
|
|
6
|
+
from telegrinder.bot.dispatch.view.chat_member import ChatMemberView
|
|
7
|
+
from telegrinder.bot.dispatch.view.inline_query import InlineQueryView
|
|
8
|
+
from telegrinder.bot.dispatch.view.message import MessageView
|
|
9
|
+
from telegrinder.bot.dispatch.view.raw import RawEventView
|
|
10
|
+
|
|
11
|
+
__all__ = (
|
|
12
12
|
"ABCStateView",
|
|
13
13
|
"ABCView",
|
|
14
14
|
"BaseStateView",
|
|
@@ -19,5 +19,5 @@ __all__ = (
|
|
|
19
19
|
"InlineQueryView",
|
|
20
20
|
"MessageView",
|
|
21
21
|
"RawEventView",
|
|
22
|
-
"ViewBox",
|
|
23
|
-
)
|
|
22
|
+
"ViewBox",
|
|
23
|
+
)
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import typing
|
|
2
|
-
from abc import ABC, abstractmethod
|
|
3
|
-
|
|
4
|
-
from telegrinder.api.api import API
|
|
5
|
-
from telegrinder.bot.cute_types.base import BaseCute
|
|
6
|
-
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
7
|
-
from telegrinder.types.objects import Update
|
|
8
|
-
|
|
9
|
-
Event = typing.TypeVar("Event", bound=BaseCute)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class ABCView(ABC):
|
|
13
|
-
def __repr__(self) -> str:
|
|
14
|
-
return "<{}>".format(self.__class__.__name__)
|
|
15
|
-
|
|
16
|
-
@abstractmethod
|
|
17
|
-
async def check(self, event: Update) -> bool:
|
|
18
|
-
pass
|
|
19
|
-
|
|
20
|
-
@abstractmethod
|
|
21
|
-
async def process(self, event: Update, api: API) -> bool:
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
@abstractmethod
|
|
25
|
-
def load(self, external: typing.Self) -> None:
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class ABCEventRawView(ABCView, ABC, typing.Generic[Event]):
|
|
30
|
-
handlers: list[ABCHandler[Event]]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class ABCStateView(ABCView, typing.Generic[Event]):
|
|
34
|
-
@abstractmethod
|
|
35
|
-
def get_state_key(self, event: Event) -> int | None:
|
|
36
|
-
pass
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
__all__ = (
|
|
1
|
+
import typing
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
|
|
4
|
+
from telegrinder.api.api import API
|
|
5
|
+
from telegrinder.bot.cute_types.base import BaseCute
|
|
6
|
+
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
7
|
+
from telegrinder.types.objects import Update
|
|
8
|
+
|
|
9
|
+
Event = typing.TypeVar("Event", bound=BaseCute)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ABCView(ABC):
|
|
13
|
+
def __repr__(self) -> str:
|
|
14
|
+
return "<{}>".format(self.__class__.__name__)
|
|
15
|
+
|
|
16
|
+
@abstractmethod
|
|
17
|
+
async def check(self, event: Update) -> bool:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
async def process(self, event: Update, api: API) -> bool:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def load(self, external: typing.Self) -> None:
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ABCEventRawView(ABCView, ABC, typing.Generic[Event]):
|
|
30
|
+
handlers: list[ABCHandler[Event]]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class ABCStateView(ABCView, typing.Generic[Event]):
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def get_state_key(self, event: Event) -> int | None:
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
__all__ = (
|
|
40
40
|
"ABCEventRawView",
|
|
41
41
|
"ABCStateView",
|
|
42
|
-
"ABCView",
|
|
43
|
-
)
|
|
42
|
+
"ABCView",
|
|
43
|
+
)
|
|
@@ -1,211 +1,200 @@
|
|
|
1
|
-
import typing
|
|
2
|
-
from abc import ABC, abstractmethod
|
|
3
|
-
from functools import cached_property
|
|
4
|
-
|
|
5
|
-
from fntypes.option import Nothing, Some
|
|
6
|
-
|
|
7
|
-
from telegrinder.api.api import API
|
|
8
|
-
from telegrinder.bot.cute_types.base import BaseCute
|
|
9
|
-
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
10
|
-
from telegrinder.bot.dispatch.handler.func import FuncHandler
|
|
11
|
-
from telegrinder.bot.dispatch.middleware.abc import ABCMiddleware
|
|
12
|
-
from telegrinder.bot.dispatch.process import process_inner
|
|
13
|
-
from telegrinder.bot.dispatch.return_manager.abc import ABCReturnManager
|
|
14
|
-
from telegrinder.bot.dispatch.view.abc import ABCStateView, ABCView
|
|
15
|
-
from telegrinder.bot.rules.abc import ABCRule
|
|
16
|
-
from telegrinder.model import Model
|
|
17
|
-
from telegrinder.msgspec_utils import Option
|
|
18
|
-
from telegrinder.tools.error_handler.error_handler import ABCErrorHandler, ErrorHandler
|
|
19
|
-
from telegrinder.types.objects import Update
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
@
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
@classmethod
|
|
92
|
-
def to_handler(
|
|
93
|
-
cls,
|
|
94
|
-
*rules: ABCRule,
|
|
95
|
-
error_handler:
|
|
96
|
-
is_blocking: bool = True,
|
|
97
|
-
) -> typing.Callable[
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
) -> typing.Callable[
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
),
|
|
180
|
-
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
self.handlers.extend(external.handlers)
|
|
202
|
-
self.middlewares.extend(external.middlewares)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
class BaseStateView(ABCStateView[Event], BaseView[Event], ABC, typing.Generic[Event]):
|
|
206
|
-
@abstractmethod
|
|
207
|
-
def get_state_key(self, event: Event) -> int | None:
|
|
208
|
-
pass
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
__all__ = ("ABCStateView", "ABCView", "BaseStateView", "BaseView")
|
|
1
|
+
import typing
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from functools import cached_property
|
|
4
|
+
|
|
5
|
+
from fntypes.option import Nothing, Some
|
|
6
|
+
|
|
7
|
+
from telegrinder.api.api import API
|
|
8
|
+
from telegrinder.bot.cute_types.base import BaseCute
|
|
9
|
+
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
10
|
+
from telegrinder.bot.dispatch.handler.func import Func, FuncHandler
|
|
11
|
+
from telegrinder.bot.dispatch.middleware.abc import ABCMiddleware
|
|
12
|
+
from telegrinder.bot.dispatch.process import process_inner
|
|
13
|
+
from telegrinder.bot.dispatch.return_manager.abc import ABCReturnManager
|
|
14
|
+
from telegrinder.bot.dispatch.view.abc import ABCStateView, ABCView
|
|
15
|
+
from telegrinder.bot.rules.abc import ABCRule
|
|
16
|
+
from telegrinder.model import Model
|
|
17
|
+
from telegrinder.msgspec_utils import Option
|
|
18
|
+
from telegrinder.tools.error_handler.error_handler import ABCErrorHandler, ErrorHandler
|
|
19
|
+
from telegrinder.types.objects import Update
|
|
20
|
+
|
|
21
|
+
P = typing.ParamSpec("P")
|
|
22
|
+
R = typing.TypeVar("R", covariant=True)
|
|
23
|
+
Event = typing.TypeVar("Event", bound=BaseCute)
|
|
24
|
+
ErrorHandlerT = typing.TypeVar("ErrorHandlerT", bound=ABCErrorHandler)
|
|
25
|
+
MiddlewareT = typing.TypeVar("MiddlewareT", bound=ABCMiddleware)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_event_model_class(view: "BaseView[Event]") -> Option[type[Event]]:
|
|
29
|
+
for base in view.__class__.__bases__ + (view.__class__,):
|
|
30
|
+
if "__orig_bases__" not in base.__dict__:
|
|
31
|
+
continue
|
|
32
|
+
|
|
33
|
+
for orig_base in base.__dict__["__orig_bases__"]:
|
|
34
|
+
origin_base = typing.get_origin(orig_base) or orig_base
|
|
35
|
+
if not isinstance(origin_base, type) and not issubclass(origin_base, object):
|
|
36
|
+
continue
|
|
37
|
+
|
|
38
|
+
for generic_type in typing.get_args(orig_base):
|
|
39
|
+
orig_generic_type = typing.get_origin(generic_type) or generic_type
|
|
40
|
+
if isinstance(orig_generic_type, type) and issubclass(orig_generic_type, BaseCute):
|
|
41
|
+
return Some(generic_type)
|
|
42
|
+
|
|
43
|
+
return Nothing()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class BaseView(ABCView, typing.Generic[Event]):
|
|
47
|
+
auto_rules: list[ABCRule]
|
|
48
|
+
handlers: list[ABCHandler[Event]]
|
|
49
|
+
middlewares: list[ABCMiddleware[Event]]
|
|
50
|
+
return_manager: ABCReturnManager[Event] | None = None
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def get_raw_event(update: Update) -> Option[Model]:
|
|
54
|
+
return getattr(update, update.update_type.value)
|
|
55
|
+
|
|
56
|
+
@cached_property
|
|
57
|
+
def event_model_class(self) -> Option[type[Event]]:
|
|
58
|
+
return get_event_model_class(self)
|
|
59
|
+
|
|
60
|
+
@typing.overload
|
|
61
|
+
@classmethod
|
|
62
|
+
def to_handler(
|
|
63
|
+
cls,
|
|
64
|
+
*rules: ABCRule,
|
|
65
|
+
) -> typing.Callable[
|
|
66
|
+
[Func[P, R]],
|
|
67
|
+
FuncHandler[Event, Func[P, R], ErrorHandler[Event]],
|
|
68
|
+
]: ...
|
|
69
|
+
|
|
70
|
+
@typing.overload
|
|
71
|
+
@classmethod
|
|
72
|
+
def to_handler(
|
|
73
|
+
cls,
|
|
74
|
+
*rules: ABCRule,
|
|
75
|
+
error_handler: ErrorHandlerT,
|
|
76
|
+
is_blocking: bool = True,
|
|
77
|
+
) -> typing.Callable[[Func[P, R]], FuncHandler[Event, Func[P, R], ErrorHandlerT]]: ...
|
|
78
|
+
|
|
79
|
+
@typing.overload
|
|
80
|
+
@classmethod
|
|
81
|
+
def to_handler(
|
|
82
|
+
cls,
|
|
83
|
+
*rules: ABCRule,
|
|
84
|
+
error_handler: typing.Literal[None] = None,
|
|
85
|
+
is_blocking: bool = True,
|
|
86
|
+
) -> typing.Callable[
|
|
87
|
+
[Func[P, R]],
|
|
88
|
+
FuncHandler[Event, Func[P, R], ErrorHandler[Event]],
|
|
89
|
+
]: ...
|
|
90
|
+
|
|
91
|
+
@classmethod
|
|
92
|
+
def to_handler(
|
|
93
|
+
cls,
|
|
94
|
+
*rules: ABCRule,
|
|
95
|
+
error_handler: ABCErrorHandler | None = None,
|
|
96
|
+
is_blocking: bool = True,
|
|
97
|
+
) -> typing.Callable[..., typing.Any]:
|
|
98
|
+
def wrapper(func):
|
|
99
|
+
return FuncHandler(
|
|
100
|
+
func,
|
|
101
|
+
list(rules),
|
|
102
|
+
is_blocking=is_blocking,
|
|
103
|
+
dataclass=None,
|
|
104
|
+
error_handler=error_handler or ErrorHandler(),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
return wrapper
|
|
108
|
+
|
|
109
|
+
@typing.overload
|
|
110
|
+
def __call__(
|
|
111
|
+
self,
|
|
112
|
+
*rules: ABCRule,
|
|
113
|
+
) -> typing.Callable[
|
|
114
|
+
[Func[P, R]],
|
|
115
|
+
FuncHandler[Event, Func[P, R], ErrorHandler[Event]],
|
|
116
|
+
]: ...
|
|
117
|
+
|
|
118
|
+
@typing.overload
|
|
119
|
+
def __call__( # type: ignore
|
|
120
|
+
self,
|
|
121
|
+
*rules: ABCRule,
|
|
122
|
+
error_handler: ErrorHandlerT,
|
|
123
|
+
is_blocking: bool = True,
|
|
124
|
+
) -> typing.Callable[[Func[P, R]], FuncHandler[Event, Func[P, R], ErrorHandlerT]]: ...
|
|
125
|
+
|
|
126
|
+
@typing.overload
|
|
127
|
+
def __call__(
|
|
128
|
+
self,
|
|
129
|
+
*rules: ABCRule,
|
|
130
|
+
error_handler: typing.Literal[None] = None,
|
|
131
|
+
is_blocking: bool = True,
|
|
132
|
+
) -> typing.Callable[
|
|
133
|
+
[Func[P, R]],
|
|
134
|
+
FuncHandler[Event, Func[P, R], ErrorHandler[Event]],
|
|
135
|
+
]: ...
|
|
136
|
+
|
|
137
|
+
def __call__(
|
|
138
|
+
self,
|
|
139
|
+
*rules: ABCRule,
|
|
140
|
+
error_handler: ABCErrorHandler | None = None,
|
|
141
|
+
is_blocking: bool = True,
|
|
142
|
+
) -> typing.Callable[..., typing.Any]:
|
|
143
|
+
def wrapper(func):
|
|
144
|
+
func_handler = FuncHandler(
|
|
145
|
+
func,
|
|
146
|
+
[*self.auto_rules, *rules],
|
|
147
|
+
is_blocking=is_blocking,
|
|
148
|
+
dataclass=None,
|
|
149
|
+
error_handler=error_handler or ErrorHandler(),
|
|
150
|
+
)
|
|
151
|
+
self.handlers.append(func_handler)
|
|
152
|
+
return func_handler
|
|
153
|
+
|
|
154
|
+
return wrapper
|
|
155
|
+
|
|
156
|
+
def register_middleware(self, *args: typing.Any, **kwargs: typing.Any):
|
|
157
|
+
def wrapper(cls: type[MiddlewareT]) -> type[MiddlewareT]:
|
|
158
|
+
self.middlewares.append(cls(*args, **kwargs))
|
|
159
|
+
return cls
|
|
160
|
+
|
|
161
|
+
return wrapper
|
|
162
|
+
|
|
163
|
+
async def check(self, event: Update) -> bool:
|
|
164
|
+
match self.get_raw_event(event):
|
|
165
|
+
case Some(e) if issubclass(
|
|
166
|
+
self.event_model_class.expect(
|
|
167
|
+
"{!r} has no event model class in generic.".format(self.__class__.__qualname__),
|
|
168
|
+
),
|
|
169
|
+
e.__class__,
|
|
170
|
+
) and (self.handlers or self.middlewares):
|
|
171
|
+
return True
|
|
172
|
+
case _:
|
|
173
|
+
return False
|
|
174
|
+
|
|
175
|
+
async def process(self, event: Update, api: API) -> bool:
|
|
176
|
+
return await process_inner(
|
|
177
|
+
api,
|
|
178
|
+
self.event_model_class.unwrap().from_update(
|
|
179
|
+
update=self.get_raw_event(event).unwrap(),
|
|
180
|
+
bound_api=api,
|
|
181
|
+
),
|
|
182
|
+
event,
|
|
183
|
+
self.middlewares,
|
|
184
|
+
self.handlers,
|
|
185
|
+
self.return_manager,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
def load(self, external: typing.Self) -> None:
|
|
189
|
+
self.auto_rules.extend(external.auto_rules)
|
|
190
|
+
self.handlers.extend(external.handlers)
|
|
191
|
+
self.middlewares.extend(external.middlewares)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class BaseStateView(ABCStateView[Event], BaseView[Event], ABC, typing.Generic[Event]):
|
|
195
|
+
@abstractmethod
|
|
196
|
+
def get_state_key(self, event: Event) -> int | None:
|
|
197
|
+
pass
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
__all__ = ("ABCStateView", "ABCView", "BaseStateView", "BaseView")
|