telegrinder 0.1.dev165__py3-none-any.whl → 0.1.dev166__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.

Files changed (88) hide show
  1. telegrinder/__init__.py +22 -0
  2. telegrinder/api/abc.py +1 -1
  3. telegrinder/api/api.py +8 -6
  4. telegrinder/api/error.py +2 -3
  5. telegrinder/bot/__init__.py +14 -0
  6. telegrinder/bot/bot.py +5 -3
  7. telegrinder/bot/cute_types/__init__.py +4 -0
  8. telegrinder/bot/cute_types/base.py +22 -13
  9. telegrinder/bot/cute_types/chat_join_request.py +63 -0
  10. telegrinder/bot/cute_types/chat_member_updated.py +244 -0
  11. telegrinder/bot/cute_types/message.py +34 -7
  12. telegrinder/bot/cute_types/update.py +5 -4
  13. telegrinder/bot/cute_types/utils.py +39 -17
  14. telegrinder/bot/dispatch/__init__.py +9 -1
  15. telegrinder/bot/dispatch/composition.py +10 -8
  16. telegrinder/bot/dispatch/context.py +9 -10
  17. telegrinder/bot/dispatch/dispatch.py +29 -19
  18. telegrinder/bot/dispatch/handler/abc.py +1 -0
  19. telegrinder/bot/dispatch/handler/func.py +29 -6
  20. telegrinder/bot/dispatch/handler/message_reply.py +2 -3
  21. telegrinder/bot/dispatch/middleware/abc.py +2 -4
  22. telegrinder/bot/dispatch/process.py +4 -3
  23. telegrinder/bot/dispatch/return_manager/__init__.py +1 -1
  24. telegrinder/bot/dispatch/return_manager/abc.py +33 -21
  25. telegrinder/bot/dispatch/return_manager/callback_query.py +4 -2
  26. telegrinder/bot/dispatch/return_manager/inline_query.py +4 -2
  27. telegrinder/bot/dispatch/return_manager/message.py +12 -6
  28. telegrinder/bot/dispatch/view/__init__.py +8 -2
  29. telegrinder/bot/dispatch/view/abc.py +26 -20
  30. telegrinder/bot/dispatch/view/box.py +72 -1
  31. telegrinder/bot/dispatch/view/callback_query.py +1 -3
  32. telegrinder/bot/dispatch/view/chat_join_request.py +17 -0
  33. telegrinder/bot/dispatch/view/chat_member.py +26 -0
  34. telegrinder/bot/dispatch/view/message.py +23 -1
  35. telegrinder/bot/dispatch/view/raw.py +116 -0
  36. telegrinder/bot/dispatch/waiter_machine/__init__.py +2 -1
  37. telegrinder/bot/dispatch/waiter_machine/machine.py +73 -19
  38. telegrinder/bot/dispatch/waiter_machine/middleware.py +3 -3
  39. telegrinder/bot/dispatch/waiter_machine/short_state.py +6 -3
  40. telegrinder/bot/polling/polling.py +4 -2
  41. telegrinder/bot/rules/__init__.py +20 -12
  42. telegrinder/bot/rules/abc.py +0 -9
  43. telegrinder/bot/rules/adapter/event.py +31 -22
  44. telegrinder/bot/rules/callback_data.py +15 -20
  45. telegrinder/bot/rules/chat_join.py +47 -0
  46. telegrinder/bot/rules/enum_text.py +7 -2
  47. telegrinder/bot/rules/inline.py +3 -3
  48. telegrinder/bot/rules/is_from.py +36 -50
  49. telegrinder/bot/rules/message.py +17 -0
  50. telegrinder/bot/rules/message_entities.py +1 -1
  51. telegrinder/bot/rules/start.py +6 -4
  52. telegrinder/bot/rules/text.py +2 -1
  53. telegrinder/bot/rules/update.py +16 -0
  54. telegrinder/bot/scenario/checkbox.py +9 -7
  55. telegrinder/client/aiohttp.py +4 -4
  56. telegrinder/model.py +33 -19
  57. telegrinder/modules.py +16 -32
  58. telegrinder/msgspec_utils.py +37 -36
  59. telegrinder/node/__init__.py +12 -12
  60. telegrinder/node/attachment.py +15 -5
  61. telegrinder/node/base.py +24 -16
  62. telegrinder/node/composer.py +8 -6
  63. telegrinder/node/container.py +1 -1
  64. telegrinder/node/rule.py +4 -4
  65. telegrinder/node/source.py +4 -2
  66. telegrinder/node/tools/generator.py +1 -1
  67. telegrinder/tools/__init__.py +1 -1
  68. telegrinder/tools/error_handler/abc.py +4 -3
  69. telegrinder/tools/error_handler/error_handler.py +22 -16
  70. telegrinder/tools/formatting/html.py +15 -7
  71. telegrinder/tools/formatting/spec_html_formats.py +1 -1
  72. telegrinder/tools/global_context/abc.py +5 -1
  73. telegrinder/tools/global_context/telegrinder_ctx.py +1 -1
  74. telegrinder/tools/i18n/base.py +4 -3
  75. telegrinder/tools/i18n/simple.py +1 -3
  76. telegrinder/tools/keyboard.py +1 -1
  77. telegrinder/tools/loop_wrapper/loop_wrapper.py +24 -16
  78. telegrinder/tools/magic.py +1 -1
  79. telegrinder/types/__init__.py +206 -0
  80. telegrinder/types/enums.py +34 -0
  81. telegrinder/types/methods.py +52 -47
  82. telegrinder/types/objects.py +531 -88
  83. telegrinder/verification_utils.py +3 -1
  84. {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev166.dist-info}/METADATA +1 -1
  85. telegrinder-0.1.dev166.dist-info/RECORD +136 -0
  86. telegrinder-0.1.dev165.dist-info/RECORD +0 -128
  87. {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev166.dist-info}/LICENSE +0 -0
  88. {telegrinder-0.1.dev165.dist-info → telegrinder-0.1.dev166.dist-info}/WHEEL +0 -0
@@ -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
@@ -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
 
@@ -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)
@@ -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:
@@ -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(tasks: list[CoroutineTask[typing.Any]], loop: asyncio.AbstractEventLoop) -> None:
20
- while len(tasks) != 0:
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
@@ -56,22 +59,26 @@ class DelayedTask(typing.Generic[CoroFunc]):
56
59
 
57
60
  @dataclasses.dataclass(kw_only=True)
58
61
  class Lifespan:
59
- startup_tasks: list[CoroutineTask[typing.Any]] = dataclasses.field(default_factory=lambda: [])
60
- shutdown_tasks: list[CoroutineTask[typing.Any]] = dataclasses.field(default_factory=lambda: [])
62
+ startup_tasks: list[CoroutineTask[typing.Any]] = dataclasses.field(
63
+ default_factory=lambda: []
64
+ )
65
+ shutdown_tasks: list[CoroutineTask[typing.Any]] = dataclasses.field(
66
+ default_factory=lambda: []
67
+ )
61
68
 
62
69
  def on_startup(self, task_or_func: Task) -> Task:
63
70
  task_or_func = to_coroutine_task(task_or_func)
64
71
  self.startup_tasks.append(task_or_func)
65
72
  return task_or_func
66
-
73
+
67
74
  def on_shutdown(self, task_or_func: Task) -> Task:
68
75
  task_or_func = to_coroutine_task(task_or_func)
69
76
  self.shutdown_tasks.append(task_or_func)
70
77
  return task_or_func
71
-
78
+
72
79
  def start(self, loop: asyncio.AbstractEventLoop) -> None:
73
80
  run_tasks(self.startup_tasks, loop)
74
-
81
+
75
82
  def shutdown(self, loop: asyncio.AbstractEventLoop) -> None:
76
83
  run_tasks(self.shutdown_tasks, loop)
77
84
 
@@ -86,7 +93,7 @@ class LoopWrapper(ABCLoopWrapper):
86
93
  self.tasks: list[CoroutineTask[typing.Any]] = tasks or []
87
94
  self.lifespan = lifespan or Lifespan()
88
95
  self._loop = asyncio.new_event_loop()
89
-
96
+
90
97
  def __repr__(self) -> str:
91
98
  return "<{}: loop={!r} with tasks={!r}, lifespan={!r}>".format(
92
99
  self.__class__.__name__,
@@ -94,15 +101,16 @@ class LoopWrapper(ABCLoopWrapper):
94
101
  self.tasks,
95
102
  self.lifespan,
96
103
  )
97
-
104
+
98
105
  def run_event_loop(self) -> None:
99
106
  if not self.tasks:
100
107
  logger.warning("You run loop with 0 tasks!")
101
108
 
102
109
  self.lifespan.start(self._loop)
103
- run_tasks(self.tasks, self._loop)
110
+ while self.tasks:
111
+ self._loop.create_task(self.tasks.pop(0))
104
112
  tasks = asyncio.all_tasks(self._loop)
105
-
113
+
106
114
  try:
107
115
  while tasks:
108
116
  tasks_results, _ = self._loop.run_until_complete(
@@ -122,7 +130,7 @@ class LoopWrapper(ABCLoopWrapper):
122
130
  self.lifespan.shutdown(self._loop)
123
131
  if self._loop.is_running():
124
132
  self._loop.close()
125
-
133
+
126
134
  def add_task(self, task: Task) -> None:
127
135
  task = to_coroutine_task(task)
128
136
 
@@ -130,7 +138,7 @@ class LoopWrapper(ABCLoopWrapper):
130
138
  self._loop.create_task(task)
131
139
  else:
132
140
  self.tasks.append(task)
133
-
141
+
134
142
  def complete_tasks(self, tasks: set[asyncio.Task[typing.Any]]) -> None:
135
143
  tasks = tasks | asyncio.all_tasks(self._loop)
136
144
  task_to_cancel = asyncio.gather(*tasks, return_exceptions=True)
@@ -28,7 +28,7 @@ def to_str(s: str | enum.Enum) -> str:
28
28
 
29
29
 
30
30
  def magic_bundle(
31
- handler: FuncType,
31
+ handler: FuncType,
32
32
  kw: dict[str | enum.Enum, typing.Any],
33
33
  *,
34
34
  start_idx: int = 1,
@@ -1,2 +1,208 @@
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
+ "BotDescription",
27
+ "BotName",
28
+ "BotShortDescription",
29
+ "BusinessConnection",
30
+ "BusinessIntro",
31
+ "BusinessLocation",
32
+ "BusinessMessagesDeleted",
33
+ "BusinessOpeningHours",
34
+ "BusinessOpeningHoursInterval",
35
+ "CallbackGame",
36
+ "CallbackQuery",
37
+ "Chat",
38
+ "ChatAdministratorRights",
39
+ "ChatBackground",
40
+ "ChatBoost",
41
+ "ChatBoostAdded",
42
+ "ChatBoostRemoved",
43
+ "ChatBoostSource",
44
+ "ChatBoostSourceGiftCode",
45
+ "ChatBoostSourceGiveaway",
46
+ "ChatBoostSourcePremium",
47
+ "ChatBoostUpdated",
48
+ "ChatFullInfo",
49
+ "ChatInviteLink",
50
+ "ChatJoinRequest",
51
+ "ChatLocation",
52
+ "ChatMember",
53
+ "ChatMemberAdministrator",
54
+ "ChatMemberBanned",
55
+ "ChatMemberLeft",
56
+ "ChatMemberMember",
57
+ "ChatMemberOwner",
58
+ "ChatMemberRestricted",
59
+ "ChatMemberUpdated",
60
+ "ChatPermissions",
61
+ "ChatPhoto",
62
+ "ChatShared",
63
+ "ChosenInlineResult",
64
+ "Contact",
65
+ "Dice",
66
+ "Document",
67
+ "EncryptedCredentials",
68
+ "EncryptedPassportElement",
69
+ "ExternalReplyInfo",
70
+ "File",
71
+ "ForceReply",
72
+ "ForumTopic",
73
+ "ForumTopicClosed",
74
+ "ForumTopicCreated",
75
+ "ForumTopicEdited",
76
+ "ForumTopicReopened",
77
+ "Game",
78
+ "GameHighScore",
79
+ "GeneralForumTopicHidden",
80
+ "GeneralForumTopicUnhidden",
81
+ "Giveaway",
82
+ "GiveawayCompleted",
83
+ "GiveawayCreated",
84
+ "GiveawayWinners",
85
+ "InaccessibleMessage",
86
+ "InlineKeyboardButton",
87
+ "InlineKeyboardMarkup",
88
+ "InlineQuery",
89
+ "InlineQueryResult",
90
+ "InlineQueryResultArticle",
91
+ "InlineQueryResultAudio",
92
+ "InlineQueryResultCachedAudio",
93
+ "InlineQueryResultCachedDocument",
94
+ "InlineQueryResultCachedGif",
95
+ "InlineQueryResultCachedMpeg4Gif",
96
+ "InlineQueryResultCachedPhoto",
97
+ "InlineQueryResultCachedSticker",
98
+ "InlineQueryResultCachedVideo",
99
+ "InlineQueryResultCachedVoice",
100
+ "InlineQueryResultContact",
101
+ "InlineQueryResultDocument",
102
+ "InlineQueryResultGame",
103
+ "InlineQueryResultGif",
104
+ "InlineQueryResultLocation",
105
+ "InlineQueryResultMpeg4Gif",
106
+ "InlineQueryResultPhoto",
107
+ "InlineQueryResultVenue",
108
+ "InlineQueryResultVideo",
109
+ "InlineQueryResultVoice",
110
+ "InlineQueryResultsButton",
111
+ "InputContactMessageContent",
112
+ "InputFile",
113
+ "InputInvoiceMessageContent",
114
+ "InputLocationMessageContent",
115
+ "InputMedia",
116
+ "InputMediaAnimation",
117
+ "InputMediaAudio",
118
+ "InputMediaDocument",
119
+ "InputMediaPhoto",
120
+ "InputMediaVideo",
121
+ "InputMessageContent",
122
+ "InputPollOption",
123
+ "InputSticker",
124
+ "InputTextMessageContent",
125
+ "InputVenueMessageContent",
126
+ "Invoice",
127
+ "KeyboardButton",
128
+ "KeyboardButtonPollType",
129
+ "KeyboardButtonRequestChat",
130
+ "KeyboardButtonRequestUsers",
131
+ "LabeledPrice",
132
+ "LinkPreviewOptions",
133
+ "Location",
134
+ "LoginUrl",
135
+ "MaskPosition",
136
+ "MaybeInaccessibleMessage",
137
+ "MenuButton",
138
+ "MenuButtonCommands",
139
+ "MenuButtonDefault",
140
+ "MenuButtonWebApp",
141
+ "Message",
142
+ "MessageAutoDeleteTimerChanged",
143
+ "MessageEntity",
144
+ "MessageId",
145
+ "MessageOrigin",
146
+ "MessageOriginChannel",
147
+ "MessageOriginChat",
148
+ "MessageOriginHiddenUser",
149
+ "MessageOriginUser",
150
+ "MessageReactionCountUpdated",
151
+ "MessageReactionUpdated",
152
+ "Model",
153
+ "OrderInfo",
154
+ "PassportData",
155
+ "PassportElementError",
156
+ "PassportElementErrorDataField",
157
+ "PassportElementErrorFile",
158
+ "PassportElementErrorFiles",
159
+ "PassportElementErrorFrontSide",
160
+ "PassportElementErrorReverseSide",
161
+ "PassportElementErrorSelfie",
162
+ "PassportElementErrorTranslationFile",
163
+ "PassportElementErrorTranslationFiles",
164
+ "PassportElementErrorUnspecified",
165
+ "PassportFile",
166
+ "PhotoSize",
167
+ "Poll",
168
+ "PollAnswer",
169
+ "PollOption",
170
+ "PreCheckoutQuery",
171
+ "ProximityAlertTriggered",
172
+ "ReactionCount",
173
+ "ReactionType",
174
+ "ReactionTypeCustomEmoji",
175
+ "ReactionTypeEmoji",
176
+ "ReplyKeyboardMarkup",
177
+ "ReplyKeyboardRemove",
178
+ "ReplyParameters",
179
+ "ResponseParameters",
180
+ "SentWebAppMessage",
181
+ "SharedUser",
182
+ "ShippingAddress",
183
+ "ShippingOption",
184
+ "ShippingQuery",
185
+ "Sticker",
186
+ "StickerSet",
187
+ "Story",
188
+ "SuccessfulPayment",
189
+ "SwitchInlineQueryChosenChat",
190
+ "TextQuote",
191
+ "Update",
192
+ "User",
193
+ "UserChatBoosts",
194
+ "UserProfilePhotos",
195
+ "UsersShared",
196
+ "Venue",
197
+ "Video",
198
+ "VideoChatEnded",
199
+ "VideoChatParticipantsInvited",
200
+ "VideoChatScheduled",
201
+ "VideoChatStarted",
202
+ "VideoNote",
203
+ "Voice",
204
+ "WebAppData",
205
+ "WebAppInfo",
206
+ "WebhookInfo",
207
+ "WriteAccessAllowed",
208
+ )
@@ -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
+ )