PySPlusthon 0.5.0__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.
Files changed (285) hide show
  1. PySPlusthon/__init__.py +3 -0
  2. PySPlusthon/client/__init__.py +1 -0
  3. PySPlusthon/client/attachments/__init__.py +29 -0
  4. PySPlusthon/client/attachments/get_file.py +22 -0
  5. PySPlusthon/client/attachments/send_animation.py +71 -0
  6. PySPlusthon/client/attachments/send_audio.py +54 -0
  7. PySPlusthon/client/attachments/send_contact.py +47 -0
  8. PySPlusthon/client/attachments/send_document.py +63 -0
  9. PySPlusthon/client/attachments/send_location.py +45 -0
  10. PySPlusthon/client/attachments/send_media_group.py +88 -0
  11. PySPlusthon/client/attachments/send_photo.py +67 -0
  12. PySPlusthon/client/attachments/send_sticker.py +51 -0
  13. PySPlusthon/client/attachments/send_video.py +56 -0
  14. PySPlusthon/client/attachments/send_voice.py +52 -0
  15. PySPlusthon/client/attachments/upload_file.py +82 -0
  16. PySPlusthon/client/chats/__init__.py +43 -0
  17. PySPlusthon/client/chats/ban_chat_member.py +24 -0
  18. PySPlusthon/client/chats/delete_chat_photo.py +32 -0
  19. PySPlusthon/client/chats/get_chat.py +69 -0
  20. PySPlusthon/client/chats/get_chat_administrators.py +18 -0
  21. PySPlusthon/client/chats/get_chat_history.py +39 -0
  22. PySPlusthon/client/chats/get_chat_member.py +16 -0
  23. PySPlusthon/client/chats/get_chat_members.py +29 -0
  24. PySPlusthon/client/chats/get_chat_members_count.py +21 -0
  25. PySPlusthon/client/chats/join_chat.py +31 -0
  26. PySPlusthon/client/chats/leave_chat.py +22 -0
  27. PySPlusthon/client/chats/pin_chat_message.py +31 -0
  28. PySPlusthon/client/chats/promote_chat_member.py +64 -0
  29. PySPlusthon/client/chats/restrict_chat_member.py +25 -0
  30. PySPlusthon/client/chats/set_chat_description.py +23 -0
  31. PySPlusthon/client/chats/set_chat_photo.py +33 -0
  32. PySPlusthon/client/chats/set_chat_title.py +23 -0
  33. PySPlusthon/client/chats/unban_chat_member.py +24 -0
  34. PySPlusthon/client/chats/unpin_all_chat_messages.py +38 -0
  35. PySPlusthon/client/chats/unpin_chat_message.py +33 -0
  36. PySPlusthon/client/client.py +232 -0
  37. PySPlusthon/client/invite_links/__init__.py +7 -0
  38. PySPlusthon/client/invite_links/create_chat_invite_link.py +14 -0
  39. PySPlusthon/client/invite_links/export_chat_invite_link.py +21 -0
  40. PySPlusthon/client/invite_links/revoke_chat_invite_link.py +23 -0
  41. PySPlusthon/client/messages/__init__.py +21 -0
  42. PySPlusthon/client/messages/answer_callback_query.py +12 -0
  43. PySPlusthon/client/messages/copy_message.py +43 -0
  44. PySPlusthon/client/messages/delete_message.py +29 -0
  45. PySPlusthon/client/messages/edit_message_caption.py +40 -0
  46. PySPlusthon/client/messages/edit_message_reply_markup.py +17 -0
  47. PySPlusthon/client/messages/edit_message_text.py +40 -0
  48. PySPlusthon/client/messages/forward_message.py +35 -0
  49. PySPlusthon/client/messages/send_message.py +38 -0
  50. PySPlusthon/client/stickers/__init__.py +9 -0
  51. PySPlusthon/client/stickers/add_sticker_to_set.py +15 -0
  52. PySPlusthon/client/stickers/create_new_sticker_set.py +16 -0
  53. PySPlusthon/client/stickers/delete_sticker_from_set.py +10 -0
  54. PySPlusthon/client/stickers/get_sticker_set.py +11 -0
  55. PySPlusthon/client/stickers/upload_sticker_file.py +16 -0
  56. PySPlusthon/client/updates/__init__.py +8 -0
  57. PySPlusthon/client/updates/delete_webhook.py +9 -0
  58. PySPlusthon/client/updates/get_updates.py +14 -0
  59. PySPlusthon/client/updates/get_webhook_info.py +10 -0
  60. PySPlusthon/client/updates/set_webhook.py +10 -0
  61. PySPlusthon/client/users/__init__.py +6 -0
  62. PySPlusthon/client/users/ask_review.py +14 -0
  63. PySPlusthon/client/users/get_me.py +16 -0
  64. PySPlusthon/conditions/__init__.py +43 -0
  65. PySPlusthon/conditions/all.py +6 -0
  66. PySPlusthon/conditions/animation.py +7 -0
  67. PySPlusthon/conditions/at_state.py +18 -0
  68. PySPlusthon/conditions/audio.py +7 -0
  69. PySPlusthon/conditions/author.py +13 -0
  70. PySPlusthon/conditions/caption.py +7 -0
  71. PySPlusthon/conditions/channel.py +11 -0
  72. PySPlusthon/conditions/channel_chat_created.py +7 -0
  73. PySPlusthon/conditions/chat.py +14 -0
  74. PySPlusthon/conditions/click.py +24 -0
  75. PySPlusthon/conditions/command.py +23 -0
  76. PySPlusthon/conditions/condition.py +88 -0
  77. PySPlusthon/conditions/contact.py +7 -0
  78. PySPlusthon/conditions/content.py +7 -0
  79. PySPlusthon/conditions/delete_chat_photo.py +7 -0
  80. PySPlusthon/conditions/document.py +7 -0
  81. PySPlusthon/conditions/entities.py +7 -0
  82. PySPlusthon/conditions/equals.py +14 -0
  83. PySPlusthon/conditions/forward.py +7 -0
  84. PySPlusthon/conditions/group.py +11 -0
  85. PySPlusthon/conditions/group_chat_created.py +7 -0
  86. PySPlusthon/conditions/is_admin.py +17 -0
  87. PySPlusthon/conditions/is_instance.py +10 -0
  88. PySPlusthon/conditions/is_joined.py +61 -0
  89. PySPlusthon/conditions/left_chat_member.py +7 -0
  90. PySPlusthon/conditions/location.py +7 -0
  91. PySPlusthon/conditions/media.py +7 -0
  92. PySPlusthon/conditions/media_group.py +7 -0
  93. PySPlusthon/conditions/new_chat_members.py +7 -0
  94. PySPlusthon/conditions/new_chat_photo.py +7 -0
  95. PySPlusthon/conditions/new_chat_title.py +7 -0
  96. PySPlusthon/conditions/number.py +12 -0
  97. PySPlusthon/conditions/photo.py +7 -0
  98. PySPlusthon/conditions/pinned_message.py +7 -0
  99. PySPlusthon/conditions/poll.py +7 -0
  100. PySPlusthon/conditions/private.py +11 -0
  101. PySPlusthon/conditions/regex.py +17 -0
  102. PySPlusthon/conditions/reply.py +7 -0
  103. PySPlusthon/conditions/sticker.py +7 -0
  104. PySPlusthon/conditions/supergroup_chat_created.py +7 -0
  105. PySPlusthon/conditions/text.py +7 -0
  106. PySPlusthon/conditions/video.py +7 -0
  107. PySPlusthon/conditions/voice.py +7 -0
  108. PySPlusthon/dispatcher/__init__.py +5 -0
  109. PySPlusthon/dispatcher/chain.py +165 -0
  110. PySPlusthon/dispatcher/dispatcher.py +124 -0
  111. PySPlusthon/dispatcher/logging_chain.py +36 -0
  112. PySPlusthon/dispatcher/monitoring_chain.py +19 -0
  113. PySPlusthon/dispatcher/printing_chain.py +21 -0
  114. PySPlusthon/enums/__init__.py +7 -0
  115. PySPlusthon/enums/chat_member_status.py +9 -0
  116. PySPlusthon/enums/chat_type.py +9 -0
  117. PySPlusthon/enums/message_media_type.py +16 -0
  118. PySPlusthon/enums/name_enum.py +13 -0
  119. PySPlusthon/enums/peer_type.py +8 -0
  120. PySPlusthon/enums/poll_type.py +8 -0
  121. PySPlusthon/enums/transaction_status.py +10 -0
  122. PySPlusthon/errors/__init__.py +11 -0
  123. PySPlusthon/errors/dispatching_errors/__init__.py +2 -0
  124. PySPlusthon/errors/dispatching_errors/break_dispatching.py +2 -0
  125. PySPlusthon/errors/dispatching_errors/continue_dispatching.py +2 -0
  126. PySPlusthon/errors/rpc_errors/__init__.py +8 -0
  127. PySPlusthon/errors/rpc_errors/bad_request_error.py +6 -0
  128. PySPlusthon/errors/rpc_errors/flood_error.py +6 -0
  129. PySPlusthon/errors/rpc_errors/forbidden_error.py +6 -0
  130. PySPlusthon/errors/rpc_errors/internal_error.py +6 -0
  131. PySPlusthon/errors/rpc_errors/not_found_error.py +6 -0
  132. PySPlusthon/errors/rpc_errors/rpc_error.py +23 -0
  133. PySPlusthon/errors/rpc_errors/too_many_requests.py +10 -0
  134. PySPlusthon/errors/rpc_errors/unauthorized_error.py +6 -0
  135. PySPlusthon/event_handlers/__init__.py +12 -0
  136. PySPlusthon/event_handlers/callback_query_handler.py +16 -0
  137. PySPlusthon/event_handlers/command_handler.py +46 -0
  138. PySPlusthon/event_handlers/connect_handler.py +19 -0
  139. PySPlusthon/event_handlers/disconnect_handler.py +18 -0
  140. PySPlusthon/event_handlers/edited_message_handler.py +16 -0
  141. PySPlusthon/event_handlers/error_handler.py +15 -0
  142. PySPlusthon/event_handlers/event_handler.py +53 -0
  143. PySPlusthon/event_handlers/initialize_handler.py +18 -0
  144. PySPlusthon/event_handlers/message_handler.py +16 -0
  145. PySPlusthon/event_handlers/shipping_query_handler.py +16 -0
  146. PySPlusthon/event_handlers/shutdown_handler.py +18 -0
  147. PySPlusthon/event_handlers/update_handler.py +16 -0
  148. PySPlusthon/network/__init__.py +1 -0
  149. PySPlusthon/network/httpconnection.py +74 -0
  150. PySPlusthon/objects/__init__.py +44 -0
  151. PySPlusthon/objects/animation.py +44 -0
  152. PySPlusthon/objects/audio.py +36 -0
  153. PySPlusthon/objects/callback_query.py +37 -0
  154. PySPlusthon/objects/chat.py +118 -0
  155. PySPlusthon/objects/chat_member.py +53 -0
  156. PySPlusthon/objects/chat_permissions.py +26 -0
  157. PySPlusthon/objects/chat_photo.py +24 -0
  158. PySPlusthon/objects/contact.py +18 -0
  159. PySPlusthon/objects/copy_text_button.py +18 -0
  160. PySPlusthon/objects/date.py +35 -0
  161. PySPlusthon/objects/document.py +36 -0
  162. PySPlusthon/objects/edited_message.py +27 -0
  163. PySPlusthon/objects/entity.py +21 -0
  164. PySPlusthon/objects/file.py +21 -0
  165. PySPlusthon/objects/forward_origin.py +22 -0
  166. PySPlusthon/objects/inline_keyboard.py +65 -0
  167. PySPlusthon/objects/inline_keyboard_button.py +42 -0
  168. PySPlusthon/objects/input_media.py +44 -0
  169. PySPlusthon/objects/input_media_photo.py +14 -0
  170. PySPlusthon/objects/input_media_video.py +14 -0
  171. PySPlusthon/objects/invite_link.py +32 -0
  172. PySPlusthon/objects/list.py +24 -0
  173. PySPlusthon/objects/location.py +14 -0
  174. PySPlusthon/objects/message.py +478 -0
  175. PySPlusthon/objects/message_id.py +31 -0
  176. PySPlusthon/objects/object.py +154 -0
  177. PySPlusthon/objects/order_info.py +19 -0
  178. PySPlusthon/objects/photo.py +31 -0
  179. PySPlusthon/objects/poll.py +34 -0
  180. PySPlusthon/objects/poll_option.py +16 -0
  181. PySPlusthon/objects/reply_keyboard.py +79 -0
  182. PySPlusthon/objects/reply_keyboard_button.py +29 -0
  183. PySPlusthon/objects/reply_keyboard_remove.py +10 -0
  184. PySPlusthon/objects/reply_markup.py +12 -0
  185. PySPlusthon/objects/shipping_address.py +22 -0
  186. PySPlusthon/objects/shipping_query.py +20 -0
  187. PySPlusthon/objects/sticker.py +54 -0
  188. PySPlusthon/objects/sticker_set.py +29 -0
  189. PySPlusthon/objects/transaction.py +25 -0
  190. PySPlusthon/objects/update.py +33 -0
  191. PySPlusthon/objects/user.py +60 -0
  192. PySPlusthon/objects/video.py +45 -0
  193. PySPlusthon/objects/voice.py +31 -0
  194. PySPlusthon/objects/webhook_info.py +16 -0
  195. PySPlusthon/proto/__init__.py +2 -0
  196. PySPlusthon/proto/enums_pb2.py +46 -0
  197. PySPlusthon/proto/enums_pb2.pyi +99 -0
  198. PySPlusthon/proto/enums_pb2_grpc.py +24 -0
  199. PySPlusthon/proto/requests/__init__.py +209 -0
  200. PySPlusthon/proto/requests/abacus_pb2.py +40 -0
  201. PySPlusthon/proto/requests/abacus_pb2.pyi +31 -0
  202. PySPlusthon/proto/requests/abacus_pb2_grpc.py +24 -0
  203. PySPlusthon/proto/requests/auth_pb2.py +49 -0
  204. PySPlusthon/proto/requests/auth_pb2.pyi +67 -0
  205. PySPlusthon/proto/requests/auth_pb2_grpc.py +24 -0
  206. PySPlusthon/proto/requests/configs_pb2.py +37 -0
  207. PySPlusthon/proto/requests/configs_pb2.pyi +15 -0
  208. PySPlusthon/proto/requests/configs_pb2_grpc.py +24 -0
  209. PySPlusthon/proto/requests/files_pb2.py +40 -0
  210. PySPlusthon/proto/requests/files_pb2.pyi +34 -0
  211. PySPlusthon/proto/requests/files_pb2_grpc.py +24 -0
  212. PySPlusthon/proto/requests/groups_pb2.py +82 -0
  213. PySPlusthon/proto/requests/groups_pb2.pyi +213 -0
  214. PySPlusthon/proto/requests/groups_pb2_grpc.py +24 -0
  215. PySPlusthon/proto/requests/messaging_pb2.py +56 -0
  216. PySPlusthon/proto/requests/messaging_pb2.pyi +119 -0
  217. PySPlusthon/proto/requests/messaging_pb2_grpc.py +24 -0
  218. PySPlusthon/proto/requests/presence_pb2.py +40 -0
  219. PySPlusthon/proto/requests/presence_pb2.pyi +24 -0
  220. PySPlusthon/proto/requests/presence_pb2_grpc.py +24 -0
  221. PySPlusthon/proto/requests/request_pb2.py +42 -0
  222. PySPlusthon/proto/requests/request_pb2.pyi +35 -0
  223. PySPlusthon/proto/requests/request_pb2_grpc.py +24 -0
  224. PySPlusthon/proto/requests/users_pb2.py +43 -0
  225. PySPlusthon/proto/requests/users_pb2.pyi +34 -0
  226. PySPlusthon/proto/requests/users_pb2_grpc.py +24 -0
  227. PySPlusthon/proto/responses/__init__.py +6 -0
  228. PySPlusthon/proto/responses/abacus_pb2.py +37 -0
  229. PySPlusthon/proto/responses/abacus_pb2.pyi +14 -0
  230. PySPlusthon/proto/responses/abacus_pb2_grpc.py +24 -0
  231. PySPlusthon/proto/responses/auth_pb2.py +42 -0
  232. PySPlusthon/proto/responses/auth_pb2.pyi +40 -0
  233. PySPlusthon/proto/responses/auth_pb2_grpc.py +24 -0
  234. PySPlusthon/proto/responses/files_pb2.py +39 -0
  235. PySPlusthon/proto/responses/files_pb2.pyi +27 -0
  236. PySPlusthon/proto/responses/files_pb2_grpc.py +24 -0
  237. PySPlusthon/proto/responses/groups_pb2.py +59 -0
  238. PySPlusthon/proto/responses/groups_pb2.pyi +90 -0
  239. PySPlusthon/proto/responses/groups_pb2_grpc.py +24 -0
  240. PySPlusthon/proto/responses/messaging_pb2.py +44 -0
  241. PySPlusthon/proto/responses/messaging_pb2.pyi +37 -0
  242. PySPlusthon/proto/responses/messaging_pb2_grpc.py +24 -0
  243. PySPlusthon/proto/responses/users_pb2.py +41 -0
  244. PySPlusthon/proto/responses/users_pb2.pyi +28 -0
  245. PySPlusthon/proto/responses/users_pb2_grpc.py +24 -0
  246. PySPlusthon/proto/structs/__init__.py +7 -0
  247. PySPlusthon/proto/structs/collections_pb2.py +54 -0
  248. PySPlusthon/proto/structs/collections_pb2.pyi +79 -0
  249. PySPlusthon/proto/structs/collections_pb2_grpc.py +24 -0
  250. PySPlusthon/proto/structs/files_pb2.py +52 -0
  251. PySPlusthon/proto/structs/files_pb2.pyi +93 -0
  252. PySPlusthon/proto/structs/files_pb2_grpc.py +24 -0
  253. PySPlusthon/proto/structs/groups_pb2.py +49 -0
  254. PySPlusthon/proto/structs/groups_pb2.pyi +144 -0
  255. PySPlusthon/proto/structs/groups_pb2_grpc.py +24 -0
  256. PySPlusthon/proto/structs/messaging_pb2.py +81 -0
  257. PySPlusthon/proto/structs/messaging_pb2.pyi +296 -0
  258. PySPlusthon/proto/structs/messaging_pb2_grpc.py +24 -0
  259. PySPlusthon/proto/structs/peers_pb2.py +47 -0
  260. PySPlusthon/proto/structs/peers_pb2.pyi +56 -0
  261. PySPlusthon/proto/structs/peers_pb2_grpc.py +24 -0
  262. PySPlusthon/proto/structs/set_updates_pb2.py +37 -0
  263. PySPlusthon/proto/structs/set_updates_pb2.pyi +15 -0
  264. PySPlusthon/proto/structs/set_updates_pb2_grpc.py +24 -0
  265. PySPlusthon/proto/structs/users_pb2.py +54 -0
  266. PySPlusthon/proto/structs/users_pb2.pyi +122 -0
  267. PySPlusthon/proto/structs/users_pb2_grpc.py +24 -0
  268. PySPlusthon/proto/updates/__init__.py +1 -0
  269. PySPlusthon/proto/updates/messaging_pb2.py +38 -0
  270. PySPlusthon/proto/updates/messaging_pb2.pyi +26 -0
  271. PySPlusthon/proto/updates/messaging_pb2_grpc.py +24 -0
  272. PySPlusthon/proto/ws_pb2.py +52 -0
  273. PySPlusthon/proto/ws_pb2.pyi +76 -0
  274. PySPlusthon/proto/ws_pb2_grpc.py +24 -0
  275. PySPlusthon/smart_call.py +73 -0
  276. PySPlusthon/states/__init__.py +3 -0
  277. PySPlusthon/states/state.py +11 -0
  278. PySPlusthon/states/state_group.py +13 -0
  279. PySPlusthon/states/state_machine.py +83 -0
  280. PySPlusthon/sync_support.py +48 -0
  281. pysplusthon-0.5.0.dist-info/METADATA +65 -0
  282. pysplusthon-0.5.0.dist-info/RECORD +285 -0
  283. pysplusthon-0.5.0.dist-info/WHEEL +5 -0
  284. pysplusthon-0.5.0.dist-info/licenses/LICENSE +19 -0
  285. pysplusthon-0.5.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,3 @@
1
+ __version__ = "1.0.0"
2
+
3
+ from .client import Client
@@ -0,0 +1 @@
1
+ from .client import Client
@@ -0,0 +1,29 @@
1
+ from .send_photo import SendPhoto
2
+ from .send_animation import SendAnimation
3
+ from .send_audio import SendAudio
4
+ from .send_document import SendDocument
5
+ from .send_sticker import SendSticker
6
+ from .send_video import SendVideo
7
+ from .send_voice import SendVoice
8
+ from .send_location import SendLocation
9
+ from .send_contact import SendContact
10
+ from .send_media_group import SendMediaGroup
11
+ from .get_file import GetFile
12
+ from .upload_file import UploadFile
13
+
14
+
15
+ class Attachments(
16
+ SendPhoto,
17
+ SendAnimation,
18
+ SendAudio,
19
+ SendDocument,
20
+ SendVideo,
21
+ SendVoice,
22
+ SendSticker,
23
+ SendLocation,
24
+ SendContact,
25
+ SendMediaGroup,
26
+ GetFile,
27
+ UploadFile
28
+ ):
29
+ pass
@@ -0,0 +1,22 @@
1
+ import PySPlusthon
2
+ from ...objects import File
3
+
4
+
5
+ class GetFile:
6
+
7
+ async def get_file(
8
+ self: "PySPlusthon.Client",
9
+ file_id: str
10
+ ) -> File:
11
+ if self.is_userbot():
12
+ from ...proto import requests, structs
13
+ access_hash, file_id, file_storage_version = map(int, file_id.split(":"))
14
+ return await self.execute(requests.GetNasimFileUrl(
15
+ file=structs.FileLocation(
16
+ file_id=file_id,
17
+ access_hash=access_hash,
18
+ file_storage_version=structs.Int32Value(value=file_storage_version)
19
+ )
20
+ ))
21
+
22
+ return await self.auto_execute("getFile", locals())
@@ -0,0 +1,71 @@
1
+ from typing import Union, BinaryIO, Optional
2
+ import os
3
+
4
+ import PySPlusthon
5
+ from ...objects import InputMedia, resolve_media, Message, ReplyMarkup
6
+
7
+
8
+ def _extract_filename_media(media) -> Optional[str]:
9
+ if isinstance(media, InputMedia):
10
+ return getattr(media.media, 'name', None) if hasattr(media.media, 'name') else None
11
+ if isinstance(media, str):
12
+ return os.path.basename(media)
13
+ return None
14
+
15
+
16
+ class SendAnimation:
17
+
18
+ async def send_animation(
19
+ self: "PySPlusthon.Client",
20
+ chat_id: Union[int, str],
21
+ animation: Union[str, bytes, BinaryIO, InputMedia],
22
+ duration: int = None,
23
+ width: int = None,
24
+ height: int = None,
25
+ caption: str = None,
26
+ reply_markup: ReplyMarkup = None,
27
+ reply_to_message_id: int = None
28
+ ) -> Message:
29
+ animation = resolve_media(animation)
30
+ filename = _extract_filename_media(animation)
31
+
32
+ if self.is_userbot():
33
+ from ...proto import requests, structs, enums
34
+ peer_id, peer_type = map(int, chat_id.split("|"))
35
+ file = await self.upload_file(chat_id, animation, enums.SEND_TYPE_GIF)
36
+ return await self.execute(requests.SendMessage(
37
+ peer=structs.Peer(
38
+ type=peer_type,
39
+ id=peer_id
40
+ ),
41
+ rid=self.ws_connection.create_rid(),
42
+ message=structs.Message(
43
+ document_message=structs.DocumentMessage(
44
+ file_id=file.id,
45
+ access_hash=peer_id,
46
+ file_size=file.size,
47
+ name=file.name,
48
+ mime_type=file.mime_type,
49
+ ext=structs.DocumentEx(
50
+ document_ex_gif=structs.DocumentExGif(
51
+ w=100,
52
+ h=100,
53
+ duration=10
54
+ )
55
+ ),
56
+ caption=structs.TextMessage(text=caption)
57
+ )
58
+ ),
59
+ ex_peer=structs.Peer(
60
+ type=peer_type,
61
+ id=peer_id
62
+ )
63
+ ))
64
+
65
+ chat_id = await self.resolve_peer_id(chat_id)
66
+ params = {"chat_id": chat_id, "animation": animation, "duration": duration, "width": width, "height": height}
67
+ if caption is not None:
68
+ params["caption"] = caption
69
+ if filename is not None:
70
+ params["filename"] = filename
71
+ return await self.auto_execute("sendAnimation", params, json=False)
@@ -0,0 +1,54 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ import PySPlusthon
4
+ from ...objects import InputMedia, resolve_media, Message, ReplyMarkup
5
+
6
+
7
+ class SendAudio:
8
+
9
+ async def send_audio(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ audio: Union[str, bytes, BinaryIO, InputMedia],
13
+ caption: str = None,
14
+ duration: int = None,
15
+ title: str = None,
16
+ reply_markup: ReplyMarkup = None,
17
+ reply_to_message_id: int = None
18
+ ) -> Message:
19
+ audio = resolve_media(audio)
20
+
21
+ if self.is_userbot():
22
+ from ...proto import requests, structs, enums
23
+ peer_id, peer_type = map(int, chat_id.split("|"))
24
+ file = await self.upload_file(chat_id, audio, enums.SEND_TYPE_AUDIO)
25
+ return await self.execute(requests.SendMessage(
26
+ peer=structs.Peer(
27
+ type=peer_type,
28
+ id=peer_id
29
+ ),
30
+ rid=self.ws_connection.create_rid(),
31
+ message=structs.Message(
32
+ document_message=structs.DocumentMessage(
33
+ file_id=file.id,
34
+ access_hash=peer_id,
35
+ file_size=file.size,
36
+ name=file.name,
37
+ mime_type=file.mime_type,
38
+ ext=structs.DocumentEx(
39
+ document_ex_audio=structs.DocumentExAudio(
40
+ duration=duration,
41
+ track=title or file.name
42
+ )
43
+ ),
44
+ caption=structs.TextMessage(text=caption)
45
+ )
46
+ ),
47
+ ex_peer=structs.Peer(
48
+ type=peer_type,
49
+ id=peer_id
50
+ )
51
+ ))
52
+
53
+ chat_id = await self.resolve_peer_id(chat_id)
54
+ return await self.auto_execute("sendAudio", locals())
@@ -0,0 +1,47 @@
1
+ from typing import Union
2
+ from json import dumps
3
+
4
+ import PySPlusthon
5
+ from ...objects import Message, ReplyMarkup
6
+
7
+
8
+ class SendContact:
9
+
10
+ async def send_contact(
11
+ self: "PySPlusthon.Client",
12
+ chat_id: Union[int, str],
13
+ phone_number: str,
14
+ first_name: str,
15
+ last_name: str = None,
16
+ vcard : bytes = None,
17
+ reply_markup: ReplyMarkup = None,
18
+ reply_to_message_id: int = None
19
+ ) -> Message:
20
+ if self.is_userbot():
21
+ from PySPlusthon.proto import requests, structs
22
+ peer_id, peer_type = map(int, chat_id.split("|"))
23
+ raw_json = {
24
+ "dataType": "contact",
25
+ "data": {
26
+ "contact": {"name": first_name, "emails": [""], "phones": [phone_number]},
27
+ }
28
+ }
29
+ return await self.execute(requests.SendMessage(
30
+ peer=structs.Peer(
31
+ type=peer_type,
32
+ id=peer_id
33
+ ),
34
+ rid=self.ws_connection.create_rid(),
35
+ message=structs.Message(
36
+ json_message=structs.JsonMessage(
37
+ raw_json=dumps(raw_json)
38
+ )
39
+ ),
40
+ ex_peer=structs.Peer(
41
+ type=peer_type,
42
+ id=peer_id
43
+ )
44
+ ))
45
+
46
+ chat_id = await self.resolve_peer_id(chat_id)
47
+ return await self.auto_execute("sendContact", locals())
@@ -0,0 +1,63 @@
1
+ from typing import Union, BinaryIO, Optional
2
+ import os
3
+
4
+ import PySPlusthon
5
+ from ...objects import InputMedia, resolve_media, Message, ReplyMarkup
6
+
7
+
8
+ def _extract_filename(document) -> Optional[str]:
9
+ if isinstance(document, InputMedia):
10
+ return getattr(document.media, 'name', None) if hasattr(document.media, 'name') else None
11
+ if isinstance(document, str):
12
+ return os.path.basename(document)
13
+ if document is not None:
14
+ return getattr(document, 'name', None)
15
+ return None
16
+
17
+
18
+ class SendDocument:
19
+
20
+ async def send_document(
21
+ self: "PySPlusthon.Client",
22
+ chat_id: Union[int, str],
23
+ document: Union[str, bytes, BinaryIO, InputMedia],
24
+ caption: str = None,
25
+ reply_markup: ReplyMarkup = None,
26
+ reply_to_message_id: int = None
27
+ ) -> Message:
28
+ document = resolve_media(document)
29
+ filename = _extract_filename(document)
30
+
31
+ if self.is_userbot():
32
+ from ...proto import requests, structs, enums
33
+ peer_id, peer_type = map(int, chat_id.split("|"))
34
+ file = await self.upload_file(chat_id, document, enums.SEND_TYPE_DOCUMENT)
35
+ return await self.execute(requests.SendMessage(
36
+ peer=structs.Peer(
37
+ type=peer_type,
38
+ id=peer_id
39
+ ),
40
+ rid=self.ws_connection.create_rid(),
41
+ message=structs.Message(
42
+ document_message=structs.DocumentMessage(
43
+ file_id=file.id,
44
+ access_hash=peer_id,
45
+ file_size=file.size,
46
+ name=file.name,
47
+ mime_type=file.mime_type,
48
+ caption=structs.TextMessage(text=caption)
49
+ )
50
+ ),
51
+ ex_peer=structs.Peer(
52
+ type=peer_type,
53
+ id=peer_id
54
+ )
55
+ ))
56
+
57
+ chat_id = await self.resolve_peer_id(chat_id)
58
+ params = {"chat_id": chat_id, "document": document}
59
+ if caption is not None:
60
+ params["caption"] = caption
61
+ if filename is not None:
62
+ params["filename"] = filename
63
+ return await self.auto_execute("sendDocument", params)
@@ -0,0 +1,45 @@
1
+ from typing import Union
2
+ from json import dumps
3
+
4
+ import PySPlusthon
5
+ from ...objects import Message, ReplyMarkup
6
+
7
+
8
+ class SendLocation:
9
+
10
+ async def send_location(
11
+ self: "PySPlusthon.Client",
12
+ chat_id: Union[int, str],
13
+ latitude: float,
14
+ longitude: float,
15
+ reply_markup: ReplyMarkup = None,
16
+ reply_to_message_id: int = None
17
+ ) -> Message:
18
+ if self.is_userbot():
19
+ from PySPlusthon.proto import requests, structs
20
+ peer_id, peer_type = map(int, chat_id.split("|"))
21
+ raw_json = {
22
+ "dataType": "location",
23
+ "data": {
24
+ "location": {"latitude": latitude, "longitude": longitude}
25
+ }
26
+ }
27
+ return await self.execute(requests.SendMessage(
28
+ peer=structs.Peer(
29
+ type=peer_type,
30
+ id=peer_id
31
+ ),
32
+ rid=self.ws_connection.create_rid(),
33
+ message=structs.Message(
34
+ json_message=structs.JsonMessage(
35
+ raw_json=dumps(raw_json)
36
+ )
37
+ ),
38
+ ex_peer=structs.Peer(
39
+ type=peer_type,
40
+ id=peer_id
41
+ )
42
+ ))
43
+
44
+ chat_id = await self.resolve_peer_id(chat_id)
45
+ return await self.auto_execute("sendLocation", locals())
@@ -0,0 +1,88 @@
1
+ from typing import Union
2
+ from json import dumps
3
+ from typing import List
4
+
5
+ import PySPlusthon
6
+ from ...objects import Message, ReplyMarkup, InputMediaPhoto, InputMediaVideo
7
+ from PySPlusthon import objects
8
+
9
+
10
+ class SendMediaGroup:
11
+
12
+ async def send_media_group(
13
+ self: "PySPlusthon.Client",
14
+ chat_id: Union[int, str],
15
+ media: List["objects.InputMedia"],
16
+ reply_markup: ReplyMarkup = None,
17
+ reply_to_message_id: int = None
18
+ ) -> List[Message]:
19
+ if self.is_userbot():
20
+ from ...proto import requests, structs, enums
21
+ peer_id, peer_type = map(int, chat_id.split("|"))
22
+ files = []
23
+ for content in media:
24
+ if isinstance(content, InputMediaPhoto):
25
+ send_type = enums.SEND_TYPE_PHOTO
26
+ elif isinstance(content, InputMediaVideo):
27
+ send_type = enums.SEND_TYPE_VIDEO
28
+ else:
29
+ send_type = enums.SEND_TYPE_DOCUMENT
30
+ file = await self.upload_file(f"{peer_id}|{peer_type}", content.media, send_type)
31
+
32
+ if send_type == enums.SEND_TYPE_PHOTO:
33
+ ext = structs.DocumentEx(
34
+ document_ex_photo=structs.DocumentExPhoto(
35
+ w=500,
36
+ h=500
37
+ )
38
+ )
39
+ else:
40
+ ext = structs.DocumentEx(
41
+ document_ex_video=structs.DocumentExVideo(
42
+ w=500,
43
+ h=500,
44
+ duration=10
45
+ )
46
+ )
47
+
48
+ single_media = structs.SingleMedia(
49
+ random_id=self.ws_connection.create_rid(),
50
+ media=structs.DocumentMessage(
51
+ file_id=file.id,
52
+ access_hash=peer_id,
53
+ file_size=file.size,
54
+ name=file.name,
55
+ mime_type=file.mime_type,
56
+ ext=ext,
57
+ caption=structs.TextMessage(text=content.caption)
58
+ )
59
+ )
60
+ files.append(single_media)
61
+
62
+ return await self.execute(requests.SendMultiMediaMessage(
63
+ peer=structs.ExPeer(
64
+ type=peer_type,
65
+ id=peer_id,
66
+ ),
67
+ multi_media=files,
68
+ grouped_id=self.ws_connection.create_rid(),
69
+ ))
70
+
71
+ chat_id = await self.resolve_peer_id(chat_id)
72
+ data = locals()
73
+ del data["self"]
74
+ if any(not m.is_json_serializable for m in data["media"]):
75
+ for i, m in enumerate(data["media"]):
76
+ data["media"][i] = m.unwrap()
77
+ if not m.is_json_serializable:
78
+ data[f"media{i}"] = m.media
79
+ data["media"][i]["media"] = f"media{i}"
80
+ data["media"] = dumps(data["media"])
81
+ else:
82
+ for i, m in enumerate(data["media"]):
83
+ data["media"][i] = m.unwrap()
84
+ result = await self.execute("sendMediaGroup", **data)
85
+ result = [Message.wrap(message) for message in result]
86
+ for message in result:
87
+ message.bind(self)
88
+ return result
@@ -0,0 +1,67 @@
1
+ from typing import Union, BinaryIO, Optional
2
+ import os
3
+
4
+ import PySPlusthon
5
+ from ...objects import InputMedia, resolve_media, Message, ReplyMarkup
6
+
7
+
8
+ def _extract_filename_media(media) -> Optional[str]:
9
+ if isinstance(media, InputMedia):
10
+ return getattr(media.media, 'name', None) if hasattr(media.media, 'name') else None
11
+ if isinstance(media, str):
12
+ return os.path.basename(media)
13
+ return None
14
+
15
+
16
+ class SendPhoto:
17
+
18
+ async def send_photo(
19
+ self: "PySPlusthon.Client",
20
+ chat_id: Union[int, str],
21
+ photo: Union[str, bytes, BinaryIO, InputMedia],
22
+ caption: str = None,
23
+ reply_markup: ReplyMarkup = None,
24
+ reply_to_message_id: int = None
25
+ ) -> Message:
26
+ photo = resolve_media(photo)
27
+ filename = _extract_filename_media(photo)
28
+
29
+ if self.is_userbot():
30
+ from ...proto import requests, structs, enums
31
+ peer_id, peer_type = map(int, chat_id.split("|"))
32
+ file = await self.upload_file(chat_id, photo, enums.SEND_TYPE_PHOTO)
33
+ return await self.execute(requests.SendMessage(
34
+ peer=structs.Peer(
35
+ type=peer_type,
36
+ id=peer_id
37
+ ),
38
+ rid=self.ws_connection.create_rid(),
39
+ message=structs.Message(
40
+ document_message=structs.DocumentMessage(
41
+ file_id=file.id,
42
+ access_hash=peer_id,
43
+ file_size=file.size,
44
+ name=file.name,
45
+ mime_type=file.mime_type,
46
+ ext=structs.DocumentEx(
47
+ document_ex_photo=structs.DocumentExPhoto(
48
+ w=100,
49
+ h=100
50
+ )
51
+ ),
52
+ caption=structs.TextMessage(text=caption)
53
+ )
54
+ ),
55
+ ex_peer=structs.Peer(
56
+ type=peer_type,
57
+ id=peer_id
58
+ )
59
+ ))
60
+
61
+ chat_id = await self.resolve_peer_id(chat_id)
62
+ params = {"chat_id": chat_id, "photo": photo}
63
+ if caption is not None:
64
+ params["caption"] = caption
65
+ if filename is not None:
66
+ params["filename"] = filename
67
+ return await self.auto_execute("sendPhoto", params)
@@ -0,0 +1,51 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ import PySPlusthon
4
+ from ...objects import InputMedia, resolve_media, Message, ReplyMarkup
5
+
6
+
7
+ class SendSticker:
8
+
9
+ async def send_sticker(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ sticker: Union[str, bytes, BinaryIO, InputMedia],
13
+ reply_markup: ReplyMarkup = None,
14
+ reply_to_message_id: int = None
15
+ ) -> Message:
16
+ if self.is_userbot():
17
+ from ...proto import requests, structs
18
+ peer_id, peer_type = map(int, chat_id.split("|"))
19
+ file_id, access_hash, file_storage_version, sticker_id, collection_id = map(int, sticker.split(":"))
20
+ return await self.execute(requests.SendMessage(
21
+ peer=structs.Peer(
22
+ type=peer_type,
23
+ id=peer_id
24
+ ),
25
+ rid=self.ws_connection.create_rid(),
26
+ message=structs.Message(
27
+ sticker_message=structs.StickerMessage(
28
+ sticker_id=structs.Int32Value(
29
+ value=sticker_id,
30
+ ),
31
+ image512=structs.ImageLocation(
32
+ file_location=structs.FileLocation(
33
+ file_id=file_id,
34
+ access_hash=access_hash,
35
+ file_storage_version=structs.Int32Value(value=file_storage_version)
36
+ )
37
+ ),
38
+ sticker_collection_id=structs.Int32Value(
39
+ value=collection_id
40
+ )
41
+ ),
42
+ ),
43
+ ex_peer=structs.Peer(
44
+ type=peer_type,
45
+ id=peer_id
46
+ )
47
+ ))
48
+
49
+ chat_id = await self.resolve_peer_id(chat_id)
50
+ sticker = resolve_media(sticker)
51
+ return await self.auto_execute("sendSticker", locals())
@@ -0,0 +1,56 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ import PySPlusthon
4
+ from ...objects import InputMedia, resolve_media, Message, ReplyMarkup
5
+
6
+
7
+ class SendVideo:
8
+
9
+ async def send_video(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ video: Union[str, bytes, BinaryIO, InputMedia],
13
+ duration: int = None,
14
+ width: int = None,
15
+ height: int = None,
16
+ caption: str = None,
17
+ reply_markup: ReplyMarkup = None,
18
+ reply_to_message_id: int = None
19
+ ) -> Message:
20
+ video = resolve_media(video)
21
+
22
+ if self.is_userbot():
23
+ from ...proto import requests, structs, enums
24
+ peer_id, peer_type = map(int, chat_id.split("|"))
25
+ file = await self.upload_file(chat_id, video, enums.SEND_TYPE_VIDEO)
26
+ return await self.execute(requests.SendMessage(
27
+ peer=structs.Peer(
28
+ type=peer_type,
29
+ id=peer_id
30
+ ),
31
+ rid=self.ws_connection.create_rid(),
32
+ message=structs.Message(
33
+ document_message=structs.DocumentMessage(
34
+ file_id=file.id,
35
+ access_hash=peer_id,
36
+ file_size=file.size,
37
+ name=file.name,
38
+ mime_type=file.mime_type,
39
+ ext=structs.DocumentEx(
40
+ document_ex_video=structs.DocumentExVideo(
41
+ w=100,
42
+ h=100,
43
+ duration=10
44
+ )
45
+ ),
46
+ caption=structs.TextMessage(text=caption)
47
+ )
48
+ ),
49
+ ex_peer=structs.Peer(
50
+ type=peer_type,
51
+ id=peer_id
52
+ )
53
+ ))
54
+
55
+ chat_id = await self.resolve_peer_id(chat_id)
56
+ return await self.auto_execute("sendVideo", locals())
@@ -0,0 +1,52 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ import PySPlusthon
4
+ from ...objects import InputMedia, resolve_media, Message, ReplyMarkup
5
+
6
+
7
+ class SendVoice:
8
+
9
+ async def send_voice(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ voice: Union[str, bytes, BinaryIO, InputMedia],
13
+ caption: str = None,
14
+ duration: int = None,
15
+ reply_markup: ReplyMarkup = None,
16
+ reply_to_message_id: int = None
17
+ ) -> Message:
18
+ voice = resolve_media(voice)
19
+
20
+ if self.is_userbot():
21
+ from ...proto import requests, structs, enums
22
+ peer_id, peer_type = map(int, chat_id.split("|"))
23
+ file = await self.upload_file(chat_id, voice, enums.SEND_TYPE_VOICE)
24
+ return await self.execute(requests.SendMessage(
25
+ peer=structs.Peer(
26
+ type=peer_type,
27
+ id=peer_id
28
+ ),
29
+ rid=self.ws_connection.create_rid(),
30
+ message=structs.Message(
31
+ document_message=structs.DocumentMessage(
32
+ file_id=file.id,
33
+ access_hash=peer_id,
34
+ file_size=file.size,
35
+ name=file.name,
36
+ mime_type=file.mime_type,
37
+ ext=structs.DocumentEx(
38
+ document_ex_voice=structs.DocumentExVoice(
39
+ duration=duration
40
+ )
41
+ ),
42
+ caption=structs.TextMessage(text=caption)
43
+ )
44
+ ),
45
+ ex_peer=structs.Peer(
46
+ type=peer_type,
47
+ id=peer_id
48
+ )
49
+ ))
50
+
51
+ chat_id = await self.resolve_peer_id(chat_id)
52
+ return await self.auto_execute("sendVoice", locals())