PySPlusthon 0.5.3__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.
- PySPlusthon/__init__.py +3 -0
- PySPlusthon/client/__init__.py +1 -0
- PySPlusthon/client/attachments/__init__.py +29 -0
- PySPlusthon/client/attachments/get_file.py +22 -0
- PySPlusthon/client/attachments/send_animation.py +71 -0
- PySPlusthon/client/attachments/send_audio.py +54 -0
- PySPlusthon/client/attachments/send_contact.py +47 -0
- PySPlusthon/client/attachments/send_document.py +63 -0
- PySPlusthon/client/attachments/send_location.py +45 -0
- PySPlusthon/client/attachments/send_media_group.py +88 -0
- PySPlusthon/client/attachments/send_photo.py +67 -0
- PySPlusthon/client/attachments/send_sticker.py +51 -0
- PySPlusthon/client/attachments/send_video.py +56 -0
- PySPlusthon/client/attachments/send_voice.py +52 -0
- PySPlusthon/client/attachments/upload_file.py +82 -0
- PySPlusthon/client/chats/__init__.py +43 -0
- PySPlusthon/client/chats/ban_chat_member.py +24 -0
- PySPlusthon/client/chats/delete_chat_photo.py +32 -0
- PySPlusthon/client/chats/get_chat.py +69 -0
- PySPlusthon/client/chats/get_chat_administrators.py +18 -0
- PySPlusthon/client/chats/get_chat_history.py +39 -0
- PySPlusthon/client/chats/get_chat_member.py +16 -0
- PySPlusthon/client/chats/get_chat_members.py +29 -0
- PySPlusthon/client/chats/get_chat_members_count.py +21 -0
- PySPlusthon/client/chats/join_chat.py +31 -0
- PySPlusthon/client/chats/leave_chat.py +22 -0
- PySPlusthon/client/chats/pin_chat_message.py +31 -0
- PySPlusthon/client/chats/promote_chat_member.py +64 -0
- PySPlusthon/client/chats/restrict_chat_member.py +25 -0
- PySPlusthon/client/chats/set_chat_description.py +23 -0
- PySPlusthon/client/chats/set_chat_photo.py +33 -0
- PySPlusthon/client/chats/set_chat_title.py +23 -0
- PySPlusthon/client/chats/unban_chat_member.py +24 -0
- PySPlusthon/client/chats/unpin_all_chat_messages.py +38 -0
- PySPlusthon/client/chats/unpin_chat_message.py +33 -0
- PySPlusthon/client/client.py +223 -0
- PySPlusthon/client/invite_links/__init__.py +7 -0
- PySPlusthon/client/invite_links/create_chat_invite_link.py +14 -0
- PySPlusthon/client/invite_links/export_chat_invite_link.py +21 -0
- PySPlusthon/client/invite_links/revoke_chat_invite_link.py +23 -0
- PySPlusthon/client/messages/__init__.py +21 -0
- PySPlusthon/client/messages/answer_callback_query.py +12 -0
- PySPlusthon/client/messages/copy_message.py +43 -0
- PySPlusthon/client/messages/delete_message.py +29 -0
- PySPlusthon/client/messages/edit_message_caption.py +40 -0
- PySPlusthon/client/messages/edit_message_reply_markup.py +17 -0
- PySPlusthon/client/messages/edit_message_text.py +40 -0
- PySPlusthon/client/messages/forward_message.py +35 -0
- PySPlusthon/client/messages/send_message.py +39 -0
- PySPlusthon/client/stickers/__init__.py +9 -0
- PySPlusthon/client/stickers/add_sticker_to_set.py +15 -0
- PySPlusthon/client/stickers/create_new_sticker_set.py +16 -0
- PySPlusthon/client/stickers/delete_sticker_from_set.py +10 -0
- PySPlusthon/client/stickers/get_sticker_set.py +11 -0
- PySPlusthon/client/stickers/upload_sticker_file.py +16 -0
- PySPlusthon/client/updates/__init__.py +8 -0
- PySPlusthon/client/updates/delete_webhook.py +9 -0
- PySPlusthon/client/updates/get_updates.py +14 -0
- PySPlusthon/client/updates/get_webhook_info.py +10 -0
- PySPlusthon/client/updates/set_webhook.py +10 -0
- PySPlusthon/client/users/__init__.py +6 -0
- PySPlusthon/client/users/ask_review.py +14 -0
- PySPlusthon/client/users/get_me.py +16 -0
- PySPlusthon/conditions/__init__.py +43 -0
- PySPlusthon/conditions/all.py +6 -0
- PySPlusthon/conditions/animation.py +7 -0
- PySPlusthon/conditions/at_state.py +18 -0
- PySPlusthon/conditions/audio.py +7 -0
- PySPlusthon/conditions/author.py +13 -0
- PySPlusthon/conditions/caption.py +7 -0
- PySPlusthon/conditions/channel.py +11 -0
- PySPlusthon/conditions/channel_chat_created.py +7 -0
- PySPlusthon/conditions/chat.py +14 -0
- PySPlusthon/conditions/click.py +24 -0
- PySPlusthon/conditions/command.py +23 -0
- PySPlusthon/conditions/condition.py +88 -0
- PySPlusthon/conditions/contact.py +7 -0
- PySPlusthon/conditions/content.py +7 -0
- PySPlusthon/conditions/delete_chat_photo.py +7 -0
- PySPlusthon/conditions/document.py +7 -0
- PySPlusthon/conditions/entities.py +7 -0
- PySPlusthon/conditions/equals.py +14 -0
- PySPlusthon/conditions/forward.py +7 -0
- PySPlusthon/conditions/group.py +11 -0
- PySPlusthon/conditions/group_chat_created.py +7 -0
- PySPlusthon/conditions/is_admin.py +17 -0
- PySPlusthon/conditions/is_instance.py +10 -0
- PySPlusthon/conditions/is_joined.py +61 -0
- PySPlusthon/conditions/left_chat_member.py +7 -0
- PySPlusthon/conditions/location.py +7 -0
- PySPlusthon/conditions/media.py +7 -0
- PySPlusthon/conditions/media_group.py +7 -0
- PySPlusthon/conditions/new_chat_members.py +7 -0
- PySPlusthon/conditions/new_chat_photo.py +7 -0
- PySPlusthon/conditions/new_chat_title.py +7 -0
- PySPlusthon/conditions/number.py +12 -0
- PySPlusthon/conditions/photo.py +7 -0
- PySPlusthon/conditions/pinned_message.py +7 -0
- PySPlusthon/conditions/poll.py +7 -0
- PySPlusthon/conditions/private.py +11 -0
- PySPlusthon/conditions/regex.py +17 -0
- PySPlusthon/conditions/reply.py +7 -0
- PySPlusthon/conditions/sticker.py +7 -0
- PySPlusthon/conditions/supergroup_chat_created.py +7 -0
- PySPlusthon/conditions/text.py +7 -0
- PySPlusthon/conditions/video.py +7 -0
- PySPlusthon/conditions/voice.py +7 -0
- PySPlusthon/dispatcher/__init__.py +5 -0
- PySPlusthon/dispatcher/chain.py +165 -0
- PySPlusthon/dispatcher/dispatcher.py +124 -0
- PySPlusthon/dispatcher/logging_chain.py +36 -0
- PySPlusthon/dispatcher/monitoring_chain.py +19 -0
- PySPlusthon/dispatcher/printing_chain.py +21 -0
- PySPlusthon/enums/__init__.py +7 -0
- PySPlusthon/enums/chat_member_status.py +9 -0
- PySPlusthon/enums/chat_type.py +9 -0
- PySPlusthon/enums/message_media_type.py +16 -0
- PySPlusthon/enums/name_enum.py +13 -0
- PySPlusthon/enums/peer_type.py +8 -0
- PySPlusthon/enums/poll_type.py +8 -0
- PySPlusthon/enums/transaction_status.py +10 -0
- PySPlusthon/errors/__init__.py +11 -0
- PySPlusthon/errors/dispatching_errors/__init__.py +2 -0
- PySPlusthon/errors/dispatching_errors/break_dispatching.py +2 -0
- PySPlusthon/errors/dispatching_errors/continue_dispatching.py +2 -0
- PySPlusthon/errors/rpc_errors/__init__.py +8 -0
- PySPlusthon/errors/rpc_errors/bad_request_error.py +6 -0
- PySPlusthon/errors/rpc_errors/flood_error.py +6 -0
- PySPlusthon/errors/rpc_errors/forbidden_error.py +6 -0
- PySPlusthon/errors/rpc_errors/internal_error.py +6 -0
- PySPlusthon/errors/rpc_errors/not_found_error.py +6 -0
- PySPlusthon/errors/rpc_errors/rpc_error.py +23 -0
- PySPlusthon/errors/rpc_errors/too_many_requests.py +10 -0
- PySPlusthon/errors/rpc_errors/unauthorized_error.py +6 -0
- PySPlusthon/event_handlers/__init__.py +12 -0
- PySPlusthon/event_handlers/callback_query_handler.py +16 -0
- PySPlusthon/event_handlers/command_handler.py +46 -0
- PySPlusthon/event_handlers/connect_handler.py +19 -0
- PySPlusthon/event_handlers/disconnect_handler.py +18 -0
- PySPlusthon/event_handlers/edited_message_handler.py +16 -0
- PySPlusthon/event_handlers/error_handler.py +15 -0
- PySPlusthon/event_handlers/event_handler.py +53 -0
- PySPlusthon/event_handlers/initialize_handler.py +18 -0
- PySPlusthon/event_handlers/message_handler.py +16 -0
- PySPlusthon/event_handlers/shipping_query_handler.py +16 -0
- PySPlusthon/event_handlers/shutdown_handler.py +18 -0
- PySPlusthon/event_handlers/update_handler.py +16 -0
- PySPlusthon/network/__init__.py +1 -0
- PySPlusthon/network/httpconnection.py +74 -0
- PySPlusthon/objects/__init__.py +43 -0
- PySPlusthon/objects/animation.py +44 -0
- PySPlusthon/objects/audio.py +36 -0
- PySPlusthon/objects/callback_query.py +37 -0
- PySPlusthon/objects/chat.py +118 -0
- PySPlusthon/objects/chat_member.py +53 -0
- PySPlusthon/objects/chat_permissions.py +26 -0
- PySPlusthon/objects/chat_photo.py +24 -0
- PySPlusthon/objects/contact.py +18 -0
- PySPlusthon/objects/date.py +35 -0
- PySPlusthon/objects/document.py +36 -0
- PySPlusthon/objects/edited_message.py +27 -0
- PySPlusthon/objects/entity.py +21 -0
- PySPlusthon/objects/file.py +21 -0
- PySPlusthon/objects/forward_origin.py +22 -0
- PySPlusthon/objects/inline_keyboard.py +65 -0
- PySPlusthon/objects/inline_keyboard_button.py +30 -0
- PySPlusthon/objects/input_media.py +44 -0
- PySPlusthon/objects/input_media_photo.py +14 -0
- PySPlusthon/objects/input_media_video.py +14 -0
- PySPlusthon/objects/invite_link.py +32 -0
- PySPlusthon/objects/list.py +24 -0
- PySPlusthon/objects/location.py +14 -0
- PySPlusthon/objects/message.py +478 -0
- PySPlusthon/objects/message_id.py +31 -0
- PySPlusthon/objects/object.py +154 -0
- PySPlusthon/objects/order_info.py +19 -0
- PySPlusthon/objects/photo.py +31 -0
- PySPlusthon/objects/poll.py +34 -0
- PySPlusthon/objects/poll_option.py +16 -0
- PySPlusthon/objects/reply_keyboard.py +79 -0
- PySPlusthon/objects/reply_keyboard_button.py +27 -0
- PySPlusthon/objects/reply_keyboard_remove.py +10 -0
- PySPlusthon/objects/reply_markup.py +12 -0
- PySPlusthon/objects/shipping_address.py +22 -0
- PySPlusthon/objects/shipping_query.py +20 -0
- PySPlusthon/objects/sticker.py +54 -0
- PySPlusthon/objects/sticker_set.py +29 -0
- PySPlusthon/objects/transaction.py +25 -0
- PySPlusthon/objects/update.py +33 -0
- PySPlusthon/objects/user.py +60 -0
- PySPlusthon/objects/video.py +45 -0
- PySPlusthon/objects/voice.py +31 -0
- PySPlusthon/objects/webhook_info.py +16 -0
- PySPlusthon/proto/__init__.py +2 -0
- PySPlusthon/proto/enums_pb2.py +46 -0
- PySPlusthon/proto/enums_pb2.pyi +99 -0
- PySPlusthon/proto/enums_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/__init__.py +209 -0
- PySPlusthon/proto/requests/abacus_pb2.py +40 -0
- PySPlusthon/proto/requests/abacus_pb2.pyi +31 -0
- PySPlusthon/proto/requests/abacus_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/auth_pb2.py +49 -0
- PySPlusthon/proto/requests/auth_pb2.pyi +67 -0
- PySPlusthon/proto/requests/auth_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/configs_pb2.py +37 -0
- PySPlusthon/proto/requests/configs_pb2.pyi +15 -0
- PySPlusthon/proto/requests/configs_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/files_pb2.py +40 -0
- PySPlusthon/proto/requests/files_pb2.pyi +34 -0
- PySPlusthon/proto/requests/files_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/groups_pb2.py +82 -0
- PySPlusthon/proto/requests/groups_pb2.pyi +213 -0
- PySPlusthon/proto/requests/groups_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/messaging_pb2.py +56 -0
- PySPlusthon/proto/requests/messaging_pb2.pyi +119 -0
- PySPlusthon/proto/requests/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/presence_pb2.py +40 -0
- PySPlusthon/proto/requests/presence_pb2.pyi +24 -0
- PySPlusthon/proto/requests/presence_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/request_pb2.py +42 -0
- PySPlusthon/proto/requests/request_pb2.pyi +35 -0
- PySPlusthon/proto/requests/request_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/users_pb2.py +43 -0
- PySPlusthon/proto/requests/users_pb2.pyi +34 -0
- PySPlusthon/proto/requests/users_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/__init__.py +6 -0
- PySPlusthon/proto/responses/abacus_pb2.py +37 -0
- PySPlusthon/proto/responses/abacus_pb2.pyi +14 -0
- PySPlusthon/proto/responses/abacus_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/auth_pb2.py +42 -0
- PySPlusthon/proto/responses/auth_pb2.pyi +40 -0
- PySPlusthon/proto/responses/auth_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/files_pb2.py +39 -0
- PySPlusthon/proto/responses/files_pb2.pyi +27 -0
- PySPlusthon/proto/responses/files_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/groups_pb2.py +59 -0
- PySPlusthon/proto/responses/groups_pb2.pyi +90 -0
- PySPlusthon/proto/responses/groups_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/messaging_pb2.py +44 -0
- PySPlusthon/proto/responses/messaging_pb2.pyi +37 -0
- PySPlusthon/proto/responses/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/users_pb2.py +41 -0
- PySPlusthon/proto/responses/users_pb2.pyi +28 -0
- PySPlusthon/proto/responses/users_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/__init__.py +7 -0
- PySPlusthon/proto/structs/collections_pb2.py +54 -0
- PySPlusthon/proto/structs/collections_pb2.pyi +79 -0
- PySPlusthon/proto/structs/collections_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/files_pb2.py +52 -0
- PySPlusthon/proto/structs/files_pb2.pyi +93 -0
- PySPlusthon/proto/structs/files_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/groups_pb2.py +49 -0
- PySPlusthon/proto/structs/groups_pb2.pyi +144 -0
- PySPlusthon/proto/structs/groups_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/messaging_pb2.py +81 -0
- PySPlusthon/proto/structs/messaging_pb2.pyi +296 -0
- PySPlusthon/proto/structs/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/peers_pb2.py +47 -0
- PySPlusthon/proto/structs/peers_pb2.pyi +56 -0
- PySPlusthon/proto/structs/peers_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/set_updates_pb2.py +37 -0
- PySPlusthon/proto/structs/set_updates_pb2.pyi +15 -0
- PySPlusthon/proto/structs/set_updates_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/users_pb2.py +54 -0
- PySPlusthon/proto/structs/users_pb2.pyi +122 -0
- PySPlusthon/proto/structs/users_pb2_grpc.py +24 -0
- PySPlusthon/proto/updates/__init__.py +1 -0
- PySPlusthon/proto/updates/messaging_pb2.py +38 -0
- PySPlusthon/proto/updates/messaging_pb2.pyi +26 -0
- PySPlusthon/proto/updates/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/ws_pb2.py +52 -0
- PySPlusthon/proto/ws_pb2.pyi +76 -0
- PySPlusthon/proto/ws_pb2_grpc.py +24 -0
- PySPlusthon/smart_call.py +73 -0
- PySPlusthon/states/__init__.py +3 -0
- PySPlusthon/states/state.py +11 -0
- PySPlusthon/states/state_group.py +13 -0
- PySPlusthon/states/state_machine.py +83 -0
- PySPlusthon/sync_support.py +48 -0
- pysplusthon-0.5.3.dist-info/METADATA +65 -0
- pysplusthon-0.5.3.dist-info/RECORD +284 -0
- pysplusthon-0.5.3.dist-info/WHEEL +5 -0
- pysplusthon-0.5.3.dist-info/licenses/LICENSE +19 -0
- pysplusthon-0.5.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
from typing import BinaryIO, List, Union
|
|
2
|
+
|
|
3
|
+
from PySPlusthon import objects
|
|
4
|
+
from . import Object
|
|
5
|
+
from .audio import Audio
|
|
6
|
+
from .animation import Animation
|
|
7
|
+
from .chat import Chat
|
|
8
|
+
from .date import Date
|
|
9
|
+
from .document import Document
|
|
10
|
+
from .photo import Photo
|
|
11
|
+
from .sticker import Sticker
|
|
12
|
+
from .user import User
|
|
13
|
+
from .video import Video
|
|
14
|
+
from .voice import Voice
|
|
15
|
+
from .message_id import MessageId
|
|
16
|
+
from ..enums import MessageMediaType
|
|
17
|
+
from ..sync_support import add_sync_support_to_object
|
|
18
|
+
from ..proto import structs
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@add_sync_support_to_object
|
|
22
|
+
class Message(Object):
|
|
23
|
+
attribute_names = [
|
|
24
|
+
("id", "message_id"),
|
|
25
|
+
("author", "from")
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def wrap(cls, raw_object):
|
|
30
|
+
try:
|
|
31
|
+
if not raw_object.get("voice") and raw_object["document"]["mime_type"].startswith("audio"):
|
|
32
|
+
raw_object["audio"] = raw_object["document"]
|
|
33
|
+
except (TypeError, KeyError):
|
|
34
|
+
pass
|
|
35
|
+
try:
|
|
36
|
+
if not raw_object.get("video") and raw_object["document"]["mime_type"].startswith("video"):
|
|
37
|
+
raw_object["animation"] = raw_object["document"]
|
|
38
|
+
except (TypeError, KeyError):
|
|
39
|
+
pass
|
|
40
|
+
return super().wrap(raw_object)
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def from_protobuf(cls, protobuf_data):
|
|
44
|
+
is_forward_message = (
|
|
45
|
+
not isinstance(protobuf_data, structs.QuotedMessage) and
|
|
46
|
+
not protobuf_data.message.ListFields() and
|
|
47
|
+
protobuf_data.quoted_message.ListFields()
|
|
48
|
+
)
|
|
49
|
+
if isinstance(protobuf_data, structs.QuotedMessage):
|
|
50
|
+
id = str(MessageId(rid=protobuf_data.message_id.value, date=protobuf_data.message_date))
|
|
51
|
+
author = User.from_protobuf(protobuf_data.sender_user_id)
|
|
52
|
+
chat = Chat.from_protobuf(protobuf_data.quoted_peer)
|
|
53
|
+
date = Date.from_protobuf(protobuf_data.message_date)
|
|
54
|
+
message = protobuf_data.quoted_message_content
|
|
55
|
+
else:
|
|
56
|
+
id = str(MessageId(rid=protobuf_data.rid, date=protobuf_data.date))
|
|
57
|
+
author = User.from_protobuf(protobuf_data.sender_uid)
|
|
58
|
+
chat = Chat.from_protobuf(protobuf_data.peer)
|
|
59
|
+
date = Date.from_protobuf(protobuf_data.date)
|
|
60
|
+
message = protobuf_data.message if protobuf_data.message.ListFields() \
|
|
61
|
+
else protobuf_data.quoted_message.quoted_message_content
|
|
62
|
+
|
|
63
|
+
return cls(
|
|
64
|
+
id=id,
|
|
65
|
+
author=author,
|
|
66
|
+
chat=chat,
|
|
67
|
+
date=date,
|
|
68
|
+
forward_from=(
|
|
69
|
+
User.from_protobuf(protobuf_data.quoted_message.sender_user_id)
|
|
70
|
+
if is_forward_message else None
|
|
71
|
+
),
|
|
72
|
+
forward_from_chat=(
|
|
73
|
+
Chat(id=f"{protobuf_data.quoted_message.public_group_id.value}|2")
|
|
74
|
+
if is_forward_message
|
|
75
|
+
and protobuf_data.quoted_message.HasField("public_group_id")
|
|
76
|
+
else None
|
|
77
|
+
),
|
|
78
|
+
forward_from_message_id=(
|
|
79
|
+
str(MessageId(
|
|
80
|
+
rid=protobuf_data.quoted_message.message_id.value,
|
|
81
|
+
date=protobuf_data.quoted_message.message_date
|
|
82
|
+
))
|
|
83
|
+
if is_forward_message else None
|
|
84
|
+
),
|
|
85
|
+
forward_date=(
|
|
86
|
+
Date.from_protobuf(protobuf_data.quoted_message.message_date)
|
|
87
|
+
if is_forward_message else None
|
|
88
|
+
),
|
|
89
|
+
reply_to_message=(
|
|
90
|
+
cls.from_protobuf(protobuf_data.quoted_message)
|
|
91
|
+
if not isinstance(protobuf_data, structs.QuotedMessage)
|
|
92
|
+
and protobuf_data.message.ListFields()
|
|
93
|
+
and protobuf_data.quoted_message.ListFields()
|
|
94
|
+
else None
|
|
95
|
+
),
|
|
96
|
+
text=(
|
|
97
|
+
message.text_message.text
|
|
98
|
+
if message.HasField("text_message") else None
|
|
99
|
+
),
|
|
100
|
+
document=(
|
|
101
|
+
Document.from_protobuf(message.document_message)
|
|
102
|
+
if message.HasField("document_message") else None
|
|
103
|
+
),
|
|
104
|
+
photo=(
|
|
105
|
+
Photo.from_protobuf(message.document_message)
|
|
106
|
+
if message.HasField("document_message")
|
|
107
|
+
and message.document_message.ext.HasField("document_ex_photo")
|
|
108
|
+
else None
|
|
109
|
+
),
|
|
110
|
+
video=(
|
|
111
|
+
Video.from_protobuf(message.document_message)
|
|
112
|
+
if message.HasField("document_message")
|
|
113
|
+
and message.document_message.ext.HasField("document_ex_video")
|
|
114
|
+
else None
|
|
115
|
+
),
|
|
116
|
+
animation=(
|
|
117
|
+
Animation.from_protobuf(message.document_message)
|
|
118
|
+
if message.HasField("document_message")
|
|
119
|
+
and message.document_message.ext.HasField("document_ex_gif")
|
|
120
|
+
else None
|
|
121
|
+
),
|
|
122
|
+
voice=(
|
|
123
|
+
Voice.from_protobuf(message.document_message)
|
|
124
|
+
if message.HasField("document_message")
|
|
125
|
+
and message.document_message.ext.HasField("document_ex_voice")
|
|
126
|
+
else None
|
|
127
|
+
),
|
|
128
|
+
audio=(
|
|
129
|
+
Audio.from_protobuf(message.document_message)
|
|
130
|
+
if message.HasField("document_message")
|
|
131
|
+
and message.document_message.ext.HasField("document_ex_audio")
|
|
132
|
+
else None
|
|
133
|
+
),
|
|
134
|
+
sticker=(
|
|
135
|
+
Sticker.from_protobuf(message.sticker_message)
|
|
136
|
+
if message.HasField("sticker_message")
|
|
137
|
+
else None
|
|
138
|
+
),
|
|
139
|
+
caption=(
|
|
140
|
+
message.document_message.caption.text
|
|
141
|
+
if message.HasField("document_message")
|
|
142
|
+
and message.document_message.HasField("caption")
|
|
143
|
+
else None
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def __init__(
|
|
148
|
+
self,
|
|
149
|
+
id: int = None,
|
|
150
|
+
author: "objects.User" = None,
|
|
151
|
+
date: "objects.Date" = None,
|
|
152
|
+
chat: "objects.Chat" = None,
|
|
153
|
+
sender_chat: "objects.Chat" = None,
|
|
154
|
+
forward_origin: "objects.ForwardOrigin" = None,
|
|
155
|
+
forward_from: "objects.User" = None,
|
|
156
|
+
forward_from_chat: "objects.Chat" = None,
|
|
157
|
+
forward_from_message_id: int = None,
|
|
158
|
+
forward_date: "objects.Date" = None,
|
|
159
|
+
reply_to_message: "objects.Message" = None,
|
|
160
|
+
edit_date: "objects.Date" = None,
|
|
161
|
+
text: str = None,
|
|
162
|
+
animation: "objects.Animation" = None,
|
|
163
|
+
entities: List["objects.Entity"] = None,
|
|
164
|
+
caption_entities: List["objects.Entity"] = None,
|
|
165
|
+
voice: "objects.Voice" = None,
|
|
166
|
+
audio: "objects.Audio" = None,
|
|
167
|
+
document: "objects.Document" = None,
|
|
168
|
+
photo: List["objects.Photo"] = None,
|
|
169
|
+
video: "objects.Video" = None,
|
|
170
|
+
sticker: "objects.Sticker" = None,
|
|
171
|
+
caption: str = None,
|
|
172
|
+
contact: "objects.Contact" = None,
|
|
173
|
+
location: "objects.Location" = None,
|
|
174
|
+
new_chat_members: List["objects.User"] = None,
|
|
175
|
+
left_chat_member: "objects.User" = None,
|
|
176
|
+
new_chat_title: str = None,
|
|
177
|
+
new_chat_photo: List["objects.Photo"] = None,
|
|
178
|
+
delete_chat_photo: bool = None,
|
|
179
|
+
group_chat_created: bool = None,
|
|
180
|
+
supergroup_chat_created: bool = None,
|
|
181
|
+
channel_chat_created: bool = None,
|
|
182
|
+
pinned_message: None = None,
|
|
183
|
+
media_group_id: int = None,
|
|
184
|
+
poll: "objects.Poll" = None,
|
|
185
|
+
reply_markup: "objects.ReplyMarkup" = None,
|
|
186
|
+
**kwargs
|
|
187
|
+
):
|
|
188
|
+
super().__init__(**kwargs)
|
|
189
|
+
self.id: int = id
|
|
190
|
+
self.author: "objects.User" = author
|
|
191
|
+
self.date: "objects.Date" = date
|
|
192
|
+
self.chat: "objects.Chat" = chat
|
|
193
|
+
self.sender_chat: "objects.Chat" = sender_chat
|
|
194
|
+
self.forward_origin: "objects.ForwardOrigin" = forward_origin
|
|
195
|
+
self.forward_from: "objects.User" = forward_from
|
|
196
|
+
self.forward_from_chat: "objects.Chat" = forward_from_chat
|
|
197
|
+
self.forward_from_message_id: int = forward_from_message_id
|
|
198
|
+
self.forward_date: "objects.Date" = forward_date
|
|
199
|
+
self.reply_to_message: "objects.Message" = reply_to_message
|
|
200
|
+
self.edit_date: "objects.Date" = edit_date
|
|
201
|
+
self.text: str = text
|
|
202
|
+
self.animation: "objects.Animation" = animation
|
|
203
|
+
self.entities: List["objects.Entity"] = entities
|
|
204
|
+
self.caption_entities: List["objects.Entity"] = caption_entities
|
|
205
|
+
self.voice: "objects.Voice" = voice
|
|
206
|
+
self.audio: "objects.Audio" = audio
|
|
207
|
+
self.document: "objects.Document" = document
|
|
208
|
+
self.photo: List["objects.Photo"] = photo
|
|
209
|
+
self.video: "objects.Video" = video
|
|
210
|
+
self.sticker: "objects.Sticker" = sticker
|
|
211
|
+
self.caption: str = caption
|
|
212
|
+
self.contact: "objects.Contact" = contact
|
|
213
|
+
self.location: "objects.Location" = location
|
|
214
|
+
self.new_chat_members: List["objects.User"] = new_chat_members
|
|
215
|
+
self.left_chat_member: "objects.User" = left_chat_member
|
|
216
|
+
self.new_chat_title: str = new_chat_title
|
|
217
|
+
self.new_chat_photo: List["objects.Photo"] = new_chat_photo
|
|
218
|
+
self.delete_chat_photo: bool = delete_chat_photo
|
|
219
|
+
self.group_chat_created: bool = group_chat_created
|
|
220
|
+
self.supergroup_chat_created: bool = supergroup_chat_created
|
|
221
|
+
self.channel_chat_created: bool = channel_chat_created
|
|
222
|
+
self.pinned_message: None = pinned_message
|
|
223
|
+
self.media_group_id: int = media_group_id
|
|
224
|
+
self.poll: "objects.Poll" = poll
|
|
225
|
+
self.reply_markup: "objects.ReplyMarkup" = reply_markup
|
|
226
|
+
|
|
227
|
+
@property
|
|
228
|
+
def media_type(self):
|
|
229
|
+
for media_type in MessageMediaType:
|
|
230
|
+
if getattr(self, media_type.value):
|
|
231
|
+
return media_type
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def content(self) -> str:
|
|
235
|
+
return self.text or self.caption or ""
|
|
236
|
+
|
|
237
|
+
@content.setter
|
|
238
|
+
def content(self, value):
|
|
239
|
+
if self.caption or self.document or self.contact or self.location or self.photo:
|
|
240
|
+
self.caption = value
|
|
241
|
+
else:
|
|
242
|
+
self.text = value
|
|
243
|
+
|
|
244
|
+
async def reply_animation(
|
|
245
|
+
self,
|
|
246
|
+
animation: Union[str, bytes, BinaryIO, "objects.InputMedia"],
|
|
247
|
+
duration: int = None,
|
|
248
|
+
width: int = None,
|
|
249
|
+
height: int = None,
|
|
250
|
+
caption: str = None,
|
|
251
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
252
|
+
):
|
|
253
|
+
return await self.client.send_animation(
|
|
254
|
+
self.chat.id,
|
|
255
|
+
animation,
|
|
256
|
+
duration,
|
|
257
|
+
width,
|
|
258
|
+
height,
|
|
259
|
+
caption,
|
|
260
|
+
reply_markup,
|
|
261
|
+
self.id
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
async def reply_audio(
|
|
265
|
+
self,
|
|
266
|
+
audio: Union[str, bytes, BinaryIO, "objects.InputMedia"],
|
|
267
|
+
caption: str = None,
|
|
268
|
+
duration: int = None,
|
|
269
|
+
title: str = None,
|
|
270
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
271
|
+
):
|
|
272
|
+
return await self.client.send_audio(self.chat.id, audio, caption, duration, title, reply_markup, self.id)
|
|
273
|
+
|
|
274
|
+
async def reply_contact(
|
|
275
|
+
self,
|
|
276
|
+
phone_number: str,
|
|
277
|
+
first_name: str,
|
|
278
|
+
last_name: str = None,
|
|
279
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
280
|
+
):
|
|
281
|
+
return await self.client.send_contact(self.chat.id, phone_number, first_name, last_name, reply_markup, self.id)
|
|
282
|
+
|
|
283
|
+
async def reply_document(
|
|
284
|
+
self,
|
|
285
|
+
document: Union[str, bytes, BinaryIO, "objects.InputMedia"],
|
|
286
|
+
caption: str = None,
|
|
287
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
288
|
+
):
|
|
289
|
+
return await self.client.send_document(self.chat.id, document, caption, reply_markup, self.id)
|
|
290
|
+
|
|
291
|
+
async def reply_location(
|
|
292
|
+
self,
|
|
293
|
+
latitude: int,
|
|
294
|
+
longitude: int,
|
|
295
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
296
|
+
):
|
|
297
|
+
return await self.client.send_location(self.chat.id, longitude, latitude, reply_markup, self.id)
|
|
298
|
+
|
|
299
|
+
async def reply_media_group(
|
|
300
|
+
self,
|
|
301
|
+
media: List["objects.InputMedia"]
|
|
302
|
+
):
|
|
303
|
+
return await self.client.send_media_group(self.chat.id, media)
|
|
304
|
+
|
|
305
|
+
async def reply_photo(
|
|
306
|
+
self,
|
|
307
|
+
photo: Union[str, bytes, BinaryIO, "objects.InputMedia"],
|
|
308
|
+
caption: str = None,
|
|
309
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
310
|
+
):
|
|
311
|
+
return await self.client.send_photo(self.chat.id, photo, caption, reply_markup, self.id)
|
|
312
|
+
|
|
313
|
+
async def reply_sticker(
|
|
314
|
+
self,
|
|
315
|
+
sticker: Union[str, bytes, BinaryIO, "objects.InputMedia"],
|
|
316
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
317
|
+
):
|
|
318
|
+
return await self.client.send_sticker(self.chat.id, sticker, reply_markup, self.id)
|
|
319
|
+
|
|
320
|
+
async def reply_video(
|
|
321
|
+
self,
|
|
322
|
+
video: Union[str, bytes, BinaryIO, "objects.InputMedia"],
|
|
323
|
+
duration: int = None,
|
|
324
|
+
width: int = None,
|
|
325
|
+
height: int = None,
|
|
326
|
+
caption: str = None,
|
|
327
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
328
|
+
):
|
|
329
|
+
return await self.client.send_video(self.chat.id, video, duration, width, height, caption, reply_markup)
|
|
330
|
+
|
|
331
|
+
async def reply_voice(
|
|
332
|
+
self,
|
|
333
|
+
voice: Union[str, bytes, BinaryIO, "objects.InputMedia"],
|
|
334
|
+
caption: str = None,
|
|
335
|
+
duration: int = None,
|
|
336
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
337
|
+
):
|
|
338
|
+
return await self.client.send_voice(self.chat.id, voice, caption, duration, reply_markup, self.id)
|
|
339
|
+
|
|
340
|
+
async def reply(
|
|
341
|
+
self,
|
|
342
|
+
text: str,
|
|
343
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
344
|
+
):
|
|
345
|
+
return await self.client.send_message(self.chat.id, text, reply_markup, self.id)
|
|
346
|
+
|
|
347
|
+
async def edit_text(
|
|
348
|
+
self,
|
|
349
|
+
text: str,
|
|
350
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
351
|
+
):
|
|
352
|
+
return await self.client.edit_message_text(self.chat.id, self.id, text, reply_markup)
|
|
353
|
+
|
|
354
|
+
async def edit_caption(
|
|
355
|
+
self,
|
|
356
|
+
caption: str,
|
|
357
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
358
|
+
):
|
|
359
|
+
return await self.client.edit_message_caption(self.chat.id, self.id, caption, reply_markup)
|
|
360
|
+
|
|
361
|
+
async def edit(
|
|
362
|
+
self,
|
|
363
|
+
text: str,
|
|
364
|
+
reply_markup: "objects.ReplyMarkup" = None
|
|
365
|
+
):
|
|
366
|
+
if self.text:
|
|
367
|
+
return await self.edit_text(text, reply_markup)
|
|
368
|
+
return await self.edit_caption(text, reply_markup)
|
|
369
|
+
|
|
370
|
+
async def edit_reply_markup(
|
|
371
|
+
self,
|
|
372
|
+
reply_markup: "objects.ReplyMarkup"
|
|
373
|
+
):
|
|
374
|
+
return await self.client.edit_message_reply_markup(self.chat.id, self.id, reply_markup)
|
|
375
|
+
|
|
376
|
+
async def delete(
|
|
377
|
+
self
|
|
378
|
+
):
|
|
379
|
+
return await self.client.delete_message(self.chat.id, self.id)
|
|
380
|
+
|
|
381
|
+
async def forward(
|
|
382
|
+
self,
|
|
383
|
+
chat_id: Union[int, str]
|
|
384
|
+
):
|
|
385
|
+
return await self.client.forward_message(chat_id, self.chat.id, self.id)
|
|
386
|
+
|
|
387
|
+
async def copy(
|
|
388
|
+
self,
|
|
389
|
+
chat_id: Union[int, str]
|
|
390
|
+
):
|
|
391
|
+
return await self.client.copy_message(chat_id, self.chat.id, self.id)
|
|
392
|
+
|
|
393
|
+
async def send(
|
|
394
|
+
self,
|
|
395
|
+
chat_id: Union[int, str],
|
|
396
|
+
reply_markup: "objects.ReplyMarkup" = None,
|
|
397
|
+
reply_to_message_id: int = None
|
|
398
|
+
):
|
|
399
|
+
if self.text:
|
|
400
|
+
return await self.client.send_message(
|
|
401
|
+
chat_id,
|
|
402
|
+
self.text,
|
|
403
|
+
reply_markup,
|
|
404
|
+
reply_to_message_id
|
|
405
|
+
)
|
|
406
|
+
elif self.photo:
|
|
407
|
+
return await self.client.send_photo(
|
|
408
|
+
chat_id,
|
|
409
|
+
self.photo[0].id,
|
|
410
|
+
self.caption,
|
|
411
|
+
reply_markup,
|
|
412
|
+
reply_to_message_id
|
|
413
|
+
)
|
|
414
|
+
elif self.voice:
|
|
415
|
+
return await self.client.send_voice(
|
|
416
|
+
chat_id,
|
|
417
|
+
self.voice.id,
|
|
418
|
+
caption=self.caption,
|
|
419
|
+
reply_markup=reply_markup,
|
|
420
|
+
reply_to_message_id=reply_to_message_id
|
|
421
|
+
)
|
|
422
|
+
elif self.audio:
|
|
423
|
+
return await self.client.send_audio(
|
|
424
|
+
chat_id,
|
|
425
|
+
self.audio.id,
|
|
426
|
+
caption=self.caption,
|
|
427
|
+
reply_markup=reply_markup,
|
|
428
|
+
reply_to_message_id=reply_to_message_id
|
|
429
|
+
)
|
|
430
|
+
elif self.video:
|
|
431
|
+
return await self.client.send_video(
|
|
432
|
+
chat_id,
|
|
433
|
+
self.video.id,
|
|
434
|
+
caption=self.caption,
|
|
435
|
+
reply_markup=reply_markup,
|
|
436
|
+
reply_to_message_id=reply_to_message_id
|
|
437
|
+
)
|
|
438
|
+
elif self.animation:
|
|
439
|
+
return await self.client.send_animation(
|
|
440
|
+
chat_id,
|
|
441
|
+
self.animation.id,
|
|
442
|
+
caption=self.caption,
|
|
443
|
+
reply_markup=reply_markup,
|
|
444
|
+
reply_to_message_id=reply_to_message_id
|
|
445
|
+
)
|
|
446
|
+
elif self.contact:
|
|
447
|
+
return await self.client.send_contact(
|
|
448
|
+
chat_id,
|
|
449
|
+
self.contact.phone_number,
|
|
450
|
+
self.contact.first_name,
|
|
451
|
+
self.contact.last_name,
|
|
452
|
+
reply_markup=reply_markup,
|
|
453
|
+
reply_to_message_id=reply_to_message_id
|
|
454
|
+
)
|
|
455
|
+
elif self.location:
|
|
456
|
+
return await self.client.send_location(
|
|
457
|
+
chat_id,
|
|
458
|
+
self.location.longitude,
|
|
459
|
+
self.location.latitude,
|
|
460
|
+
reply_markup=reply_markup,
|
|
461
|
+
reply_to_message_id=reply_to_message_id
|
|
462
|
+
)
|
|
463
|
+
elif self.sticker:
|
|
464
|
+
return await self.client.send_sticker(
|
|
465
|
+
chat_id,
|
|
466
|
+
self.sticker.id,
|
|
467
|
+
reply_markup=reply_markup,
|
|
468
|
+
reply_to_message_id=reply_to_message_id
|
|
469
|
+
)
|
|
470
|
+
elif self.document:
|
|
471
|
+
return await self.client.send_document(
|
|
472
|
+
chat_id,
|
|
473
|
+
self.document.id,
|
|
474
|
+
self.caption,
|
|
475
|
+
reply_markup,
|
|
476
|
+
reply_to_message_id
|
|
477
|
+
)
|
|
478
|
+
raise TypeError("Message is not copyable")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from . import Object
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MessageId(Object):
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
message_id: Union[str, tuple] = None,
|
|
10
|
+
*,
|
|
11
|
+
rid: int = None,
|
|
12
|
+
date: int = None,
|
|
13
|
+
**kwargs
|
|
14
|
+
):
|
|
15
|
+
super().__init__(**kwargs)
|
|
16
|
+
if message_id is not None and isinstance(message_id, str):
|
|
17
|
+
rid, date = map(int, message_id.split(":"))
|
|
18
|
+
elif message_id is not None:
|
|
19
|
+
rid, date = message_id
|
|
20
|
+
self.rid = rid
|
|
21
|
+
self.date = date
|
|
22
|
+
|
|
23
|
+
def __str__(self):
|
|
24
|
+
return f"{self.rid}:{self.date}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def resolve_message_id(message_id: Union[str, tuple, MessageId]) -> MessageId:
|
|
28
|
+
if not isinstance(message_id, MessageId):
|
|
29
|
+
message_id = MessageId(message_id)
|
|
30
|
+
|
|
31
|
+
return message_id
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from typing import get_type_hints, get_args, get_origin, Union, List, Optional
|
|
2
|
+
from copy import copy
|
|
3
|
+
from json import dumps
|
|
4
|
+
|
|
5
|
+
from ..enums import NameEnum
|
|
6
|
+
import PySPlusthon
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Object:
|
|
10
|
+
attribute_names = []
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def expected_types(cls):
|
|
14
|
+
return get_type_hints(cls.__init__)
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def validate_types(cls, raw_object):
|
|
18
|
+
expected_types = cls.expected_types()
|
|
19
|
+
for key, value in raw_object.items():
|
|
20
|
+
if not expected_types.get(key):
|
|
21
|
+
continue
|
|
22
|
+
if value is None:
|
|
23
|
+
continue
|
|
24
|
+
expected_type = expected_types[key]
|
|
25
|
+
union_type = Union if type(Union) is type else (type(Union), type(Union[str, int]))
|
|
26
|
+
if isinstance(expected_type, union_type) and get_origin(expected_type) in (Union, None):
|
|
27
|
+
expected_type = get_args(expected_type)[0]
|
|
28
|
+
if isinstance(expected_type, (type(List), type(List[str]))) and get_origin(expected_type) == list:
|
|
29
|
+
if isinstance(value, list):
|
|
30
|
+
raw_object[key] = wrap(expected_type, value)
|
|
31
|
+
continue
|
|
32
|
+
if issubclass(expected_type, NameEnum):
|
|
33
|
+
try:
|
|
34
|
+
raw_object[key] = expected_type(value)
|
|
35
|
+
except ValueError:
|
|
36
|
+
pass
|
|
37
|
+
else:
|
|
38
|
+
continue
|
|
39
|
+
if not issubclass(expected_type, Object):
|
|
40
|
+
continue
|
|
41
|
+
if isinstance(value, expected_type):
|
|
42
|
+
continue
|
|
43
|
+
raw_object[key] = expected_type.wrap(value)
|
|
44
|
+
return raw_object
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def wrap(cls, raw_object):
|
|
48
|
+
for attribute_name, key_name in cls.attribute_names:
|
|
49
|
+
if raw_object.get(key_name):
|
|
50
|
+
raw_object[attribute_name] = raw_object.pop(key_name)
|
|
51
|
+
raw_object = cls.validate_types(raw_object)
|
|
52
|
+
return cls(**raw_object)
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def from_protobuf(cls, protobuf_data):
|
|
56
|
+
raise NotImplementedError()
|
|
57
|
+
|
|
58
|
+
def __setitem__(self, key, value):
|
|
59
|
+
setattr(self, key, value)
|
|
60
|
+
|
|
61
|
+
def __getitem__(self, item):
|
|
62
|
+
return getattr(self, item)
|
|
63
|
+
|
|
64
|
+
def bind(self, client):
|
|
65
|
+
self.client = client
|
|
66
|
+
for value in self.__dict__.values():
|
|
67
|
+
if isinstance(value, Object):
|
|
68
|
+
value.bind(client)
|
|
69
|
+
|
|
70
|
+
def __init__(
|
|
71
|
+
self,
|
|
72
|
+
**kwargs
|
|
73
|
+
):
|
|
74
|
+
self.client: Optional["PySPlusthon.Client"] = None
|
|
75
|
+
for key, value in kwargs.items():
|
|
76
|
+
self[key] = value
|
|
77
|
+
|
|
78
|
+
def unwrap(self):
|
|
79
|
+
result = copy(self)
|
|
80
|
+
del result.client
|
|
81
|
+
for key, value in result.__dict__.copy().items():
|
|
82
|
+
if isinstance(value, NameEnum):
|
|
83
|
+
result[key] = value.value
|
|
84
|
+
if isinstance(value, list):
|
|
85
|
+
result[key] = unwrap(value)
|
|
86
|
+
if isinstance(value, Object):
|
|
87
|
+
result[key] = value.unwrap()
|
|
88
|
+
if value is None:
|
|
89
|
+
delattr(result, key)
|
|
90
|
+
for attribute_name, key_name in result.attribute_names:
|
|
91
|
+
if result.__dict__.get(attribute_name):
|
|
92
|
+
result[key_name] = result.__dict__.pop(attribute_name)
|
|
93
|
+
return result.__dict__
|
|
94
|
+
|
|
95
|
+
def to_json(self):
|
|
96
|
+
return dumps(self.unwrap(), ensure_ascii=False, indent=4)
|
|
97
|
+
|
|
98
|
+
def __repr__(self):
|
|
99
|
+
attributes = []
|
|
100
|
+
for key, value in self.__dict__.items():
|
|
101
|
+
if key == "client":
|
|
102
|
+
continue
|
|
103
|
+
if value is None:
|
|
104
|
+
continue
|
|
105
|
+
attributes.append(f"{key}={repr(value)}")
|
|
106
|
+
|
|
107
|
+
if not attributes:
|
|
108
|
+
return f"{type(self).__name__}()"
|
|
109
|
+
|
|
110
|
+
attributes = ",\n".join(attributes)
|
|
111
|
+
attributes = "\n".join(" "*4 + line for line in attributes.splitlines())
|
|
112
|
+
return f"{type(self).__name__}(\n{attributes}\n)"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def wrap(expected_type, raw_object):
|
|
116
|
+
if isinstance(expected_type, (type(List), type(List[str]))) and get_origin(expected_type) == list:
|
|
117
|
+
if isinstance(raw_object, list):
|
|
118
|
+
expected_type = get_args(expected_type)[0]
|
|
119
|
+
raw_object = copy(raw_object)
|
|
120
|
+
for i, element in enumerate(raw_object):
|
|
121
|
+
if element is None:
|
|
122
|
+
continue
|
|
123
|
+
if isinstance(expected_type, (type(List), type(List[str]))) and get_origin(expected_type) == list:
|
|
124
|
+
if isinstance(element, list):
|
|
125
|
+
raw_object[i] = wrap(expected_type, element)
|
|
126
|
+
continue
|
|
127
|
+
if not issubclass(expected_type, Object):
|
|
128
|
+
continue
|
|
129
|
+
if isinstance(element, expected_type):
|
|
130
|
+
continue
|
|
131
|
+
raw_object[i] = expected_type.wrap(element)
|
|
132
|
+
from .list import List as PySplusthonList
|
|
133
|
+
return PySplusthonList(raw_object)
|
|
134
|
+
|
|
135
|
+
if issubclass(expected_type, Object):
|
|
136
|
+
return expected_type.wrap(raw_object)
|
|
137
|
+
|
|
138
|
+
return raw_object
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def unwrap(wrapped_object):
|
|
142
|
+
if isinstance(wrapped_object, list):
|
|
143
|
+
wrapped_object = copy(wrapped_object)
|
|
144
|
+
for i, element in enumerate(wrapped_object):
|
|
145
|
+
wrapped_object[i] = unwrap(element)
|
|
146
|
+
return list(wrapped_object)
|
|
147
|
+
|
|
148
|
+
if isinstance(wrapped_object, Object):
|
|
149
|
+
return wrapped_object.unwrap()
|
|
150
|
+
|
|
151
|
+
if isinstance(wrapped_object, NameEnum):
|
|
152
|
+
return wrapped_object.value
|
|
153
|
+
|
|
154
|
+
return wrapped_object
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from . import Object
|
|
2
|
+
from PySPlusthon import objects
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class OrderInfo(Object):
|
|
6
|
+
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
name: str = None,
|
|
10
|
+
phone_number: str = None,
|
|
11
|
+
email: str = None,
|
|
12
|
+
shipping_address: "objects.ShippingAddress" = None,
|
|
13
|
+
**kwargs
|
|
14
|
+
):
|
|
15
|
+
super().__init__(**kwargs)
|
|
16
|
+
self.name: str = name
|
|
17
|
+
self.phone_number: str = phone_number
|
|
18
|
+
self.email: str = email
|
|
19
|
+
self.shipping_address: "objects.ShippingAddress" = shipping_address
|