telegrinder 0.1.dev165__py3-none-any.whl → 0.1.dev167__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 +20 -0
- telegrinder/api/abc.py +1 -1
- telegrinder/api/api.py +8 -6
- telegrinder/api/error.py +2 -3
- telegrinder/bot/__init__.py +12 -0
- telegrinder/bot/bot.py +2 -2
- telegrinder/bot/cute_types/__init__.py +4 -0
- telegrinder/bot/cute_types/base.py +10 -10
- telegrinder/bot/cute_types/callback_query.py +1 -3
- telegrinder/bot/cute_types/chat_join_request.py +65 -0
- telegrinder/bot/cute_types/chat_member_updated.py +246 -0
- telegrinder/bot/cute_types/message.py +44 -38
- telegrinder/bot/cute_types/update.py +5 -4
- telegrinder/bot/cute_types/utils.py +40 -20
- telegrinder/bot/dispatch/__init__.py +8 -1
- telegrinder/bot/dispatch/composition.py +7 -7
- telegrinder/bot/dispatch/context.py +9 -10
- telegrinder/bot/dispatch/dispatch.py +30 -22
- telegrinder/bot/dispatch/handler/abc.py +1 -0
- telegrinder/bot/dispatch/handler/func.py +21 -5
- telegrinder/bot/dispatch/handler/message_reply.py +2 -3
- telegrinder/bot/dispatch/middleware/abc.py +2 -4
- telegrinder/bot/dispatch/process.py +4 -3
- telegrinder/bot/dispatch/return_manager/__init__.py +1 -1
- telegrinder/bot/dispatch/return_manager/abc.py +28 -20
- telegrinder/bot/dispatch/return_manager/callback_query.py +4 -2
- telegrinder/bot/dispatch/return_manager/inline_query.py +4 -2
- telegrinder/bot/dispatch/return_manager/message.py +8 -4
- telegrinder/bot/dispatch/view/__init__.py +8 -2
- telegrinder/bot/dispatch/view/abc.py +27 -23
- telegrinder/bot/dispatch/view/box.py +74 -11
- telegrinder/bot/dispatch/view/callback_query.py +1 -3
- telegrinder/bot/dispatch/view/chat_join_request.py +17 -0
- telegrinder/bot/dispatch/view/chat_member.py +26 -0
- telegrinder/bot/dispatch/view/message.py +23 -1
- telegrinder/bot/dispatch/view/raw.py +112 -0
- telegrinder/bot/dispatch/waiter_machine/machine.py +41 -26
- telegrinder/bot/dispatch/waiter_machine/middleware.py +14 -7
- telegrinder/bot/dispatch/waiter_machine/short_state.py +10 -7
- telegrinder/bot/polling/polling.py +2 -4
- telegrinder/bot/rules/__init__.py +20 -12
- telegrinder/bot/rules/abc.py +0 -9
- telegrinder/bot/rules/adapter/event.py +29 -22
- telegrinder/bot/rules/callback_data.py +15 -18
- telegrinder/bot/rules/chat_join.py +47 -0
- telegrinder/bot/rules/enum_text.py +7 -2
- telegrinder/bot/rules/fuzzy.py +1 -2
- telegrinder/bot/rules/inline.py +3 -3
- telegrinder/bot/rules/is_from.py +39 -51
- telegrinder/bot/rules/markup.py +1 -2
- telegrinder/bot/rules/mention.py +1 -4
- telegrinder/bot/rules/message.py +17 -0
- telegrinder/bot/rules/message_entities.py +1 -1
- telegrinder/bot/rules/regex.py +1 -2
- telegrinder/bot/rules/rule_enum.py +1 -3
- telegrinder/bot/rules/start.py +7 -7
- telegrinder/bot/rules/text.py +2 -1
- telegrinder/bot/rules/update.py +16 -0
- telegrinder/bot/scenario/checkbox.py +5 -7
- telegrinder/client/aiohttp.py +5 -7
- telegrinder/model.py +37 -22
- telegrinder/modules.py +15 -33
- telegrinder/msgspec_utils.py +34 -35
- telegrinder/node/__init__.py +12 -12
- telegrinder/node/attachment.py +21 -7
- telegrinder/node/base.py +14 -13
- telegrinder/node/composer.py +5 -5
- telegrinder/node/container.py +1 -1
- telegrinder/node/message.py +3 -1
- telegrinder/node/rule.py +4 -4
- telegrinder/node/source.py +6 -2
- telegrinder/node/text.py +3 -1
- telegrinder/node/tools/generator.py +1 -1
- telegrinder/tools/__init__.py +3 -1
- telegrinder/tools/buttons.py +4 -6
- telegrinder/tools/error_handler/abc.py +1 -2
- telegrinder/tools/error_handler/error.py +3 -6
- telegrinder/tools/error_handler/error_handler.py +34 -24
- telegrinder/tools/formatting/html.py +9 -5
- telegrinder/tools/formatting/links.py +1 -3
- telegrinder/tools/formatting/spec_html_formats.py +1 -1
- telegrinder/tools/global_context/abc.py +3 -1
- telegrinder/tools/global_context/global_context.py +13 -31
- telegrinder/tools/global_context/telegrinder_ctx.py +1 -1
- telegrinder/tools/i18n/base.py +4 -3
- telegrinder/tools/i18n/middleware/base.py +1 -3
- telegrinder/tools/i18n/simple.py +1 -3
- telegrinder/tools/keyboard.py +1 -1
- telegrinder/tools/limited_dict.py +27 -0
- telegrinder/tools/loop_wrapper/loop_wrapper.py +18 -14
- telegrinder/tools/magic.py +1 -1
- telegrinder/types/__init__.py +236 -0
- telegrinder/types/enums.py +34 -0
- telegrinder/types/methods.py +52 -47
- telegrinder/types/objects.py +533 -90
- telegrinder/verification_utils.py +4 -1
- {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev167.dist-info}/METADATA +1 -1
- telegrinder-0.1.dev167.dist-info/RECORD +137 -0
- telegrinder-0.1.dev165.dist-info/RECORD +0 -128
- {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev167.dist-info}/LICENSE +0 -0
- {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev167.dist-info}/WHEEL +0 -0
|
@@ -78,11 +78,15 @@ class StringFormatter(string.Formatter):
|
|
|
78
78
|
with suppress(ValueError):
|
|
79
79
|
return HTMLFormatter(
|
|
80
80
|
format(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
(
|
|
82
|
+
value.formatting()
|
|
83
|
+
if isinstance(value, TagFormat)
|
|
84
|
+
else (
|
|
85
|
+
self.get_spec_formatter(value)(**value.__dict__).formatting()
|
|
86
|
+
if is_spec_format(value)
|
|
87
|
+
else value
|
|
88
|
+
)
|
|
89
|
+
),
|
|
86
90
|
fmt,
|
|
87
91
|
)
|
|
88
92
|
)
|
|
@@ -29,9 +29,7 @@ def get_invite_chat_link(invite_link: str) -> str:
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def user_open_message_link(user_id: int, message: str | None = None) -> str:
|
|
32
|
-
return f"tg://openmessage?user_id={user_id}" + (
|
|
33
|
-
"" if not message else f"&msg?text={message}"
|
|
34
|
-
)
|
|
32
|
+
return f"tg://openmessage?user_id={user_id}" + ("" if not message else f"&msg?text={message}")
|
|
35
33
|
|
|
36
34
|
|
|
37
35
|
__all__ = (
|
|
@@ -35,7 +35,9 @@ class GlobalCtxVar(typing.Generic[T]):
|
|
|
35
35
|
|
|
36
36
|
@classmethod
|
|
37
37
|
def collect(cls, name: str, ctx_value: T | CtxVariable[T]) -> typing.Self:
|
|
38
|
-
ctx_value =
|
|
38
|
+
ctx_value = (
|
|
39
|
+
CtxVar(ctx_value) if not isinstance(ctx_value, CtxVar | GlobalCtxVar) else ctx_value
|
|
40
|
+
)
|
|
39
41
|
params = ctx_value.__dict__
|
|
40
42
|
params["name"] = name
|
|
41
43
|
return cls(**params)
|
|
@@ -15,10 +15,8 @@ F = typing.TypeVar("F", bound=typing.Callable)
|
|
|
15
15
|
CtxValueT = typing.TypeVar("CtxValueT", default=typing.Any)
|
|
16
16
|
|
|
17
17
|
if typing.TYPE_CHECKING:
|
|
18
|
-
|
|
19
18
|
_: typing.TypeAlias = None
|
|
20
19
|
else:
|
|
21
|
-
|
|
22
20
|
_ = lambda: None
|
|
23
21
|
|
|
24
22
|
|
|
@@ -51,14 +49,10 @@ def root_protection(func: F) -> F:
|
|
|
51
49
|
|
|
52
50
|
@wraps(func)
|
|
53
51
|
def wrapper(self: "GlobalContext", name: str, /, *args) -> typing.Any:
|
|
54
|
-
if self.is_root_attribute(name) and name in (
|
|
55
|
-
self.__dict__ | self.__class__.__dict__
|
|
56
|
-
):
|
|
52
|
+
if self.is_root_attribute(name) and name in (self.__dict__ | self.__class__.__dict__):
|
|
57
53
|
root_attr = self.get_root_attribute(name).unwrap()
|
|
58
54
|
if all((not root_attr.can_be_rewritten, not root_attr.can_be_read)):
|
|
59
|
-
raise AttributeError(
|
|
60
|
-
f"Unable to set, get, delete root attribute {name!r}."
|
|
61
|
-
)
|
|
55
|
+
raise AttributeError(f"Unable to set, get, delete root attribute {name!r}.")
|
|
62
56
|
if func.__name__ == "__setattr__" and not root_attr.can_be_rewritten:
|
|
63
57
|
raise AttributeError(f"Unable to set root attribute {name!r}.")
|
|
64
58
|
if func.__name__ == "__getattr__" and not root_attr.can_be_read:
|
|
@@ -106,9 +100,7 @@ class Storage:
|
|
|
106
100
|
)
|
|
107
101
|
|
|
108
102
|
def __repr__(self) -> str:
|
|
109
|
-
return "<ContextStorage: %s>" % ", ".join(
|
|
110
|
-
"ctx @" + repr(x) for x in self._storage
|
|
111
|
-
)
|
|
103
|
+
return "<ContextStorage: %s>" % ", ".join("ctx @" + repr(x) for x in self._storage)
|
|
112
104
|
|
|
113
105
|
@property
|
|
114
106
|
def storage(self) -> dict[str, "GlobalContext"]:
|
|
@@ -132,7 +124,9 @@ class Storage:
|
|
|
132
124
|
order_default=True,
|
|
133
125
|
field_specifiers=(ctx_var,),
|
|
134
126
|
)
|
|
135
|
-
class GlobalContext(
|
|
127
|
+
class GlobalContext(
|
|
128
|
+
ABCGlobalContext, typing.Generic[CtxValueT], dict[str, GlobalCtxVar[CtxValueT]]
|
|
129
|
+
):
|
|
136
130
|
"""GlobalContext.
|
|
137
131
|
|
|
138
132
|
```
|
|
@@ -208,19 +202,14 @@ class GlobalContext(ABCGlobalContext, typing.Generic[CtxValueT], dict[str, Globa
|
|
|
208
202
|
"""Returns True if the names of context stores
|
|
209
203
|
that use self and __value instances are equivalent."""
|
|
210
204
|
|
|
211
|
-
return (
|
|
212
|
-
isinstance(__value, GlobalContext)
|
|
213
|
-
and self.__ctx_name__ == __value.__ctx_name__
|
|
214
|
-
)
|
|
205
|
+
return isinstance(__value, GlobalContext) and self.__ctx_name__ == __value.__ctx_name__
|
|
215
206
|
|
|
216
207
|
def __setitem__(self, __name: str, __value: CtxValueT | CtxVariable[CtxValueT]):
|
|
217
208
|
if is_dunder(__name):
|
|
218
209
|
raise NameError("Cannot set a context variable with dunder name.")
|
|
219
210
|
var = self.get(__name)
|
|
220
211
|
if var and var.unwrap().const:
|
|
221
|
-
raise TypeError(
|
|
222
|
-
f"Unable to set variable {__name!r}, because it's a constant."
|
|
223
|
-
)
|
|
212
|
+
raise TypeError(f"Unable to set variable {__name!r}, because it's a constant.")
|
|
224
213
|
dict.__setitem__(self, __name, GlobalCtxVar.collect(__name, __value))
|
|
225
214
|
|
|
226
215
|
def __getitem__(self, __name: str) -> CtxValueT:
|
|
@@ -229,9 +218,7 @@ class GlobalContext(ABCGlobalContext, typing.Generic[CtxValueT], dict[str, Globa
|
|
|
229
218
|
def __delitem__(self, __name: str):
|
|
230
219
|
var = self.get(__name).unwrap()
|
|
231
220
|
if var.const:
|
|
232
|
-
raise TypeError(
|
|
233
|
-
f"Unable to delete variable {__name!r}, because it's a constant."
|
|
234
|
-
)
|
|
221
|
+
raise TypeError(f"Unable to delete variable {__name!r}, because it's a constant.")
|
|
235
222
|
dict.__delitem__(self, __name)
|
|
236
223
|
|
|
237
224
|
@root_protection
|
|
@@ -328,9 +315,7 @@ class GlobalContext(ABCGlobalContext, typing.Generic[CtxValueT], dict[str, Globa
|
|
|
328
315
|
var_value_type: type[T],
|
|
329
316
|
) -> Option[GlobalCtxVar[T]]: ...
|
|
330
317
|
|
|
331
|
-
def pop(
|
|
332
|
-
self, var_name: str, var_value_type: type[T] = object
|
|
333
|
-
) -> Option[GlobalCtxVar[T]]:
|
|
318
|
+
def pop(self, var_name: str, var_value_type: type[T] = object) -> Option[GlobalCtxVar[T]]:
|
|
334
319
|
"""Pop context variable by name."""
|
|
335
320
|
|
|
336
321
|
val = self.get(var_name, var_value_type)
|
|
@@ -398,9 +383,7 @@ class GlobalContext(ABCGlobalContext, typing.Generic[CtxValueT], dict[str, Globa
|
|
|
398
383
|
|
|
399
384
|
var = self.get(old_var_name).unwrap()
|
|
400
385
|
if var.const:
|
|
401
|
-
return Error(
|
|
402
|
-
f"Unable to rename variable {old_var_name!r}, " "because it's a constant."
|
|
403
|
-
)
|
|
386
|
+
return Error(f"Unable to rename variable {old_var_name!r}, " "because it's a constant.")
|
|
404
387
|
del self[old_var_name]
|
|
405
388
|
self[new_var_name] = var.value
|
|
406
389
|
return Ok(_())
|
|
@@ -419,9 +402,8 @@ class GlobalContext(ABCGlobalContext, typing.Generic[CtxValueT], dict[str, Globa
|
|
|
419
402
|
return dict.clear(self)
|
|
420
403
|
|
|
421
404
|
for name, var in self.dict().items():
|
|
422
|
-
if var.const:
|
|
423
|
-
|
|
424
|
-
del self[name]
|
|
405
|
+
if not var.const:
|
|
406
|
+
del self[name]
|
|
425
407
|
|
|
426
408
|
def delete_ctx(self) -> Result[_, str]:
|
|
427
409
|
"""Delete context by `ctx_name`."""
|
|
@@ -7,7 +7,7 @@ from telegrinder.tools.global_context import GlobalContext, ctx_var
|
|
|
7
7
|
|
|
8
8
|
class TelegrinderCtx(GlobalContext):
|
|
9
9
|
"""Basic type-hinted telegrinder context with context name `"telegrinder"`.
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
You can use this class or GlobalContext:
|
|
12
12
|
```
|
|
13
13
|
from telegrinder.tools.global_context import GlobalContext, TelegrinderCtx
|
telegrinder/tools/i18n/base.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import enum
|
|
2
|
+
import typing
|
|
2
3
|
from abc import ABC, abstractmethod
|
|
3
4
|
|
|
4
5
|
|
|
@@ -9,14 +10,14 @@ class ABCI18n(ABC):
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class ABCTranslator(ABC):
|
|
12
|
-
def __init__(self, locale: str, **kwargs):
|
|
13
|
+
def __init__(self, locale: str, **kwargs: typing.Any) -> None:
|
|
13
14
|
self.locale = locale
|
|
14
15
|
|
|
15
16
|
@abstractmethod
|
|
16
|
-
def get(self, __key: str, *args, **kwargs) -> str:
|
|
17
|
+
def get(self, __key: str, *args: typing.Any, **kwargs: typing.Any) -> str:
|
|
17
18
|
"""This translates a key to actual human-readable string"""
|
|
18
19
|
|
|
19
|
-
def __call__(self, __key: str, *args, **kwargs):
|
|
20
|
+
def __call__(self, __key: str, *args: typing.Any, **kwargs: typing.Any) -> str:
|
|
20
21
|
return self.get(__key, *args, **kwargs)
|
|
21
22
|
|
|
22
23
|
|
|
@@ -17,9 +17,7 @@ class ABCTranslatorMiddleware(ABCMiddleware[T]):
|
|
|
17
17
|
pass
|
|
18
18
|
|
|
19
19
|
async def pre(self, event: T, ctx: dict) -> bool:
|
|
20
|
-
ctx[I18nEnum.I18N] = self.i18n.get_translator_by_locale(
|
|
21
|
-
await self.get_locale(event)
|
|
22
|
-
)
|
|
20
|
+
ctx[I18nEnum.I18N] = self.i18n.get_translator_by_locale(await self.get_locale(event))
|
|
23
21
|
return True
|
|
24
22
|
|
|
25
23
|
|
telegrinder/tools/i18n/simple.py
CHANGED
|
@@ -20,9 +20,7 @@ class SimpleI18n(ABCI18n):
|
|
|
20
20
|
if not os.path.isdir(os.path.join(self.folder, name)):
|
|
21
21
|
continue
|
|
22
22
|
|
|
23
|
-
mo_path = os.path.join(
|
|
24
|
-
self.folder, name, "LC_MESSAGES", f"{self.domain}.mo"
|
|
25
|
-
)
|
|
23
|
+
mo_path = os.path.join(self.folder, name, "LC_MESSAGES", f"{self.domain}.mo")
|
|
26
24
|
if os.path.exists(mo_path):
|
|
27
25
|
with open(mo_path, "rb") as f:
|
|
28
26
|
result[name] = gettext.GNUTranslations(f)
|
telegrinder/tools/keyboard.py
CHANGED
|
@@ -46,7 +46,7 @@ class ABCMarkup(ABC, typing.Generic[ButtonT]):
|
|
|
46
46
|
def add(self, row_or_button: RowButtons[ButtonT] | ButtonT) -> typing.Self:
|
|
47
47
|
if not len(self.keyboard):
|
|
48
48
|
self.row()
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
if isinstance(row_or_button, RowButtons):
|
|
51
51
|
self.keyboard[-1].extend(row_or_button.get_data())
|
|
52
52
|
if row_or_button.auto_row:
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
from collections import UserDict, deque
|
|
3
|
+
|
|
4
|
+
KT = typing.TypeVar("KT")
|
|
5
|
+
VT = typing.TypeVar("VT")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LimitedDict(UserDict[KT, VT]):
|
|
9
|
+
def __init__(self, *, maxlimit: int = 1000) -> None:
|
|
10
|
+
super().__init__()
|
|
11
|
+
self.maxlimit = maxlimit
|
|
12
|
+
self.queue: deque[KT] = deque(maxlen=maxlimit)
|
|
13
|
+
|
|
14
|
+
def __setitem__(self, key: KT, value: VT, /) -> None:
|
|
15
|
+
if len(self.queue) >= self.maxlimit:
|
|
16
|
+
self.pop(self.queue.popleft(), None)
|
|
17
|
+
if key not in self.queue:
|
|
18
|
+
self.queue.append(key)
|
|
19
|
+
super().__setitem__(key, value)
|
|
20
|
+
|
|
21
|
+
def __delitem__(self, key: KT) -> None:
|
|
22
|
+
if key in self.queue:
|
|
23
|
+
self.queue.remove(key)
|
|
24
|
+
return super().__delitem__(key)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
__all__ = ("LimitedDict",)
|
|
@@ -16,17 +16,20 @@ CoroutineFunc: typing.TypeAlias = typing.Callable[P, CoroutineTask[T]]
|
|
|
16
16
|
Task: typing.TypeAlias = typing.Union[CoroutineFunc, CoroutineTask, "DelayedTask"]
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
def run_tasks(
|
|
20
|
-
|
|
19
|
+
def run_tasks(
|
|
20
|
+
tasks: list[CoroutineTask[typing.Any]],
|
|
21
|
+
loop: asyncio.AbstractEventLoop,
|
|
22
|
+
) -> None:
|
|
23
|
+
while tasks:
|
|
21
24
|
loop.run_until_complete(tasks.pop(0))
|
|
22
25
|
|
|
23
26
|
|
|
24
|
-
def to_coroutine_task(task: Task) -> CoroutineTask:
|
|
27
|
+
def to_coroutine_task(task: Task) -> CoroutineTask[typing.Any]:
|
|
25
28
|
if asyncio.iscoroutinefunction(task) or isinstance(task, DelayedTask):
|
|
26
29
|
task = task()
|
|
27
30
|
elif not asyncio.iscoroutine(task):
|
|
28
|
-
raise TypeError("Task should be coroutine or coroutine function.")
|
|
29
|
-
return task
|
|
31
|
+
raise TypeError("Task should be coroutine or coroutine function.")
|
|
32
|
+
return task
|
|
30
33
|
|
|
31
34
|
|
|
32
35
|
@dataclasses.dataclass
|
|
@@ -63,15 +66,15 @@ class Lifespan:
|
|
|
63
66
|
task_or_func = to_coroutine_task(task_or_func)
|
|
64
67
|
self.startup_tasks.append(task_or_func)
|
|
65
68
|
return task_or_func
|
|
66
|
-
|
|
69
|
+
|
|
67
70
|
def on_shutdown(self, task_or_func: Task) -> Task:
|
|
68
71
|
task_or_func = to_coroutine_task(task_or_func)
|
|
69
72
|
self.shutdown_tasks.append(task_or_func)
|
|
70
73
|
return task_or_func
|
|
71
|
-
|
|
74
|
+
|
|
72
75
|
def start(self, loop: asyncio.AbstractEventLoop) -> None:
|
|
73
76
|
run_tasks(self.startup_tasks, loop)
|
|
74
|
-
|
|
77
|
+
|
|
75
78
|
def shutdown(self, loop: asyncio.AbstractEventLoop) -> None:
|
|
76
79
|
run_tasks(self.shutdown_tasks, loop)
|
|
77
80
|
|
|
@@ -86,7 +89,7 @@ class LoopWrapper(ABCLoopWrapper):
|
|
|
86
89
|
self.tasks: list[CoroutineTask[typing.Any]] = tasks or []
|
|
87
90
|
self.lifespan = lifespan or Lifespan()
|
|
88
91
|
self._loop = asyncio.new_event_loop()
|
|
89
|
-
|
|
92
|
+
|
|
90
93
|
def __repr__(self) -> str:
|
|
91
94
|
return "<{}: loop={!r} with tasks={!r}, lifespan={!r}>".format(
|
|
92
95
|
self.__class__.__name__,
|
|
@@ -94,15 +97,16 @@ class LoopWrapper(ABCLoopWrapper):
|
|
|
94
97
|
self.tasks,
|
|
95
98
|
self.lifespan,
|
|
96
99
|
)
|
|
97
|
-
|
|
100
|
+
|
|
98
101
|
def run_event_loop(self) -> None:
|
|
99
102
|
if not self.tasks:
|
|
100
103
|
logger.warning("You run loop with 0 tasks!")
|
|
101
104
|
|
|
102
105
|
self.lifespan.start(self._loop)
|
|
103
|
-
|
|
106
|
+
while self.tasks:
|
|
107
|
+
self._loop.create_task(self.tasks.pop(0))
|
|
104
108
|
tasks = asyncio.all_tasks(self._loop)
|
|
105
|
-
|
|
109
|
+
|
|
106
110
|
try:
|
|
107
111
|
while tasks:
|
|
108
112
|
tasks_results, _ = self._loop.run_until_complete(
|
|
@@ -122,7 +126,7 @@ class LoopWrapper(ABCLoopWrapper):
|
|
|
122
126
|
self.lifespan.shutdown(self._loop)
|
|
123
127
|
if self._loop.is_running():
|
|
124
128
|
self._loop.close()
|
|
125
|
-
|
|
129
|
+
|
|
126
130
|
def add_task(self, task: Task) -> None:
|
|
127
131
|
task = to_coroutine_task(task)
|
|
128
132
|
|
|
@@ -130,7 +134,7 @@ class LoopWrapper(ABCLoopWrapper):
|
|
|
130
134
|
self._loop.create_task(task)
|
|
131
135
|
else:
|
|
132
136
|
self.tasks.append(task)
|
|
133
|
-
|
|
137
|
+
|
|
134
138
|
def complete_tasks(self, tasks: set[asyncio.Task[typing.Any]]) -> None:
|
|
135
139
|
tasks = tasks | asyncio.all_tasks(self._loop)
|
|
136
140
|
task_to_cancel = asyncio.gather(*tasks, return_exceptions=True)
|
telegrinder/tools/magic.py
CHANGED
telegrinder/types/__init__.py
CHANGED
|
@@ -1,2 +1,238 @@
|
|
|
1
1
|
from telegrinder.types.enums import *
|
|
2
2
|
from telegrinder.types.objects import *
|
|
3
|
+
|
|
4
|
+
__all__ = (
|
|
5
|
+
"Animation",
|
|
6
|
+
"Audio",
|
|
7
|
+
"BackgroundFill",
|
|
8
|
+
"BackgroundFillFreeformGradient",
|
|
9
|
+
"BackgroundFillGradient",
|
|
10
|
+
"BackgroundFillSolid",
|
|
11
|
+
"BackgroundType",
|
|
12
|
+
"BackgroundTypeChatTheme",
|
|
13
|
+
"BackgroundTypeFill",
|
|
14
|
+
"BackgroundTypePattern",
|
|
15
|
+
"BackgroundTypeWallpaper",
|
|
16
|
+
"Birthdate",
|
|
17
|
+
"BotCommand",
|
|
18
|
+
"BotCommandScope",
|
|
19
|
+
"BotCommandScopeAllChatAdministrators",
|
|
20
|
+
"BotCommandScopeAllGroupChats",
|
|
21
|
+
"BotCommandScopeAllPrivateChats",
|
|
22
|
+
"BotCommandScopeChat",
|
|
23
|
+
"BotCommandScopeChatAdministrators",
|
|
24
|
+
"BotCommandScopeChatMember",
|
|
25
|
+
"BotCommandScopeDefault",
|
|
26
|
+
"BotCommandScopeType",
|
|
27
|
+
"BotDescription",
|
|
28
|
+
"BotName",
|
|
29
|
+
"BotShortDescription",
|
|
30
|
+
"BusinessConnection",
|
|
31
|
+
"BusinessIntro",
|
|
32
|
+
"BusinessLocation",
|
|
33
|
+
"BusinessMessagesDeleted",
|
|
34
|
+
"BusinessOpeningHours",
|
|
35
|
+
"BusinessOpeningHoursInterval",
|
|
36
|
+
"CallbackGame",
|
|
37
|
+
"CallbackQuery",
|
|
38
|
+
"Chat",
|
|
39
|
+
"ChatAction",
|
|
40
|
+
"ChatAdministratorRights",
|
|
41
|
+
"ChatBackground",
|
|
42
|
+
"ChatBoost",
|
|
43
|
+
"ChatBoostAdded",
|
|
44
|
+
"ChatBoostRemoved",
|
|
45
|
+
"ChatBoostSource",
|
|
46
|
+
"ChatBoostSourceGiftCode",
|
|
47
|
+
"ChatBoostSourceGiveaway",
|
|
48
|
+
"ChatBoostSourcePremium",
|
|
49
|
+
"ChatBoostSourceType",
|
|
50
|
+
"ChatBoostUpdated",
|
|
51
|
+
"ChatFullInfo",
|
|
52
|
+
"ChatInviteLink",
|
|
53
|
+
"ChatJoinRequest",
|
|
54
|
+
"ChatLocation",
|
|
55
|
+
"ChatMember",
|
|
56
|
+
"ChatMemberAdministrator",
|
|
57
|
+
"ChatMemberBanned",
|
|
58
|
+
"ChatMemberLeft",
|
|
59
|
+
"ChatMemberMember",
|
|
60
|
+
"ChatMemberOwner",
|
|
61
|
+
"ChatMemberRestricted",
|
|
62
|
+
"ChatMemberStatus",
|
|
63
|
+
"ChatMemberUpdated",
|
|
64
|
+
"ChatPermissions",
|
|
65
|
+
"ChatPhoto",
|
|
66
|
+
"ChatShared",
|
|
67
|
+
"ChatType",
|
|
68
|
+
"ChosenInlineResult",
|
|
69
|
+
"Contact",
|
|
70
|
+
"ContentType",
|
|
71
|
+
"Currency",
|
|
72
|
+
"DefaultAccentColor",
|
|
73
|
+
"Dice",
|
|
74
|
+
"DiceEmoji",
|
|
75
|
+
"Document",
|
|
76
|
+
"EncryptedCredentials",
|
|
77
|
+
"EncryptedPassportElement",
|
|
78
|
+
"EncryptedPassportElementType",
|
|
79
|
+
"ExternalReplyInfo",
|
|
80
|
+
"File",
|
|
81
|
+
"ForceReply",
|
|
82
|
+
"ForumTopic",
|
|
83
|
+
"ForumTopicClosed",
|
|
84
|
+
"ForumTopicCreated",
|
|
85
|
+
"ForumTopicEdited",
|
|
86
|
+
"ForumTopicReopened",
|
|
87
|
+
"Game",
|
|
88
|
+
"GameHighScore",
|
|
89
|
+
"GeneralForumTopicHidden",
|
|
90
|
+
"GeneralForumTopicUnhidden",
|
|
91
|
+
"Giveaway",
|
|
92
|
+
"GiveawayCompleted",
|
|
93
|
+
"GiveawayCreated",
|
|
94
|
+
"GiveawayWinners",
|
|
95
|
+
"InaccessibleMessage",
|
|
96
|
+
"InlineKeyboardButton",
|
|
97
|
+
"InlineKeyboardMarkup",
|
|
98
|
+
"InlineQuery",
|
|
99
|
+
"InlineQueryChatType",
|
|
100
|
+
"InlineQueryResult",
|
|
101
|
+
"InlineQueryResultArticle",
|
|
102
|
+
"InlineQueryResultAudio",
|
|
103
|
+
"InlineQueryResultCachedAudio",
|
|
104
|
+
"InlineQueryResultCachedDocument",
|
|
105
|
+
"InlineQueryResultCachedGif",
|
|
106
|
+
"InlineQueryResultCachedMpeg4Gif",
|
|
107
|
+
"InlineQueryResultCachedPhoto",
|
|
108
|
+
"InlineQueryResultCachedSticker",
|
|
109
|
+
"InlineQueryResultCachedVideo",
|
|
110
|
+
"InlineQueryResultCachedVoice",
|
|
111
|
+
"InlineQueryResultContact",
|
|
112
|
+
"InlineQueryResultDocument",
|
|
113
|
+
"InlineQueryResultDocumentMimeType",
|
|
114
|
+
"InlineQueryResultGame",
|
|
115
|
+
"InlineQueryResultGif",
|
|
116
|
+
"InlineQueryResultGifThumbnailMimeType",
|
|
117
|
+
"InlineQueryResultLocation",
|
|
118
|
+
"InlineQueryResultMimeType",
|
|
119
|
+
"InlineQueryResultMpeg4Gif",
|
|
120
|
+
"InlineQueryResultMpeg4GifThumbnailMimeType",
|
|
121
|
+
"InlineQueryResultPhoto",
|
|
122
|
+
"InlineQueryResultThumbnailMimeType",
|
|
123
|
+
"InlineQueryResultVenue",
|
|
124
|
+
"InlineQueryResultVideo",
|
|
125
|
+
"InlineQueryResultVideoMimeType",
|
|
126
|
+
"InlineQueryResultVoice",
|
|
127
|
+
"InlineQueryResultsButton",
|
|
128
|
+
"InputContactMessageContent",
|
|
129
|
+
"InputFile",
|
|
130
|
+
"InputInvoiceMessageContent",
|
|
131
|
+
"InputLocationMessageContent",
|
|
132
|
+
"InputMedia",
|
|
133
|
+
"InputMediaAnimation",
|
|
134
|
+
"InputMediaAudio",
|
|
135
|
+
"InputMediaDocument",
|
|
136
|
+
"InputMediaPhoto",
|
|
137
|
+
"InputMediaVideo",
|
|
138
|
+
"InputMessageContent",
|
|
139
|
+
"InputPollOption",
|
|
140
|
+
"InputSticker",
|
|
141
|
+
"InputTextMessageContent",
|
|
142
|
+
"InputVenueMessageContent",
|
|
143
|
+
"Invoice",
|
|
144
|
+
"KeyboardButton",
|
|
145
|
+
"KeyboardButtonPollType",
|
|
146
|
+
"KeyboardButtonRequestChat",
|
|
147
|
+
"KeyboardButtonRequestUsers",
|
|
148
|
+
"LabeledPrice",
|
|
149
|
+
"LinkPreviewOptions",
|
|
150
|
+
"Location",
|
|
151
|
+
"LoginUrl",
|
|
152
|
+
"MaskPosition",
|
|
153
|
+
"MaskPositionPoint",
|
|
154
|
+
"MaybeInaccessibleMessage",
|
|
155
|
+
"MenuButton",
|
|
156
|
+
"MenuButtonCommands",
|
|
157
|
+
"MenuButtonDefault",
|
|
158
|
+
"MenuButtonWebApp",
|
|
159
|
+
"Message",
|
|
160
|
+
"MessageAutoDeleteTimerChanged",
|
|
161
|
+
"MessageEntity",
|
|
162
|
+
"MessageEntityType",
|
|
163
|
+
"MessageId",
|
|
164
|
+
"MessageOrigin",
|
|
165
|
+
"MessageOriginChannel",
|
|
166
|
+
"MessageOriginChat",
|
|
167
|
+
"MessageOriginHiddenUser",
|
|
168
|
+
"MessageOriginType",
|
|
169
|
+
"MessageOriginUser",
|
|
170
|
+
"MessageReactionCountUpdated",
|
|
171
|
+
"MessageReactionUpdated",
|
|
172
|
+
"Model",
|
|
173
|
+
"OrderInfo",
|
|
174
|
+
"PassportData",
|
|
175
|
+
"PassportElementError",
|
|
176
|
+
"PassportElementErrorDataField",
|
|
177
|
+
"PassportElementErrorFile",
|
|
178
|
+
"PassportElementErrorFiles",
|
|
179
|
+
"PassportElementErrorFrontSide",
|
|
180
|
+
"PassportElementErrorReverseSide",
|
|
181
|
+
"PassportElementErrorSelfie",
|
|
182
|
+
"PassportElementErrorTranslationFile",
|
|
183
|
+
"PassportElementErrorTranslationFiles",
|
|
184
|
+
"PassportElementErrorType",
|
|
185
|
+
"PassportElementErrorUnspecified",
|
|
186
|
+
"PassportFile",
|
|
187
|
+
"PhotoSize",
|
|
188
|
+
"Poll",
|
|
189
|
+
"PollAnswer",
|
|
190
|
+
"PollOption",
|
|
191
|
+
"PollType",
|
|
192
|
+
"PreCheckoutQuery",
|
|
193
|
+
"ProgrammingLanguage",
|
|
194
|
+
"ProximityAlertTriggered",
|
|
195
|
+
"ReactionCount",
|
|
196
|
+
"ReactionEmoji",
|
|
197
|
+
"ReactionType",
|
|
198
|
+
"ReactionTypeCustomEmoji",
|
|
199
|
+
"ReactionTypeEmoji",
|
|
200
|
+
"ReactionTypeType",
|
|
201
|
+
"ReplyKeyboardMarkup",
|
|
202
|
+
"ReplyKeyboardRemove",
|
|
203
|
+
"ReplyParameters",
|
|
204
|
+
"ResponseParameters",
|
|
205
|
+
"SentWebAppMessage",
|
|
206
|
+
"SharedUser",
|
|
207
|
+
"ShippingAddress",
|
|
208
|
+
"ShippingOption",
|
|
209
|
+
"ShippingQuery",
|
|
210
|
+
"Sticker",
|
|
211
|
+
"StickerFormat",
|
|
212
|
+
"StickerSet",
|
|
213
|
+
"StickerSetStickerType",
|
|
214
|
+
"StickerType",
|
|
215
|
+
"Story",
|
|
216
|
+
"SuccessfulPayment",
|
|
217
|
+
"SwitchInlineQueryChosenChat",
|
|
218
|
+
"TextQuote",
|
|
219
|
+
"TopicIconColor",
|
|
220
|
+
"Update",
|
|
221
|
+
"UpdateType",
|
|
222
|
+
"User",
|
|
223
|
+
"UserChatBoosts",
|
|
224
|
+
"UserProfilePhotos",
|
|
225
|
+
"UsersShared",
|
|
226
|
+
"Venue",
|
|
227
|
+
"Video",
|
|
228
|
+
"VideoChatEnded",
|
|
229
|
+
"VideoChatParticipantsInvited",
|
|
230
|
+
"VideoChatScheduled",
|
|
231
|
+
"VideoChatStarted",
|
|
232
|
+
"VideoNote",
|
|
233
|
+
"Voice",
|
|
234
|
+
"WebAppData",
|
|
235
|
+
"WebAppInfo",
|
|
236
|
+
"WebhookInfo",
|
|
237
|
+
"WriteAccessAllowed",
|
|
238
|
+
)
|
telegrinder/types/enums.py
CHANGED
|
@@ -657,3 +657,37 @@ class StickerFormat(str, enum.Enum):
|
|
|
657
657
|
STATIC = "static"
|
|
658
658
|
ANIMATED = "animated"
|
|
659
659
|
VIDEO = "video"
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
__all__ = (
|
|
663
|
+
"BotCommandScopeType",
|
|
664
|
+
"ChatAction",
|
|
665
|
+
"ChatBoostSourceType",
|
|
666
|
+
"ChatMemberStatus",
|
|
667
|
+
"ChatType",
|
|
668
|
+
"ContentType",
|
|
669
|
+
"Currency",
|
|
670
|
+
"DefaultAccentColor",
|
|
671
|
+
"DiceEmoji",
|
|
672
|
+
"EncryptedPassportElementType",
|
|
673
|
+
"InlineQueryChatType",
|
|
674
|
+
"InlineQueryResultDocumentMimeType",
|
|
675
|
+
"InlineQueryResultGifThumbnailMimeType",
|
|
676
|
+
"InlineQueryResultMimeType",
|
|
677
|
+
"InlineQueryResultMpeg4GifThumbnailMimeType",
|
|
678
|
+
"InlineQueryResultThumbnailMimeType",
|
|
679
|
+
"InlineQueryResultVideoMimeType",
|
|
680
|
+
"MaskPositionPoint",
|
|
681
|
+
"MessageEntityType",
|
|
682
|
+
"MessageOriginType",
|
|
683
|
+
"PassportElementErrorType",
|
|
684
|
+
"PollType",
|
|
685
|
+
"ProgrammingLanguage",
|
|
686
|
+
"ReactionEmoji",
|
|
687
|
+
"ReactionTypeType",
|
|
688
|
+
"StickerFormat",
|
|
689
|
+
"StickerSetStickerType",
|
|
690
|
+
"StickerType",
|
|
691
|
+
"TopicIconColor",
|
|
692
|
+
"UpdateType",
|
|
693
|
+
)
|