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.
Files changed (284) 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 +223 -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 +39 -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 +43 -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/date.py +35 -0
  160. PySPlusthon/objects/document.py +36 -0
  161. PySPlusthon/objects/edited_message.py +27 -0
  162. PySPlusthon/objects/entity.py +21 -0
  163. PySPlusthon/objects/file.py +21 -0
  164. PySPlusthon/objects/forward_origin.py +22 -0
  165. PySPlusthon/objects/inline_keyboard.py +65 -0
  166. PySPlusthon/objects/inline_keyboard_button.py +30 -0
  167. PySPlusthon/objects/input_media.py +44 -0
  168. PySPlusthon/objects/input_media_photo.py +14 -0
  169. PySPlusthon/objects/input_media_video.py +14 -0
  170. PySPlusthon/objects/invite_link.py +32 -0
  171. PySPlusthon/objects/list.py +24 -0
  172. PySPlusthon/objects/location.py +14 -0
  173. PySPlusthon/objects/message.py +478 -0
  174. PySPlusthon/objects/message_id.py +31 -0
  175. PySPlusthon/objects/object.py +154 -0
  176. PySPlusthon/objects/order_info.py +19 -0
  177. PySPlusthon/objects/photo.py +31 -0
  178. PySPlusthon/objects/poll.py +34 -0
  179. PySPlusthon/objects/poll_option.py +16 -0
  180. PySPlusthon/objects/reply_keyboard.py +79 -0
  181. PySPlusthon/objects/reply_keyboard_button.py +27 -0
  182. PySPlusthon/objects/reply_keyboard_remove.py +10 -0
  183. PySPlusthon/objects/reply_markup.py +12 -0
  184. PySPlusthon/objects/shipping_address.py +22 -0
  185. PySPlusthon/objects/shipping_query.py +20 -0
  186. PySPlusthon/objects/sticker.py +54 -0
  187. PySPlusthon/objects/sticker_set.py +29 -0
  188. PySPlusthon/objects/transaction.py +25 -0
  189. PySPlusthon/objects/update.py +33 -0
  190. PySPlusthon/objects/user.py +60 -0
  191. PySPlusthon/objects/video.py +45 -0
  192. PySPlusthon/objects/voice.py +31 -0
  193. PySPlusthon/objects/webhook_info.py +16 -0
  194. PySPlusthon/proto/__init__.py +2 -0
  195. PySPlusthon/proto/enums_pb2.py +46 -0
  196. PySPlusthon/proto/enums_pb2.pyi +99 -0
  197. PySPlusthon/proto/enums_pb2_grpc.py +24 -0
  198. PySPlusthon/proto/requests/__init__.py +209 -0
  199. PySPlusthon/proto/requests/abacus_pb2.py +40 -0
  200. PySPlusthon/proto/requests/abacus_pb2.pyi +31 -0
  201. PySPlusthon/proto/requests/abacus_pb2_grpc.py +24 -0
  202. PySPlusthon/proto/requests/auth_pb2.py +49 -0
  203. PySPlusthon/proto/requests/auth_pb2.pyi +67 -0
  204. PySPlusthon/proto/requests/auth_pb2_grpc.py +24 -0
  205. PySPlusthon/proto/requests/configs_pb2.py +37 -0
  206. PySPlusthon/proto/requests/configs_pb2.pyi +15 -0
  207. PySPlusthon/proto/requests/configs_pb2_grpc.py +24 -0
  208. PySPlusthon/proto/requests/files_pb2.py +40 -0
  209. PySPlusthon/proto/requests/files_pb2.pyi +34 -0
  210. PySPlusthon/proto/requests/files_pb2_grpc.py +24 -0
  211. PySPlusthon/proto/requests/groups_pb2.py +82 -0
  212. PySPlusthon/proto/requests/groups_pb2.pyi +213 -0
  213. PySPlusthon/proto/requests/groups_pb2_grpc.py +24 -0
  214. PySPlusthon/proto/requests/messaging_pb2.py +56 -0
  215. PySPlusthon/proto/requests/messaging_pb2.pyi +119 -0
  216. PySPlusthon/proto/requests/messaging_pb2_grpc.py +24 -0
  217. PySPlusthon/proto/requests/presence_pb2.py +40 -0
  218. PySPlusthon/proto/requests/presence_pb2.pyi +24 -0
  219. PySPlusthon/proto/requests/presence_pb2_grpc.py +24 -0
  220. PySPlusthon/proto/requests/request_pb2.py +42 -0
  221. PySPlusthon/proto/requests/request_pb2.pyi +35 -0
  222. PySPlusthon/proto/requests/request_pb2_grpc.py +24 -0
  223. PySPlusthon/proto/requests/users_pb2.py +43 -0
  224. PySPlusthon/proto/requests/users_pb2.pyi +34 -0
  225. PySPlusthon/proto/requests/users_pb2_grpc.py +24 -0
  226. PySPlusthon/proto/responses/__init__.py +6 -0
  227. PySPlusthon/proto/responses/abacus_pb2.py +37 -0
  228. PySPlusthon/proto/responses/abacus_pb2.pyi +14 -0
  229. PySPlusthon/proto/responses/abacus_pb2_grpc.py +24 -0
  230. PySPlusthon/proto/responses/auth_pb2.py +42 -0
  231. PySPlusthon/proto/responses/auth_pb2.pyi +40 -0
  232. PySPlusthon/proto/responses/auth_pb2_grpc.py +24 -0
  233. PySPlusthon/proto/responses/files_pb2.py +39 -0
  234. PySPlusthon/proto/responses/files_pb2.pyi +27 -0
  235. PySPlusthon/proto/responses/files_pb2_grpc.py +24 -0
  236. PySPlusthon/proto/responses/groups_pb2.py +59 -0
  237. PySPlusthon/proto/responses/groups_pb2.pyi +90 -0
  238. PySPlusthon/proto/responses/groups_pb2_grpc.py +24 -0
  239. PySPlusthon/proto/responses/messaging_pb2.py +44 -0
  240. PySPlusthon/proto/responses/messaging_pb2.pyi +37 -0
  241. PySPlusthon/proto/responses/messaging_pb2_grpc.py +24 -0
  242. PySPlusthon/proto/responses/users_pb2.py +41 -0
  243. PySPlusthon/proto/responses/users_pb2.pyi +28 -0
  244. PySPlusthon/proto/responses/users_pb2_grpc.py +24 -0
  245. PySPlusthon/proto/structs/__init__.py +7 -0
  246. PySPlusthon/proto/structs/collections_pb2.py +54 -0
  247. PySPlusthon/proto/structs/collections_pb2.pyi +79 -0
  248. PySPlusthon/proto/structs/collections_pb2_grpc.py +24 -0
  249. PySPlusthon/proto/structs/files_pb2.py +52 -0
  250. PySPlusthon/proto/structs/files_pb2.pyi +93 -0
  251. PySPlusthon/proto/structs/files_pb2_grpc.py +24 -0
  252. PySPlusthon/proto/structs/groups_pb2.py +49 -0
  253. PySPlusthon/proto/structs/groups_pb2.pyi +144 -0
  254. PySPlusthon/proto/structs/groups_pb2_grpc.py +24 -0
  255. PySPlusthon/proto/structs/messaging_pb2.py +81 -0
  256. PySPlusthon/proto/structs/messaging_pb2.pyi +296 -0
  257. PySPlusthon/proto/structs/messaging_pb2_grpc.py +24 -0
  258. PySPlusthon/proto/structs/peers_pb2.py +47 -0
  259. PySPlusthon/proto/structs/peers_pb2.pyi +56 -0
  260. PySPlusthon/proto/structs/peers_pb2_grpc.py +24 -0
  261. PySPlusthon/proto/structs/set_updates_pb2.py +37 -0
  262. PySPlusthon/proto/structs/set_updates_pb2.pyi +15 -0
  263. PySPlusthon/proto/structs/set_updates_pb2_grpc.py +24 -0
  264. PySPlusthon/proto/structs/users_pb2.py +54 -0
  265. PySPlusthon/proto/structs/users_pb2.pyi +122 -0
  266. PySPlusthon/proto/structs/users_pb2_grpc.py +24 -0
  267. PySPlusthon/proto/updates/__init__.py +1 -0
  268. PySPlusthon/proto/updates/messaging_pb2.py +38 -0
  269. PySPlusthon/proto/updates/messaging_pb2.pyi +26 -0
  270. PySPlusthon/proto/updates/messaging_pb2_grpc.py +24 -0
  271. PySPlusthon/proto/ws_pb2.py +52 -0
  272. PySPlusthon/proto/ws_pb2.pyi +76 -0
  273. PySPlusthon/proto/ws_pb2_grpc.py +24 -0
  274. PySPlusthon/smart_call.py +73 -0
  275. PySPlusthon/states/__init__.py +3 -0
  276. PySPlusthon/states/state.py +11 -0
  277. PySPlusthon/states/state_group.py +13 -0
  278. PySPlusthon/states/state_machine.py +83 -0
  279. PySPlusthon/sync_support.py +48 -0
  280. pysplusthon-0.5.3.dist-info/METADATA +65 -0
  281. pysplusthon-0.5.3.dist-info/RECORD +284 -0
  282. pysplusthon-0.5.3.dist-info/WHEEL +5 -0
  283. pysplusthon-0.5.3.dist-info/licenses/LICENSE +19 -0
  284. pysplusthon-0.5.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,82 @@
1
+ from typing import Union, BinaryIO
2
+ from io import BufferedIOBase, BytesIO, RawIOBase
3
+ import mimetypes
4
+ import os
5
+
6
+ import PySPlusthon
7
+ from ...objects import File
8
+ try:
9
+ from PySPlusthon.proto import requests, structs, enums
10
+ except ImportError:
11
+ pass
12
+
13
+
14
+ class UploadFile:
15
+
16
+ async def upload_file(
17
+ self: "PySPlusthon.Client",
18
+ chat_id: str,
19
+ file: Union[bytes, BinaryIO],
20
+ send_type: "enums.SendType",
21
+ expected_size: int = None,
22
+ name: str = None,
23
+ mime_type: str = None,
24
+ ) -> File:
25
+ peer_id, peer_type = map(int, chat_id.split("|"))
26
+
27
+ is_file_like = isinstance(file, (BufferedIOBase, BytesIO, RawIOBase))
28
+
29
+ if not expected_size:
30
+ if isinstance(file, bytes):
31
+ expected_size = len(file)
32
+ elif is_file_like:
33
+ current = file.tell()
34
+ file.seek(0, 2)
35
+ expected_size = file.tell()
36
+ file.seek(current)
37
+
38
+ if not name:
39
+ if is_file_like:
40
+ raw_name = getattr(file, "name", None)
41
+ name = os.path.basename(raw_name) if raw_name else "upload"
42
+ else:
43
+ name = "upload"
44
+
45
+ send_type_map = {
46
+ enums.SEND_TYPE_PHOTO: "image",
47
+ enums.SEND_TYPE_VIDEO: "video",
48
+ enums.SEND_TYPE_GIF: "video",
49
+ enums.SEND_TYPE_AUDIO: "audio",
50
+ enums.SEND_TYPE_VOICE: "audio",
51
+ enums.SEND_TYPE_DOCUMENT: "document",
52
+ }
53
+ file_type = send_type_map.get(send_type, "application")
54
+
55
+ if not mime_type:
56
+ if name != "upload":
57
+ mime_type = mimetypes.guess_type(name)[0]
58
+
59
+ if not mime_type:
60
+ mime_type = f"{file_type}/octet-stream"
61
+
62
+ if is_file_like:
63
+ file.seek(0)
64
+ file = file.read()
65
+
66
+ result = await self.execute(requests.GetNasimFileUploadUrl(
67
+ expected_size=expected_size,
68
+ crc=0,
69
+ uid=peer_id,
70
+ name=name,
71
+ mime_type=mime_type,
72
+ ex_peer=structs.ExPeer(
73
+ type=peer_type,
74
+ id=peer_id,
75
+ access_hash=0
76
+ ),
77
+ send_type=structs.SendTypeValue(
78
+ type=send_type
79
+ )
80
+ ))
81
+ await self.http2_connection.upload_file(result.url, file, result.chunk_size)
82
+ return File(id=result.file_id, size=expected_size, name=name, mime_type=mime_type)
@@ -0,0 +1,43 @@
1
+ from .ban_chat_member import BanChatMember
2
+ from .delete_chat_photo import DeleteChatPhoto
3
+ from .get_chat import GetChat
4
+ from .get_chat_administrators import GetChatAdministrators
5
+ from .get_chat_history import GetChatHistory
6
+ from .get_chat_members_count import GetChatMembersCount
7
+ from .get_chat_member import GetChatMember
8
+ from .get_chat_members import GetChatMembers
9
+ from .join_chat import JoinChat
10
+ from .leave_chat import LeaveChat
11
+ from .pin_chat_message import PinChatMessage
12
+ from .promote_chat_member import PromoteChatMember
13
+ from .restrict_chat_member import RestrictChatMember
14
+ from .set_chat_description import SetChatDescription
15
+ from .set_chat_photo import SetChatPhoto
16
+ from .set_chat_title import SetChatTitle
17
+ from .unban_chat_member import UnbanChatMember
18
+ from .unpin_all_chat_messages import UnpinAllChatMessages
19
+ from .unpin_chat_message import UnpinChatMessage
20
+
21
+
22
+ class Chats(
23
+ BanChatMember,
24
+ DeleteChatPhoto,
25
+ GetChat,
26
+ GetChatAdministrators,
27
+ GetChatHistory,
28
+ GetChatMembersCount,
29
+ GetChatMember,
30
+ GetChatMembers,
31
+ JoinChat,
32
+ LeaveChat,
33
+ PinChatMessage,
34
+ PromoteChatMember,
35
+ RestrictChatMember,
36
+ SetChatDescription,
37
+ SetChatTitle,
38
+ SetChatPhoto,
39
+ UnbanChatMember,
40
+ UnpinAllChatMessages,
41
+ UnpinChatMessage
42
+ ):
43
+ pass
@@ -0,0 +1,24 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+
6
+ class BanChatMember:
7
+
8
+ async def ban_chat_member(
9
+ self: "PySPlusthon.Client",
10
+ chat_id: Union[int, str],
11
+ user_id: Union[int, str]
12
+ ) -> bool:
13
+ if self.is_userbot():
14
+ from PySPlusthon.proto import requests, structs
15
+ peer_id, peer_type = map(int, chat_id.split("|"))
16
+ return await self.execute(requests.KickUser(
17
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
18
+ user=structs.UserOutPeer(uid=user_id, access_hash=1),
19
+ rid=self.ws_connection.create_rid()
20
+ ))
21
+
22
+ chat_id = await self.resolve_peer_id(chat_id)
23
+ user_id = await self.resolve_peer_id(user_id)
24
+ return await self.auto_execute("banChatMember", locals())
@@ -0,0 +1,32 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+
6
+ class DeleteChatPhoto:
7
+
8
+ async def delete_chat_photo(
9
+ self: "PySPlusthon.Client",
10
+ chat_id: Union[int, str]
11
+ ) -> bool:
12
+ if self.is_userbot():
13
+ from PySPlusthon.proto import requests, structs
14
+ peer_id, peer_type = map(int, chat_id.split("|"))
15
+
16
+ response = await self.execute(requests.LoadGroupAvatars(
17
+ peer=structs.GroupOutPeer(group_id=peer_id)
18
+ ))
19
+
20
+ avatars = response.avatars.avatars
21
+ if not avatars:
22
+ return
23
+ last_avatar = avatars[0]
24
+
25
+ return await self.execute(requests.RemoveGroupAvatar(
26
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
27
+ rid=self.ws_connection.create_rid(),
28
+ avatar_id=last_avatar.id
29
+ ))
30
+
31
+ chat_id = await self.resolve_peer_id(chat_id)
32
+ return await self.auto_execute("deleteChatPhoto", locals())
@@ -0,0 +1,69 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+ from ...objects import Chat
5
+
6
+
7
+ class GetChat:
8
+
9
+ async def get_chat(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str]
12
+ ) -> Chat:
13
+ if self.is_userbot():
14
+ from ...proto import requests, structs
15
+ peer_id, peer_type = chat_id.split("|")
16
+
17
+ if not peer_id.isnumeric():
18
+ # "@username"
19
+ if peer_id.startswith("@"):
20
+ peer_id = peer_id[1:]
21
+
22
+ # "+9*********" | "+09*********" | "+989*********"
23
+ elif peer_id.startswith("+"):
24
+ peer_id = peer_id[1:]
25
+
26
+ # "https://ble.ir/join/ABCDEEFGHI" | "https://ble.ir/username"
27
+ elif peer_id.startswith("https://ble.ir/"):
28
+ peer_id = peer_id[15:]
29
+
30
+ # "ble.ir/join/ABCDEEFGHI" | "ble.ir/username"
31
+ elif peer_id.startswith("ble.ir/"):
32
+ peer_id = peer_id[7:]
33
+
34
+ response = await self.execute(requests.SearchContacts(
35
+ request=peer_id
36
+ ))
37
+
38
+ if response.user_peers:
39
+ result = response.user_peers[0]
40
+ peer_id = result.uid
41
+
42
+ elif response.group_peers:
43
+ result = response.group_peers[0]
44
+ peer_id = result.group_id
45
+
46
+ else:
47
+ return
48
+
49
+ peer_id, peer_type = map(int, (peer_id, peer_type))
50
+
51
+ if peer_type in (1, 4):
52
+ users = await self.execute(requests.LoadUsers(
53
+ user_peers=[structs.UserOutPeer(
54
+ uid=peer_id,
55
+ access_hash=1
56
+ )]
57
+ ))
58
+ return users.users[0]
59
+
60
+ if peer_type in (2, 3, 5):
61
+ return await self.execute(requests.GetFullGroup(
62
+ peer=structs.GroupOutPeer(
63
+ group_id=peer_id,
64
+ access_hash=1
65
+ )
66
+ ))
67
+
68
+ else:
69
+ return await self.auto_execute("getChat", locals())
@@ -0,0 +1,18 @@
1
+ from typing import Union, List
2
+
3
+ import PySPlusthon
4
+ from ...objects import ChatMember
5
+
6
+
7
+ class GetChatAdministrators:
8
+
9
+ async def get_chat_administrators(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str]
12
+ ) -> List[ChatMember]:
13
+ if self.is_userbot():
14
+ result = await self.get_chat_members(chat_id)
15
+ return [member for member in result.members if member.is_admin.value]
16
+
17
+ chat_id = await self.resolve_peer_id(chat_id)
18
+ return await self.auto_execute("getChatAdministrators", locals())
@@ -0,0 +1,39 @@
1
+ from typing import Union, List
2
+ from datetime import datetime
3
+
4
+ import PySPlusthon
5
+ from ...objects import Message, List as PySplusthonList
6
+ try:
7
+ from PySPlusthon.proto import requests, structs, updates
8
+ except ImportError:
9
+ pass
10
+
11
+
12
+ class GetChatHistory:
13
+
14
+ async def get_chat_history(
15
+ self: "PySPlusthon.Client",
16
+ chat_id: Union[int, str],
17
+ date: Union[datetime, int] = -1,
18
+ limit: int = 40
19
+ ) -> List[Message]:
20
+ peer_id, peer_type = map(int, chat_id.split("|"))
21
+ if isinstance(date, datetime):
22
+ date = date.timestamp() * 1000
23
+ peer = structs.Peer(type=peer_type, id=peer_id)
24
+ response = await self.execute(requests.LoadHistory(
25
+ peer=peer,
26
+ date=date,
27
+ load_mode=2,
28
+ limit=limit
29
+ ))
30
+ history = PySplusthonList()
31
+ for message_container in response.history:
32
+ message_container_fields = [field.name for field in message_container.DESCRIPTOR.fields]
33
+ message_fields = [field.name for field in updates.Message.DESCRIPTOR.fields]
34
+ fields = [field for field in message_container_fields if field in message_fields]
35
+ data = {field: getattr(message_container, field) for field in fields}
36
+ update_message = updates.Message(peer=peer, **data)
37
+ message = Message.from_protobuf(update_message)
38
+ history.append(message)
39
+ return history
@@ -0,0 +1,16 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+ from ...objects import ChatMember
5
+
6
+
7
+ class GetChatMember:
8
+
9
+ async def get_chat_member(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ user_id: Union[int, str]
13
+ ) -> ChatMember:
14
+ chat_id = await self.resolve_peer_id(chat_id)
15
+ user_id = await self.resolve_peer_id(user_id)
16
+ return await self.auto_execute("getChatMember", locals())
@@ -0,0 +1,29 @@
1
+ import PySPlusthon
2
+ try:
3
+ from PySPlusthon.proto import requests, structs, responses
4
+ except ImportError:
5
+ pass
6
+
7
+
8
+ class GetChatMembers:
9
+
10
+ async def get_chat_members(
11
+ self: "PySPlusthon.Client",
12
+ chat_id: str,
13
+ limit: int = 200,
14
+ next: bytes = None,
15
+ excepted_permissions: bool = False,
16
+ contacts: bool = False,
17
+ query: str = None
18
+ ) -> "responses.LoadMembers":
19
+ peer_id, peer_type = map(int, chat_id.split("|"))
20
+ return await self.execute(requests.LoadMembers(
21
+ group=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
22
+ limit=limit,
23
+ next=next,
24
+ condition=structs.LoadMembersCondition(
25
+ excepted_permissions=excepted_permissions,
26
+ contacts=contacts,
27
+ query=query
28
+ )
29
+ ))
@@ -0,0 +1,21 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+
6
+ class GetChatMembersCount:
7
+
8
+ async def get_chat_members_count(
9
+ self: "PySPlusthon.Client",
10
+ chat_id: Union[int, str]
11
+ ) -> int:
12
+ if self.is_userbot():
13
+ from PySPlusthon.proto import requests, structs
14
+ peer_id, peer_type = map(int, chat_id.split("|"))
15
+ response = await self.execute(requests.GetGroupMembersCount(
16
+ group=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
17
+ ))
18
+ return response.members_count
19
+
20
+ chat_id = await self.resolve_peer_id(chat_id)
21
+ return await self.auto_execute("getChatMembersCount", locals())
@@ -0,0 +1,31 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+ try:
5
+ from ...proto import requests, structs, responses
6
+ except ImportError:
7
+ pass
8
+
9
+
10
+ class JoinChat:
11
+ async def join_chat(
12
+ self: "PySPlusthon.Client",
13
+ chat_id: str
14
+ ) -> Union["responses.JoinGroup", "responses.JoinPublicGroup"]:
15
+ peer_id, peer_type = chat_id.split("|")
16
+
17
+ # 1234567890 | "1234567890"
18
+ if isinstance(peer_id, int) or (isinstance(peer_id, str) and peer_id.isnumeric()):
19
+ return await self.execute(requests.JoinPublicGroup(
20
+ peer=structs.Peer(
21
+ type=int(peer_type),
22
+ id=int(peer_id)
23
+ )
24
+ ))
25
+
26
+ # "https://ble.ir/join/ABCDEEFGHI" | "ble.ir/join/ABCDEEFGHI"
27
+ token = peer_id.replace("https://", "").replace("ble.ir/join/", "")
28
+
29
+ return await self.execute(requests.JoinGroup(
30
+ token=token
31
+ ))
@@ -0,0 +1,22 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+
6
+ class LeaveChat:
7
+
8
+ async def leave_chat(
9
+ self: "PySPlusthon.Client",
10
+ chat_id: Union[int, str]
11
+ ) -> bool:
12
+ if self.is_userbot():
13
+ from PySPlusthon.proto import requests, structs
14
+ peer_id, peer_type = map(int, chat_id.split("|"))
15
+ return await self.execute(requests.LeaveGroup(
16
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
17
+ rid=self.ws_connection.create_rid(),
18
+ make_orphan=False
19
+ ))
20
+
21
+ chat_id = await self.resolve_peer_id(chat_id)
22
+ return await self.auto_execute("leaveChat", locals())
@@ -0,0 +1,31 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+ from ...objects import resolve_message_id
5
+
6
+
7
+ class PinChatMessage:
8
+
9
+ async def pin_chat_message(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ message_id: Union[int, str]
13
+ ) -> bool:
14
+ if self.is_userbot():
15
+ from PySPlusthon.proto import requests, structs
16
+ peer_id, peer_type = map(int, chat_id.split("|"))
17
+ message_id = resolve_message_id(message_id)
18
+ if peer_type in (1, 4):
19
+ return await self.execute(requests.PinMessages(
20
+ peer=structs.Peer(type=peer_type, id=peer_id),
21
+ message_id=structs.MessageId(date=message_id.date, rid=message_id.rid)
22
+ ))
23
+ elif peer_type in (2 ,3 ,5):
24
+ return await self.execute(requests.PinMessage(
25
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
26
+ date=message_id.date,
27
+ msg_rid=message_id.rid
28
+ ))
29
+
30
+ chat_id = await self.resolve_peer_id(chat_id)
31
+ return await self.auto_execute("pinChatMessage", locals())
@@ -0,0 +1,64 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+ class PromoteChatMember:
6
+
7
+ async def promote_chat_member(
8
+ self: "PySPlusthon.Client",
9
+ chat_id: Union[int, str],
10
+ user_id: Union[int, str],
11
+ can_edit_messages: bool = None,
12
+ can_delete_messages: bool = None,
13
+ can_manage_video_chats: bool = None,
14
+ can_restrict_members: bool = None,
15
+ can_promote_members: bool = None,
16
+ can_change_info: bool = None,
17
+ can_invite_users: bool = None,
18
+ can_pin_messages: bool = None,
19
+ can_send_messages: bool = None,
20
+ can_send_media_messages: bool = None,
21
+ can_send_media: bool = None,
22
+ can_send_gif_stickers: bool = None,
23
+ can_reply_to_story: bool = None,
24
+ can_forward_message_from: bool = None,
25
+ can_send_gift_packet: bool = None,
26
+ can_start_call: bool = None,
27
+ can_send_link_message: bool = None,
28
+ can_send_forwarded_message: bool = None,
29
+ can_kick_user: bool = None,
30
+ can_send_message: bool = None,
31
+ can_see_members: bool = None,
32
+ can_add_story: bool = None
33
+ ) -> bool:
34
+ if self.is_userbot():
35
+ from PySPlusthon.proto import requests, structs
36
+ peer_id, peer_type = map(int, chat_id.split("|"))
37
+ return await self.execute(requests.SetMemberPermissions(
38
+ group=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
39
+ user=structs.UserOutPeer(uid=user_id, access_hash=1),
40
+ permissions=structs.Permissions(
41
+ edit_message=can_edit_messages,
42
+ delete_message=can_delete_messages,
43
+ manage_call=can_manage_video_chats,
44
+ change_info=can_change_info,
45
+ invite_user=can_invite_users,
46
+ pin_message=can_pin_messages,
47
+ send_media=can_send_media,
48
+ send_gif_stickers=can_send_gif_stickers,
49
+ reply_to_story=can_reply_to_story,
50
+ forward_message_from=can_forward_message_from,
51
+ send_gift_packet=can_send_gift_packet,
52
+ start_call=can_start_call,
53
+ send_link_message=can_send_link_message,
54
+ send_forwarded_message=can_send_forwarded_message,
55
+ kick_user=can_kick_user,
56
+ send_message=can_send_message,
57
+ see_members=can_see_members,
58
+ add_story=can_add_story
59
+ )
60
+ ))
61
+
62
+ chat_id = await self.resolve_peer_id(chat_id)
63
+ user_id = await self.resolve_peer_id(user_id)
64
+ return await self.auto_execute("promoteChatMember", locals())
@@ -0,0 +1,25 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+ from PySPlusthon import objects
5
+
6
+
7
+ class RestrictChatMember:
8
+
9
+ async def restrict_chat_member(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ user_id: Union[int, str],
13
+ permissions: "objects.ChatPermissions"
14
+ ) -> bool:
15
+ if self.is_userbot():
16
+ from ...proto import requests, structs
17
+ peer_id, peer_type = map(int, chat_id.split("|"))
18
+ return await self.execute(requests.RemoveUserAdmin(
19
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
20
+ user_peer=structs.UserOutPeer(uid=user_id, access_hash=1),
21
+ ))
22
+
23
+ chat_id = await self.resolve_peer_id(chat_id)
24
+ user_id = await self.resolve_peer_id(user_id)
25
+ return await self.auto_execute("restrictChatMember", locals())
@@ -0,0 +1,23 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+
6
+ class SetChatDescription:
7
+
8
+ async def set_chat_description(
9
+ self: "PySPlusthon.Client",
10
+ chat_id: Union[int, str],
11
+ description: str
12
+ ) -> bool:
13
+ if self.is_userbot():
14
+ from PySPlusthon.proto import requests, structs
15
+ peer_id, peer_type = map(int, chat_id.split("|"))
16
+ return await self.execute(requests.EditGroupAbout(
17
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
18
+ rid=self.ws_connection.create_rid(),
19
+ about=description
20
+ ))
21
+
22
+ chat_id = await self.resolve_peer_id(chat_id)
23
+ return await self.auto_execute("setChatDescription", locals())
@@ -0,0 +1,33 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ import PySPlusthon
4
+ from ...objects import InputMedia, resolve_media
5
+
6
+
7
+ class SetChatPhoto:
8
+
9
+ async def set_chat_photo(
10
+ self: "PySPlusthon.Client",
11
+ chat_id: Union[int, str],
12
+ photo: Union[str, bytes, BinaryIO, InputMedia]
13
+ ) -> bool:
14
+ photo = resolve_media(photo)
15
+
16
+ if self.is_userbot():
17
+ from ...proto import requests, structs, enums
18
+ peer_id, peer_type = map(int, chat_id.split("|"))
19
+ file = await self.upload_file(f"{self.user.id}|1", photo, enums.SEND_TYPE_PHOTO)
20
+ return await self.execute(requests.EditGroupAvatar(
21
+ group_peer=structs.GroupOutPeer(
22
+ group_id=peer_id,
23
+ access_hash=1
24
+ ),
25
+ file_location=structs.FileLocation(
26
+ file_id=file.id,
27
+ access_hash=self.user.id
28
+ ),
29
+ rid=self.ws_connection.create_rid()
30
+ ))
31
+
32
+ chat_id = await self.resolve_peer_id(chat_id)
33
+ return await self.auto_execute("setChatPhoto", locals())
@@ -0,0 +1,23 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+
6
+ class SetChatTitle:
7
+
8
+ async def set_chat_title(
9
+ self: "PySPlusthon.Client",
10
+ chat_id: Union[int, str],
11
+ title: str
12
+ ) -> bool:
13
+ if self.is_userbot():
14
+ from PySPlusthon.proto import requests, structs
15
+ peer_id, peer_type = map(int, chat_id.split("|"))
16
+ return await self.execute(requests.EditGroupTitle(
17
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
18
+ title=title,
19
+ rid=self.ws_connection.create_rid()
20
+ ))
21
+
22
+ chat_id = await self.resolve_peer_id(chat_id)
23
+ return await self.auto_execute("setChatTitle", locals())
@@ -0,0 +1,24 @@
1
+ from typing import Union
2
+
3
+ import PySPlusthon
4
+
5
+
6
+ class UnbanChatMember:
7
+
8
+ async def unban_chat_member(
9
+ self: "PySPlusthon.Client",
10
+ chat_id: Union[int, str],
11
+ user_id: Union[int, str],
12
+ only_if_banned: bool = True
13
+ ) -> bool:
14
+ if self.is_userbot():
15
+ from PySPlusthon.proto import requests, structs
16
+ peer_id, peer_type = map(int, chat_id.split("|"))
17
+ return await self.execute(requests.UnBanUser(
18
+ group_peer=structs.GroupOutPeer(group_id=peer_id, access_hash=1),
19
+ user=structs.UserOutPeer(uid=user_id, access_hash=1)
20
+ ))
21
+
22
+ chat_id = await self.resolve_peer_id(chat_id)
23
+ user_id = await self.resolve_peer_id(user_id)
24
+ return await self.auto_execute("unbanChatMember", locals())