botapi-py 1.3.0__tar.gz → 1.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: botapi-py
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Summary: A simple and flexible Python library to conveniently build Telegram bots using the Bot API.
5
5
  Requires-Dist: httpx>=0.28.1
6
6
  Requires-Dist: pydantic>=2.12.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "botapi-py"
3
- version = "1.3.0"
3
+ version = "1.3.2"
4
4
  description = "A simple and flexible Python library to conveniently build Telegram bots using the Bot API."
5
5
  # readme = "README.md"
6
6
  # authors = [
@@ -1,5 +1,8 @@
1
1
  from .get_updates_handler import GetUpdatesAsyncDispatcher
2
- from .redis_pubsub_handler import RedisPubSubAsyncDispatcher
2
+ try:
3
+ from .redis_pubsub_handler import RedisPubSubAsyncDispatcher
4
+ except ImportError:
5
+ pass
3
6
 
4
7
  __all__ = [
5
8
  'GetUpdatesAsyncDispatcher',
@@ -7,17 +7,16 @@ from typing import Any, Callable, Coroutine, TypeAlias
7
7
  import pydantic
8
8
  from botapi.types import Update
9
9
 
10
- logger = logging.getLogger(__name__)
11
-
12
10
  try:
13
11
  import redis.asyncio as redis
14
12
  from redis.asyncio.client import PubSub
13
+ _has_redis = True
15
14
  except ImportError as e:
16
- logger.error(
17
- 'The Redis python library is not installed. Please install it to use this feature.'
18
- )
15
+ _has_redis = False
19
16
  raise e
20
17
 
18
+ logger = logging.getLogger(__name__)
19
+
21
20
  UpdateHandler: TypeAlias = Callable[[Update], Coroutine[Any, Any, None]]
22
21
 
23
22
 
@@ -54,6 +53,9 @@ class RedisPubSubAsyncDispatcher:
54
53
  shutdown_wait_timeout (float, optional):
55
54
  Timeout in seconds to wait for pending tasks to complete on shutdown.
56
55
  '''
56
+ if not _has_redis:
57
+ raise ImportError('redis-py is not installed. Install `botapi-py[redis]` to use this dispatcher.')
58
+
57
59
  self.redis_client = redis_client
58
60
  self.update_handler = update_handler
59
61
  self.pubsub_channel = pubsub_channel
@@ -1,7 +1,5 @@
1
1
  import enum
2
2
 
3
- from . import boilerplate
4
-
5
3
  class ChatType(enum.StrEnum):
6
4
  PRIVATE = 'private'
7
5
  GROUP = 'group'
@@ -102,7 +100,7 @@ class ServiceMessage(enum.StrEnum):
102
100
  WEB_APP_DATA = 'web_app_data'
103
101
  SUGGESTED_POST = 'suggested_post_info'
104
102
 
105
- @boilerplate.extend_enum(MediaType, ServiceMessage)
103
+ # @boilerplate.extend_enum(MediaType, ServiceMessage)
106
104
  class MessageType(enum.StrEnum):
107
105
  '''
108
106
  The content of this message.
@@ -118,6 +116,69 @@ class MessageType(enum.StrEnum):
118
116
  LOCATION = 'location'
119
117
  CONTACT = 'contact'
120
118
 
119
+ # MediaType - Python sucks.
120
+ ANIMATION = 'animation'
121
+ AUDIO = 'audio'
122
+ DOCUMENT = 'document'
123
+ PHOTO = 'photo'
124
+ STICKER = 'sticker'
125
+ VIDEO = 'video'
126
+ VIDEO_NOTE = 'video_note'
127
+ VOICE = 'voice'
128
+ STORY = 'story'
129
+ PAID_MEDIA = 'paid_media'
130
+
131
+ # ServiceMessage - Python sucks.
132
+ NEW_CHAT_MEMBERS = 'new_chat_members'
133
+ LEFT_CHAT_MEMBER = 'left_chat_member'
134
+ NEW_CHAT_TITLE = 'new_chat_title'
135
+ NEW_CHAT_PHOTO = 'new_chat_photo'
136
+ DELETE_CHAT_PHOTO = 'delete_chat_photo'
137
+ GROUP_CHAT_CREATED = 'group_chat_created'
138
+ SUPERGROUP_CHAT_CREATED = 'supergroup_chat_created'
139
+ CHANNEL_CHAT_CREATED = 'channel_chat_created'
140
+ MESSAGE_AUTO_DELETE_TIMER_CHANGED = 'message_auto_delete_timer_changed'
141
+ MIGRATE_TO_CHAT_ID = 'migrate_to_chat_id'
142
+ MIGRATE_FROM_CHAT_ID = 'migrate_from_chat_id'
143
+ PINNED_MESSAGE = 'pinned_message'
144
+ SUCCESSFUL_PAYMENT = 'successful_payment'
145
+ REFUNDED_PAYMENT = 'refunded_payment'
146
+ USERS_SHARED = 'users_shared'
147
+ CHAT_SHARED = 'chat_shared'
148
+ GIFT = 'gift'
149
+ UNIQUE_GIFT = 'unique_gift'
150
+ CONNECTED_WEBSITE = 'connected_website'
151
+ WRITE_ACCESS_ALLOWED = 'write_access_allowed'
152
+ PASSPORT_DATA = 'passport_data'
153
+ PROXIMITY_ALERT_TRIGGERED = 'proximity_alert_triggered'
154
+ BOOST_ADDED = 'boost_added'
155
+ CHAT_BACKGROUND_SET = 'chat_background_set'
156
+ CHECKLIST_TASKS_DONE = 'checklist_tasks_done'
157
+ CHECKLIST_TASKS_ADDED = 'checklist_tasks_added'
158
+ DIRECT_MESSAGE_PRICE_CHANGED = 'direct_message_price_changed'
159
+ FORUM_TOPIC_CREATED = 'forum_topic_created'
160
+ FORUM_TOPIC_EDITED = 'forum_topic_edited'
161
+ FORUM_TOPIC_CLOSED = 'forum_topic_closed'
162
+ FORUM_TOPIC_REOPENED = 'forum_topic_reopened'
163
+ GENERAL_FORUM_TOPIC_HIDDEN = 'general_forum_topic_hidden'
164
+ GENERAL_FORUM_TOPIC_UNHIDDEN = 'general_forum_topic_unhidden'
165
+ GIVEAWAY = 'giveaway'
166
+ GIVEAWAY_CREATED = 'giveaway_created'
167
+ GIVEAWAY_WINNERS = 'giveaway_winners'
168
+ GIVEAWAY_COMPLETED = 'giveaway_completed'
169
+ PAID_MESSAGE_PRICE_CHANGED = 'paid_message_price_changed'
170
+ SUGGESTED_POST_APPROVED = 'suggested_post_approved'
171
+ SUGGESTED_POST_APPROVAL_FAILED = 'suggested_post_approval_failed'
172
+ SUGGESTED_POST_DECLINED = 'suggested_post_declined'
173
+ SUGGESTED_POST_PAID = 'suggested_post_paid'
174
+ SUGGESTED_POST_REFUNDED = 'suggested_post_refunded'
175
+ VIDEO_CHAT_SCHEDULED = 'video_chat_scheduled'
176
+ VIDEO_CHAT_STARTED = 'video_chat_started'
177
+ VIDEO_CHAT_ENDED = 'video_chat_ended'
178
+ VIDEO_CHAT_PARTICIPANTS_INVITED = 'video_chat_participants_invited'
179
+ WEB_APP_DATA = 'web_app_data'
180
+ SUGGESTED_POST = 'suggested_post_info'
181
+
121
182
  class ChatMemberStatus(enum.StrEnum):
122
183
  '''
123
184
  Statuses of a chat member.
@@ -1,20 +0,0 @@
1
- import enum
2
-
3
- from typing import TypeVar, Callable
4
-
5
- # Enums
6
- E = TypeVar('E', bound=enum.Enum)
7
-
8
- def extend_enum(*sources: type[E]) -> Callable[..., type[E]]:
9
- '''
10
- Decorator that extends an Enum class with members
11
- from one or more source Enum classes.
12
- '''
13
- def decorator(target: type[E]) -> type[E]:
14
- for source in sources:
15
- for member in source:
16
- if member.name not in target.__members__:
17
- target._member_map_[member.name] = member
18
- return target
19
- return decorator
20
-
File without changes
File without changes
File without changes
File without changes