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,118 +1,114 @@
|
|
|
1
|
-
import typing
|
|
2
|
-
|
|
3
|
-
from telegrinder.api.api import API
|
|
4
|
-
from telegrinder.bot.cute_types.update import UpdateCute
|
|
5
|
-
from telegrinder.bot.dispatch.handler.func import FuncHandler
|
|
6
|
-
from telegrinder.bot.dispatch.process import process_inner
|
|
7
|
-
from telegrinder.bot.dispatch.view.abc import ABCEventRawView
|
|
8
|
-
from telegrinder.bot.dispatch.view.base import BaseView, ErrorHandlerT
|
|
9
|
-
from telegrinder.bot.rules.abc import ABCRule
|
|
10
|
-
from telegrinder.tools.error_handler.error_handler import ABCErrorHandler, ErrorHandler
|
|
11
|
-
from telegrinder.types.enums import UpdateType
|
|
12
|
-
from telegrinder.types.objects import Update
|
|
13
|
-
|
|
14
|
-
T = typing.TypeVar("T", contravariant=True)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
self
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
__all__ = ("RawEventView",)
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from telegrinder.api.api import API
|
|
4
|
+
from telegrinder.bot.cute_types.update import UpdateCute
|
|
5
|
+
from telegrinder.bot.dispatch.handler.func import Func, FuncHandler
|
|
6
|
+
from telegrinder.bot.dispatch.process import process_inner
|
|
7
|
+
from telegrinder.bot.dispatch.view.abc import ABCEventRawView
|
|
8
|
+
from telegrinder.bot.dispatch.view.base import BaseView, ErrorHandlerT
|
|
9
|
+
from telegrinder.bot.rules.abc import ABCRule
|
|
10
|
+
from telegrinder.tools.error_handler.error_handler import ABCErrorHandler, ErrorHandler
|
|
11
|
+
from telegrinder.types.enums import UpdateType
|
|
12
|
+
from telegrinder.types.objects import Update
|
|
13
|
+
|
|
14
|
+
T = typing.TypeVar("T", contravariant=True)
|
|
15
|
+
R = typing.TypeVar("R", covariant=True)
|
|
16
|
+
P = typing.ParamSpec("P")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class RawEventView(ABCEventRawView[UpdateCute], BaseView[UpdateCute]):
|
|
20
|
+
def __init__(self) -> None:
|
|
21
|
+
self.auto_rules = []
|
|
22
|
+
self.handlers = []
|
|
23
|
+
self.middlewares = []
|
|
24
|
+
self.return_manager = None
|
|
25
|
+
|
|
26
|
+
@typing.overload
|
|
27
|
+
def __call__(
|
|
28
|
+
self,
|
|
29
|
+
update_type: UpdateType,
|
|
30
|
+
*rules: ABCRule,
|
|
31
|
+
) -> typing.Callable[
|
|
32
|
+
[Func[P, R]],
|
|
33
|
+
FuncHandler[UpdateCute, Func[P, R], ErrorHandler[UpdateCute]],
|
|
34
|
+
]: ...
|
|
35
|
+
|
|
36
|
+
@typing.overload
|
|
37
|
+
def __call__(
|
|
38
|
+
self,
|
|
39
|
+
update_type: UpdateType,
|
|
40
|
+
*rules: ABCRule,
|
|
41
|
+
dataclass: type[T],
|
|
42
|
+
) -> typing.Callable[[Func[P, R]], FuncHandler[UpdateCute, Func[P, R], ErrorHandler[T]]]: ...
|
|
43
|
+
|
|
44
|
+
@typing.overload
|
|
45
|
+
def __call__(
|
|
46
|
+
self,
|
|
47
|
+
update_type: UpdateType,
|
|
48
|
+
*rules: ABCRule,
|
|
49
|
+
error_handler: ErrorHandlerT,
|
|
50
|
+
) -> typing.Callable[
|
|
51
|
+
[Func[P, R]],
|
|
52
|
+
FuncHandler[UpdateCute, Func[P, R], ErrorHandlerT],
|
|
53
|
+
]: ...
|
|
54
|
+
|
|
55
|
+
@typing.overload
|
|
56
|
+
def __call__(
|
|
57
|
+
self,
|
|
58
|
+
update_type: UpdateType,
|
|
59
|
+
*rules: ABCRule,
|
|
60
|
+
dataclass: type[typing.Any],
|
|
61
|
+
error_handler: ErrorHandlerT,
|
|
62
|
+
is_blocking: bool = True,
|
|
63
|
+
) -> typing.Callable[[Func[P, R]], FuncHandler[UpdateCute, Func[P, R], ErrorHandlerT]]: ...
|
|
64
|
+
|
|
65
|
+
@typing.overload
|
|
66
|
+
def __call__(
|
|
67
|
+
self,
|
|
68
|
+
update_type: UpdateType,
|
|
69
|
+
*rules: ABCRule,
|
|
70
|
+
dataclass: None = None,
|
|
71
|
+
error_handler: None = None,
|
|
72
|
+
is_blocking: bool = True,
|
|
73
|
+
) -> typing.Callable[
|
|
74
|
+
[Func[P, R]],
|
|
75
|
+
FuncHandler[UpdateCute, Func[P, R], ErrorHandler[UpdateCute]],
|
|
76
|
+
]: ...
|
|
77
|
+
|
|
78
|
+
def __call__( # type: ignore
|
|
79
|
+
self,
|
|
80
|
+
update_type: UpdateType,
|
|
81
|
+
*rules: ABCRule,
|
|
82
|
+
dataclass: type[typing.Any] | None = None,
|
|
83
|
+
error_handler: ABCErrorHandler | None = None,
|
|
84
|
+
is_blocking: bool = True,
|
|
85
|
+
):
|
|
86
|
+
def wrapper(func):
|
|
87
|
+
func_handler = FuncHandler(
|
|
88
|
+
func,
|
|
89
|
+
rules=[*self.auto_rules, *rules],
|
|
90
|
+
is_blocking=is_blocking,
|
|
91
|
+
dataclass=dataclass,
|
|
92
|
+
error_handler=error_handler or ErrorHandler(),
|
|
93
|
+
update_type=update_type,
|
|
94
|
+
)
|
|
95
|
+
self.handlers.append(func_handler)
|
|
96
|
+
return func_handler
|
|
97
|
+
|
|
98
|
+
return wrapper
|
|
99
|
+
|
|
100
|
+
async def check(self, event: Update) -> bool:
|
|
101
|
+
return bool(self.handlers) or bool(self.middlewares)
|
|
102
|
+
|
|
103
|
+
async def process(self, event: Update, api: API) -> bool:
|
|
104
|
+
return await process_inner(
|
|
105
|
+
api,
|
|
106
|
+
UpdateCute.from_update(event, bound_api=api),
|
|
107
|
+
event,
|
|
108
|
+
self.middlewares,
|
|
109
|
+
self.handlers,
|
|
110
|
+
self.return_manager,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
__all__ = ("RawEventView",)
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
from telegrinder.bot.dispatch.waiter_machine.hasher import (
|
|
2
|
-
CALLBACK_QUERY_FOR_MESSAGE,
|
|
3
|
-
CALLBACK_QUERY_FROM_CHAT,
|
|
4
|
-
CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE,
|
|
5
|
-
MESSAGE_FROM_USER,
|
|
6
|
-
MESSAGE_FROM_USER_IN_CHAT,
|
|
7
|
-
MESSAGE_IN_CHAT,
|
|
8
|
-
Hasher,
|
|
9
|
-
StateViewHasher,
|
|
10
|
-
)
|
|
11
|
-
from telegrinder.bot.dispatch.waiter_machine.machine import WaiterMachine, clear_wm_storage_worker
|
|
12
|
-
from telegrinder.bot.dispatch.waiter_machine.middleware import WaiterMiddleware
|
|
13
|
-
from telegrinder.bot.dispatch.waiter_machine.short_state import ShortState
|
|
14
|
-
|
|
15
|
-
__all__ = (
|
|
1
|
+
from telegrinder.bot.dispatch.waiter_machine.hasher import (
|
|
2
|
+
CALLBACK_QUERY_FOR_MESSAGE,
|
|
3
|
+
CALLBACK_QUERY_FROM_CHAT,
|
|
4
|
+
CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE,
|
|
5
|
+
MESSAGE_FROM_USER,
|
|
6
|
+
MESSAGE_FROM_USER_IN_CHAT,
|
|
7
|
+
MESSAGE_IN_CHAT,
|
|
8
|
+
Hasher,
|
|
9
|
+
StateViewHasher,
|
|
10
|
+
)
|
|
11
|
+
from telegrinder.bot.dispatch.waiter_machine.machine import WaiterMachine, clear_wm_storage_worker
|
|
12
|
+
from telegrinder.bot.dispatch.waiter_machine.middleware import WaiterMiddleware
|
|
13
|
+
from telegrinder.bot.dispatch.waiter_machine.short_state import ShortState
|
|
14
|
+
|
|
15
|
+
__all__ = (
|
|
16
16
|
"CALLBACK_QUERY_FOR_MESSAGE",
|
|
17
17
|
"CALLBACK_QUERY_FROM_CHAT",
|
|
18
18
|
"CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE",
|
|
@@ -24,5 +24,5 @@ __all__ = (
|
|
|
24
24
|
"StateViewHasher",
|
|
25
25
|
"WaiterMachine",
|
|
26
26
|
"WaiterMiddleware",
|
|
27
|
-
"clear_wm_storage_worker",
|
|
28
|
-
)
|
|
27
|
+
"clear_wm_storage_worker",
|
|
28
|
+
)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import typing
|
|
2
|
-
|
|
3
|
-
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
4
|
-
|
|
5
|
-
from .short_state import EventModel, ShortState
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class WaiterActions(typing.TypedDict, typing.Generic[EventModel]):
|
|
9
|
-
on_miss: typing.NotRequired[ABCHandler[EventModel]]
|
|
10
|
-
on_drop: typing.NotRequired[typing.Callable[[ShortState[EventModel]], None]]
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__all__ = ("WaiterActions",)
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from telegrinder.bot.dispatch.handler.abc import ABCHandler
|
|
4
|
+
|
|
5
|
+
from .short_state import EventModel, ShortState
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class WaiterActions(typing.TypedDict, typing.Generic[EventModel]):
|
|
9
|
+
on_miss: typing.NotRequired[ABCHandler[EventModel]]
|
|
10
|
+
on_drop: typing.NotRequired[typing.Callable[[ShortState[EventModel]], None]]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
__all__ = ("WaiterActions",)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from .callback import CALLBACK_QUERY_FOR_MESSAGE, CALLBACK_QUERY_FROM_CHAT, CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE
|
|
2
|
-
from .hasher import Hasher
|
|
3
|
-
from .message import MESSAGE_FROM_USER, MESSAGE_FROM_USER_IN_CHAT, MESSAGE_IN_CHAT
|
|
4
|
-
from .state import StateViewHasher
|
|
5
|
-
|
|
6
|
-
__all__ = (
|
|
1
|
+
from .callback import CALLBACK_QUERY_FOR_MESSAGE, CALLBACK_QUERY_FROM_CHAT, CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE
|
|
2
|
+
from .hasher import Hasher
|
|
3
|
+
from .message import MESSAGE_FROM_USER, MESSAGE_FROM_USER_IN_CHAT, MESSAGE_IN_CHAT
|
|
4
|
+
from .state import StateViewHasher
|
|
5
|
+
|
|
6
|
+
__all__ = (
|
|
7
7
|
"CALLBACK_QUERY_FOR_MESSAGE",
|
|
8
8
|
"CALLBACK_QUERY_FROM_CHAT",
|
|
9
9
|
"CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE",
|
|
@@ -11,5 +11,5 @@ __all__ = (
|
|
|
11
11
|
"MESSAGE_FROM_USER",
|
|
12
12
|
"MESSAGE_FROM_USER_IN_CHAT",
|
|
13
13
|
"MESSAGE_IN_CHAT",
|
|
14
|
-
"StateViewHasher",
|
|
15
|
-
)
|
|
14
|
+
"StateViewHasher",
|
|
15
|
+
)
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
from fntypes.option import Some
|
|
2
|
-
|
|
3
|
-
from telegrinder.bot.cute_types import CallbackQueryCute as CallbackQuery
|
|
4
|
-
from telegrinder.bot.dispatch.view import CallbackQueryView
|
|
5
|
-
from telegrinder.bot.dispatch.waiter_machine.hasher.hasher import Hasher
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def from_chat_hash(chat_id: int) -> int:
|
|
9
|
-
return chat_id
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def get_chat_from_event(event: CallbackQuery) -> int | None:
|
|
13
|
-
return event.chat.and_then(lambda chat: Some(chat.id)).unwrap_or_none()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def for_message_hash(message_id: int) -> int:
|
|
17
|
-
return message_id
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def get_message_for_event(event: CallbackQuery) -> int | None:
|
|
21
|
-
return event.message_id.unwrap_or_none()
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def for_message_in_chat(chat_and_message: tuple[int, int]) -> str:
|
|
25
|
-
return f"{chat_and_message[0]}_{chat_and_message[1]}"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def get_chat_and_message_for_event(event: CallbackQuery) -> tuple[int, int] | None:
|
|
29
|
-
if not event.message_id or not event.chat:
|
|
30
|
-
return None
|
|
31
|
-
return event.chat.unwrap().id, event.message_id.unwrap()
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
CALLBACK_QUERY_FROM_CHAT = Hasher(
|
|
35
|
-
view_class=CallbackQueryView,
|
|
36
|
-
get_hash_from_data=from_chat_hash,
|
|
37
|
-
get_data_from_event=get_chat_from_event,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
CALLBACK_QUERY_FOR_MESSAGE = Hasher(
|
|
41
|
-
view_class=CallbackQueryView,
|
|
42
|
-
get_hash_from_data=for_message_hash,
|
|
43
|
-
get_data_from_event=get_message_for_event,
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE = Hasher(
|
|
47
|
-
view_class=CallbackQueryView,
|
|
48
|
-
get_hash_from_data=for_message_in_chat,
|
|
49
|
-
get_data_from_event=get_chat_and_message_for_event,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
__all__ = (
|
|
54
|
-
"CALLBACK_QUERY_FOR_MESSAGE",
|
|
55
|
-
"CALLBACK_QUERY_FROM_CHAT",
|
|
56
|
-
"CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE",
|
|
57
|
-
)
|
|
1
|
+
from fntypes.option import Some
|
|
2
|
+
|
|
3
|
+
from telegrinder.bot.cute_types import CallbackQueryCute as CallbackQuery
|
|
4
|
+
from telegrinder.bot.dispatch.view import CallbackQueryView
|
|
5
|
+
from telegrinder.bot.dispatch.waiter_machine.hasher.hasher import Hasher
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def from_chat_hash(chat_id: int) -> int:
|
|
9
|
+
return chat_id
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_chat_from_event(event: CallbackQuery) -> int | None:
|
|
13
|
+
return event.chat.and_then(lambda chat: Some(chat.id)).unwrap_or_none()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def for_message_hash(message_id: int) -> int:
|
|
17
|
+
return message_id
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_message_for_event(event: CallbackQuery) -> int | None:
|
|
21
|
+
return event.message_id.unwrap_or_none()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def for_message_in_chat(chat_and_message: tuple[int, int]) -> str:
|
|
25
|
+
return f"{chat_and_message[0]}_{chat_and_message[1]}"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_chat_and_message_for_event(event: CallbackQuery) -> tuple[int, int] | None:
|
|
29
|
+
if not event.message_id or not event.chat:
|
|
30
|
+
return None
|
|
31
|
+
return event.chat.unwrap().id, event.message_id.unwrap()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
CALLBACK_QUERY_FROM_CHAT = Hasher(
|
|
35
|
+
view_class=CallbackQueryView,
|
|
36
|
+
get_hash_from_data=from_chat_hash,
|
|
37
|
+
get_data_from_event=get_chat_from_event,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
CALLBACK_QUERY_FOR_MESSAGE = Hasher(
|
|
41
|
+
view_class=CallbackQueryView,
|
|
42
|
+
get_hash_from_data=for_message_hash,
|
|
43
|
+
get_data_from_event=get_message_for_event,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE = Hasher(
|
|
47
|
+
view_class=CallbackQueryView,
|
|
48
|
+
get_hash_from_data=for_message_in_chat,
|
|
49
|
+
get_data_from_event=get_chat_and_message_for_event,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
__all__ = (
|
|
54
|
+
"CALLBACK_QUERY_FOR_MESSAGE",
|
|
55
|
+
"CALLBACK_QUERY_FROM_CHAT",
|
|
56
|
+
"CALLBACK_QUERY_IN_CHAT_FOR_MESSAGE",
|
|
57
|
+
)
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import typing
|
|
2
|
-
from functools import cached_property
|
|
3
|
-
|
|
4
|
-
from fntypes.option import Option
|
|
5
|
-
|
|
6
|
-
from telegrinder.bot.cute_types import BaseCute
|
|
7
|
-
from telegrinder.bot.dispatch.view.base import BaseView
|
|
8
|
-
from telegrinder.tools.functional import from_optional
|
|
9
|
-
|
|
10
|
-
T = typing.TypeVar("T")
|
|
11
|
-
Event = typing.TypeVar("Event", bound=BaseCute)
|
|
12
|
-
Data = typing.TypeVar("Data")
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def _echo(__x: T) -> T:
|
|
16
|
-
return __x
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ECHO = _echo
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class Hasher(typing.Generic[Event, Data]):
|
|
23
|
-
def __init__(
|
|
24
|
-
self,
|
|
25
|
-
view_class: type[BaseView[Event]],
|
|
26
|
-
get_hash_from_data: typing.Callable[[Data], typing.Hashable | None] | None = None,
|
|
27
|
-
get_data_from_event: typing.Callable[[Event], Data | None] | None = None,
|
|
28
|
-
) -> None:
|
|
29
|
-
self.view_class = view_class
|
|
30
|
-
self._get_hash_from_data = get_hash_from_data
|
|
31
|
-
self._get_data_from_event = get_data_from_event
|
|
32
|
-
|
|
33
|
-
def __hash__(self) -> int:
|
|
34
|
-
return hash(self.name)
|
|
35
|
-
|
|
36
|
-
def __repr__(self) -> str:
|
|
37
|
-
return f"<Hasher {self.name}>"
|
|
38
|
-
|
|
39
|
-
@cached_property
|
|
40
|
-
def name(self) -> str:
|
|
41
|
-
return f"{self.view_class.__name__}_{id(self)}"
|
|
42
|
-
|
|
43
|
-
def get_hash_from_data(self, data: Data) -> Option[typing.Hashable]:
|
|
44
|
-
if self._get_hash_from_data is None:
|
|
45
|
-
raise NotImplementedError
|
|
46
|
-
return from_optional(self._get_hash_from_data(data))
|
|
47
|
-
|
|
48
|
-
def get_data_from_event(self, event: Event) -> Option[Data]:
|
|
49
|
-
if not self._get_data_from_event:
|
|
50
|
-
raise NotImplementedError
|
|
51
|
-
return from_optional(self._get_data_from_event(event))
|
|
52
|
-
|
|
53
|
-
def get_hash_from_data_from_event(self, event: Event) -> Option[typing.Hashable]:
|
|
54
|
-
return self.get_data_from_event(event).and_then(self.get_hash_from_data) # type: ignore
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
__all__ = ("Hasher",)
|
|
1
|
+
import typing
|
|
2
|
+
from functools import cached_property
|
|
3
|
+
|
|
4
|
+
from fntypes.option import Option
|
|
5
|
+
|
|
6
|
+
from telegrinder.bot.cute_types import BaseCute
|
|
7
|
+
from telegrinder.bot.dispatch.view.base import BaseView
|
|
8
|
+
from telegrinder.tools.functional import from_optional
|
|
9
|
+
|
|
10
|
+
T = typing.TypeVar("T")
|
|
11
|
+
Event = typing.TypeVar("Event", bound=BaseCute)
|
|
12
|
+
Data = typing.TypeVar("Data")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _echo(__x: T) -> T:
|
|
16
|
+
return __x
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
ECHO = _echo
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Hasher(typing.Generic[Event, Data]):
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
view_class: type[BaseView[Event]],
|
|
26
|
+
get_hash_from_data: typing.Callable[[Data], typing.Hashable | None] | None = None,
|
|
27
|
+
get_data_from_event: typing.Callable[[Event], Data | None] | None = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
self.view_class = view_class
|
|
30
|
+
self._get_hash_from_data = get_hash_from_data
|
|
31
|
+
self._get_data_from_event = get_data_from_event
|
|
32
|
+
|
|
33
|
+
def __hash__(self) -> int:
|
|
34
|
+
return hash(self.name)
|
|
35
|
+
|
|
36
|
+
def __repr__(self) -> str:
|
|
37
|
+
return f"<Hasher {self.name}>"
|
|
38
|
+
|
|
39
|
+
@cached_property
|
|
40
|
+
def name(self) -> str:
|
|
41
|
+
return f"{self.view_class.__name__}_{id(self)}"
|
|
42
|
+
|
|
43
|
+
def get_hash_from_data(self, data: Data) -> Option[typing.Hashable]:
|
|
44
|
+
if self._get_hash_from_data is None:
|
|
45
|
+
raise NotImplementedError
|
|
46
|
+
return from_optional(self._get_hash_from_data(data))
|
|
47
|
+
|
|
48
|
+
def get_data_from_event(self, event: Event) -> Option[Data]:
|
|
49
|
+
if not self._get_data_from_event:
|
|
50
|
+
raise NotImplementedError
|
|
51
|
+
return from_optional(self._get_data_from_event(event))
|
|
52
|
+
|
|
53
|
+
def get_hash_from_data_from_event(self, event: Event) -> Option[typing.Hashable]:
|
|
54
|
+
return self.get_data_from_event(event).and_then(self.get_hash_from_data) # type: ignore
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
__all__ = ("Hasher",)
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
from telegrinder.bot.cute_types import MessageCute as Message
|
|
2
|
-
from telegrinder.bot.dispatch.view import MessageView
|
|
3
|
-
from telegrinder.bot.dispatch.waiter_machine.hasher.hasher import Hasher
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def from_chat_hash(chat_id: int) -> int:
|
|
7
|
-
return chat_id
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def get_chat_from_event(event: Message) -> int:
|
|
11
|
-
return event.chat.id
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def from_user_in_chat_hash(chat_and_user: tuple[int, int]) -> str:
|
|
15
|
-
return f"{chat_and_user[0]}_{chat_and_user[1]}"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def get_user_in_chat_from_event(event: Message) -> tuple[int, int]:
|
|
19
|
-
return event.chat.id, event.from_user.id
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def from_user_hash(from_id: int) -> int:
|
|
23
|
-
return from_id
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def get_user_from_event(event: Message) -> int:
|
|
27
|
-
return event.from_user.id
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
MESSAGE_IN_CHAT = Hasher(
|
|
31
|
-
view_class=MessageView,
|
|
32
|
-
get_hash_from_data=from_chat_hash,
|
|
33
|
-
get_data_from_event=get_chat_from_event,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
MESSAGE_FROM_USER = Hasher(
|
|
37
|
-
view_class=MessageView,
|
|
38
|
-
get_hash_from_data=from_user_hash,
|
|
39
|
-
get_data_from_event=get_user_from_event,
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
MESSAGE_FROM_USER_IN_CHAT = Hasher(
|
|
43
|
-
view_class=MessageView,
|
|
44
|
-
get_hash_from_data=from_user_in_chat_hash,
|
|
45
|
-
get_data_from_event=get_user_in_chat_from_event,
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
__all__ = (
|
|
50
|
-
"MESSAGE_FROM_USER",
|
|
51
|
-
"MESSAGE_FROM_USER_IN_CHAT",
|
|
52
|
-
"MESSAGE_IN_CHAT",
|
|
53
|
-
)
|
|
1
|
+
from telegrinder.bot.cute_types import MessageCute as Message
|
|
2
|
+
from telegrinder.bot.dispatch.view import MessageView
|
|
3
|
+
from telegrinder.bot.dispatch.waiter_machine.hasher.hasher import Hasher
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def from_chat_hash(chat_id: int) -> int:
|
|
7
|
+
return chat_id
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_chat_from_event(event: Message) -> int:
|
|
11
|
+
return event.chat.id
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def from_user_in_chat_hash(chat_and_user: tuple[int, int]) -> str:
|
|
15
|
+
return f"{chat_and_user[0]}_{chat_and_user[1]}"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_user_in_chat_from_event(event: Message) -> tuple[int, int]:
|
|
19
|
+
return event.chat.id, event.from_user.id
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def from_user_hash(from_id: int) -> int:
|
|
23
|
+
return from_id
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_user_from_event(event: Message) -> int:
|
|
27
|
+
return event.from_user.id
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
MESSAGE_IN_CHAT = Hasher(
|
|
31
|
+
view_class=MessageView,
|
|
32
|
+
get_hash_from_data=from_chat_hash,
|
|
33
|
+
get_data_from_event=get_chat_from_event,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
MESSAGE_FROM_USER = Hasher(
|
|
37
|
+
view_class=MessageView,
|
|
38
|
+
get_hash_from_data=from_user_hash,
|
|
39
|
+
get_data_from_event=get_user_from_event,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
MESSAGE_FROM_USER_IN_CHAT = Hasher(
|
|
43
|
+
view_class=MessageView,
|
|
44
|
+
get_hash_from_data=from_user_in_chat_hash,
|
|
45
|
+
get_data_from_event=get_user_in_chat_from_event,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
__all__ = (
|
|
50
|
+
"MESSAGE_FROM_USER",
|
|
51
|
+
"MESSAGE_FROM_USER_IN_CHAT",
|
|
52
|
+
"MESSAGE_IN_CHAT",
|
|
53
|
+
)
|