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,118 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ from PySPlusthon import enums, objects
4
+ from . import Object
5
+ from ..sync_support import add_sync_support_to_object
6
+
7
+
8
+ @add_sync_support_to_object
9
+ class Chat(Object):
10
+
11
+ @classmethod
12
+ def from_protobuf(cls, protobuf_data):
13
+ return cls(
14
+ id=f"{protobuf_data.id}|{protobuf_data.type}"
15
+ )
16
+
17
+ def __init__(
18
+ self,
19
+ id: int = None,
20
+ type: "enums.ChatType" = None,
21
+ title: str = None,
22
+ username: str = None,
23
+ first_name: str = None,
24
+ last_name: str = None,
25
+ all_members_are_administrators: bool = None,
26
+ bio: str = None,
27
+ description: str = None,
28
+ invite_link: str = None,
29
+ linked_chat_id: int = None,
30
+ pinned_message: "objects.Message" = None,
31
+ sticker_set_name: str = None,
32
+ can_set_sticker_set: bool = None,
33
+ photo: "objects.ChatPhoto" = None,
34
+ **kwargs
35
+ ):
36
+ super().__init__(**kwargs)
37
+ self.id: int = id
38
+ self.type: "enums.ChatType" = type
39
+ self.title: str = title
40
+ self.username: str = username
41
+ self.first_name: str = first_name
42
+ self.last_name: str = last_name
43
+ self.all_members_are_administrators: bool = all_members_are_administrators
44
+ self.bio: str = bio
45
+ self.description: str = description
46
+ self.invite_link: str = invite_link
47
+ self.linked_chat_id: int = linked_chat_id
48
+ self.pinned_message: "objects.Message" = pinned_message
49
+ self.sticker_set_name: str = sticker_set_name
50
+ self.can_set_sticker_set: bool = can_set_sticker_set
51
+ self.photo: "objects.ChatPhoto" = photo
52
+
53
+ def __eq__(self, other):
54
+ return self.id == other.id
55
+
56
+ def mention(self, text=None):
57
+ text = text or self.full_name
58
+ return f"[{text}](uid:{self.id})"
59
+
60
+ @property
61
+ def link(self):
62
+ if self.invite_link:
63
+ return f"https://{self.invite_link}"
64
+ if self.username:
65
+ return f"{self.client.http_connection.short_url}/{self.username}"
66
+
67
+ @property
68
+ def full_name(self):
69
+ if self.first_name and self.last_name:
70
+ return f"{self.first_name} {self.last_name}"
71
+ if self.first_name:
72
+ return self.first_name
73
+ if self.title:
74
+ return self.title
75
+ return ""
76
+
77
+ async def ban_member(self, user_id: Union[int, str]):
78
+ return await self.client.ban_chat_member(self.id, user_id)
79
+
80
+ async def delete_photo(self):
81
+ return await self.client.delete_chat_photo(self.id)
82
+
83
+ async def get(self):
84
+ return await self.client.get_chat(self.id)
85
+
86
+ async def get_administrators(self):
87
+ return await self.client.get_chat_administrators(self.id)
88
+
89
+ async def get_member(self, user_id: Union[int, str]):
90
+ return await self.client.get_chat_member(self.id, user_id)
91
+
92
+ async def get_members_count(self):
93
+ return await self.client.get_chat_members_count(self.id)
94
+
95
+ async def leave(self):
96
+ return await self.client.leave_chat(self.id)
97
+
98
+ async def pin_message(self, message_id: int):
99
+ return await self.client.pin_chat_message(self.id, message_id)
100
+
101
+ async def promote_member(self, user_id: Union[int, str], *args, **kwargs):
102
+ return await self.client.promote_chat_member(self.id, user_id, *args, **kwargs)
103
+
104
+
105
+ async def set_description(self, description: str):
106
+ return await self.client.set_chat_description(self.id, description)
107
+
108
+ async def set_photo(self, photo: Union[str, bytes, BinaryIO, "objects.InputMedia"]):
109
+ return await self.client.set_chat_photo(self.id, photo)
110
+
111
+ async def set_title(self, title: str):
112
+ return await self.client.set_chat_title(self.id, title)
113
+
114
+ async def unban_member(self, user_id: Union[int, str], only_if_banned: bool = True):
115
+ return await self.client.unban_chat_member(self.id, user_id, only_if_banned)
116
+
117
+ async def unpin_message(self, message_id: int = None):
118
+ return await self.client.unpin_chat_message(self.id, message_id)
@@ -0,0 +1,53 @@
1
+ from . import Object
2
+ from PySPlusthon import enums, objects
3
+
4
+
5
+ class ChatMember(Object):
6
+
7
+ def __init__(
8
+ self,
9
+ is_member: bool = None,
10
+ can_send_media: bool = None,
11
+ can_send_gif_stickers: bool = None,
12
+ can_forward_message_from: bool = None,
13
+ can_send_gift_packet: bool = None,
14
+ can_send_link_message: bool = None,
15
+ can_send_forwarded_message: bool = None,
16
+ can_kick_user: bool = None,
17
+ can_send_message: bool = None,
18
+ can_see_members: bool = None,
19
+ can_add_story: bool = None,
20
+ user: "objects.User" = None,
21
+ status: "enums.ChatMemberStatus" = None,
22
+ can_change_info: bool = None,
23
+ can_delete_messages: bool = None,
24
+ can_invite_users: bool = None,
25
+ can_restrict_members: bool = None,
26
+ can_pin_messages: bool = None,
27
+ can_promote_members: bool = None,
28
+ can_send_messages: bool = None,
29
+ can_send_media_messages: bool = None,
30
+ **kwargs
31
+ ):
32
+ super().__init__(**kwargs)
33
+ self.is_member: bool = is_member
34
+ self.can_send_media: bool = can_send_media
35
+ self.can_send_gif_stickers: bool = can_send_gif_stickers
36
+ self.can_forward_message_from: bool = can_forward_message_from
37
+ self.can_send_gift_packet: bool = can_send_gift_packet
38
+ self.can_send_link_message: bool = can_send_link_message
39
+ self.can_send_forwarded_message: bool = can_send_forwarded_message
40
+ self.can_kick_user: bool = can_kick_user
41
+ self.can_send_message: bool = can_send_message
42
+ self.can_see_members: bool = can_see_members
43
+ self.can_add_story: bool = can_add_story
44
+ self.user: "objects.User" = user
45
+ self.status: "enums.ChatMemberStatus" = status
46
+ self.can_change_info: bool = can_change_info
47
+ self.can_delete_messages: bool = can_delete_messages
48
+ self.can_invite_users: bool = can_invite_users
49
+ self.can_restrict_members: bool = can_restrict_members
50
+ self.can_pin_messages: bool = can_pin_messages
51
+ self.can_promote_members: bool = can_promote_members
52
+ self.can_send_messages: bool = can_send_messages
53
+ self.can_send_media_messages: bool = can_send_media_messages
@@ -0,0 +1,26 @@
1
+ from . import Object
2
+
3
+
4
+ class ChatPermissions(Object):
5
+
6
+ def __init__(
7
+ self,
8
+ can_send_messages: bool = None,
9
+ can_send_audios: bool = None,
10
+ can_send_documents: bool = None,
11
+ can_send_photos: bool = None,
12
+ can_send_videos: bool = None,
13
+ can_change_info: bool = None,
14
+ can_invite_users: bool = None,
15
+ can_pin_messages: bool = None,
16
+ **kwargs
17
+ ):
18
+ super().__init__(**kwargs)
19
+ self.can_send_messages: bool = can_send_messages
20
+ self.can_send_audios: bool = can_send_audios
21
+ self.can_send_documents: bool = can_send_documents
22
+ self.can_send_photos: bool = can_send_photos
23
+ self.can_send_videos: bool = can_send_videos
24
+ self.can_change_info: bool = can_change_info
25
+ self.can_invite_users: bool = can_invite_users
26
+ self.can_pin_messages: bool = can_pin_messages
@@ -0,0 +1,24 @@
1
+ from . import Object
2
+
3
+
4
+ class ChatPhoto(Object):
5
+ attribute_names = [
6
+ ("small_id", "small_file_id"),
7
+ ("small_unique_id", "small_file_unique_id"),
8
+ ("big_id", "big_file_id"),
9
+ ("big_unique_id", "big_file_unique_id")
10
+ ]
11
+
12
+ def __init__(
13
+ self,
14
+ small_id: str = None,
15
+ small_unique_id: str = None,
16
+ big_id: str = None,
17
+ big_unique_id: str = None,
18
+ **kwargs
19
+ ):
20
+ super().__init__(**kwargs)
21
+ self.small_id: str = small_id
22
+ self.small_unique_id: str = small_unique_id
23
+ self.big_id: str = big_id
24
+ self.big_unique_id: str = big_unique_id
@@ -0,0 +1,18 @@
1
+ from . import Object
2
+
3
+
4
+ class Contact(Object):
5
+
6
+ def __init__(
7
+ self,
8
+ phone_number: str = None,
9
+ first_name: str = None,
10
+ last_name: str = None,
11
+ user_id: int = None,
12
+ **kwargs
13
+ ):
14
+ super().__init__(**kwargs)
15
+ self.phone_number: str = phone_number
16
+ self.first_name: str = first_name
17
+ self.last_name: str = last_name
18
+ self.user_id: int = user_id
@@ -0,0 +1,35 @@
1
+ from datetime import datetime
2
+
3
+ from . import Object
4
+
5
+
6
+ class Date(Object, datetime):
7
+
8
+ @classmethod
9
+ def wrap(cls, raw_object):
10
+ date_time = datetime.fromtimestamp(raw_object)
11
+ return super().__new__(cls, *date_time.timetuple()[:6])
12
+
13
+ @classmethod
14
+ def from_protobuf(cls, timestamp_ms: int):
15
+ return cls.wrap(timestamp_ms // 1000)
16
+
17
+ def __new__(
18
+ cls,
19
+ *args,
20
+ **kwargs
21
+ ):
22
+ return super().__new__(cls, *args, *kwargs)
23
+
24
+ def __init__(
25
+ self,
26
+ *args,
27
+ **kwargs
28
+ ):
29
+ super().__init__(**kwargs)
30
+
31
+ def __repr__(self):
32
+ return str(self)
33
+
34
+ def unwrap(self):
35
+ return int(super().timestamp())
@@ -0,0 +1,36 @@
1
+ from PySPlusthon import objects
2
+
3
+ from . import Object
4
+
5
+
6
+ class Document(Object):
7
+ attribute_names = [
8
+ ("id", "file_id"),
9
+ ("size", "file_size"),
10
+ ("name", "file_name")
11
+ ]
12
+
13
+ @classmethod
14
+ def from_protobuf(cls, protobuf_data):
15
+ return cls(
16
+ id=protobuf_data.file_id,
17
+ name=protobuf_data.name,
18
+ size=protobuf_data.file_size,
19
+ mime_type=protobuf_data.mime_type
20
+ )
21
+
22
+ def __init__(
23
+ self,
24
+ id: str = None,
25
+ thumb: "objects.Photo" = None,
26
+ name: str = None,
27
+ mime_type: str = None,
28
+ size: int = None,
29
+ **kwargs
30
+ ):
31
+ super().__init__(**kwargs)
32
+ self.id: str = id
33
+ self.thumb: None = thumb
34
+ self.name: str = name
35
+ self.mime_type: str = mime_type
36
+ self.size: int = size
@@ -0,0 +1,27 @@
1
+ from . import Object
2
+ from PySPlusthon import objects
3
+
4
+
5
+ class EditedMessage(Object):
6
+ attribute_names = [
7
+ ("id", "message_id"),
8
+ ("author", "from")
9
+ ]
10
+
11
+ def __init__(
12
+ self,
13
+ id: int = None,
14
+ author: "objects.User" = None,
15
+ date: "objects.Date" = None,
16
+ chat: "objects.Chat" = None,
17
+ edit_date: "objects.Date" = None,
18
+ text: str = None,
19
+ **kwargs
20
+ ):
21
+ super().__init__(**kwargs)
22
+ self.id: int = id
23
+ self.author: "objects.User" = author
24
+ self.date: "objects.Date" = date
25
+ self.chat: "objects.Chat" = chat
26
+ self.edit_date: "objects.Date" = edit_date
27
+ self.text: str = text
@@ -0,0 +1,21 @@
1
+ from . import Object
2
+ from PySPlusthon import objects
3
+
4
+
5
+ class Entity(Object):
6
+
7
+ def __init__(
8
+ self,
9
+ type: str = None,
10
+ offset: int = None,
11
+ length: int = None,
12
+ url: str = None,
13
+ user: "objects.User" = None,
14
+ **kwargs
15
+ ):
16
+ super().__init__(**kwargs)
17
+ self.type: str = type
18
+ self.offset: int = offset
19
+ self.length: int = length
20
+ self.url: str = url
21
+ self.user: "objects.User" = user
@@ -0,0 +1,21 @@
1
+ from . import Object
2
+
3
+
4
+ class File(Object):
5
+ attribute_names = [
6
+ ("id", "file_id"),
7
+ ("size", "file_size"),
8
+ ("path", "file_path")
9
+ ]
10
+
11
+ def __init__(
12
+ self,
13
+ id: str = None,
14
+ size: int = None,
15
+ path: str = None,
16
+ **kwargs
17
+ ):
18
+ super().__init__(**kwargs)
19
+ self.id: str = id
20
+ self.size: int = size
21
+ self.path: str = path
@@ -0,0 +1,22 @@
1
+ from PySPlusthon import enums
2
+ from . import Object
3
+ from .. import objects
4
+
5
+
6
+ class ForwardOrigin(Object):
7
+
8
+ def __init__(
9
+ self,
10
+ type: "enums.PeerType" = None,
11
+ date: "objects.Date" = None,
12
+ sender_user: "objects.User" = None,
13
+ chat: "objects.Chat" = None,
14
+ message_id: int = None,
15
+ **kwargs
16
+ ):
17
+ super().__init__(**kwargs)
18
+ self.type: "enums.PeerType" = type
19
+ self.date: "objects.Date" = date
20
+ self.sender_user: "objects.User" = sender_user
21
+ self.chat: "objects.Chat" = chat
22
+ self.message_id: int = message_id
@@ -0,0 +1,65 @@
1
+ from typing import Union, List, Tuple
2
+ from copy import deepcopy
3
+
4
+ from . import Object, ReplyMarkup, InlineKeyboardButton
5
+ from .list import List as PySplusthonList
6
+ from PySPlusthon import objects
7
+
8
+
9
+ class InlineKeyboard(ReplyMarkup):
10
+ def __init__(
11
+ self,
12
+ *rows: List[Union["objects.InlineKeyboardButton", Tuple[str, str]]],
13
+ **kwargs
14
+ ):
15
+ super().__init__(**kwargs)
16
+ if "inline_keyboard" not in kwargs:
17
+ self.inline_keyboard: List[List["objects.InlineKeyboardButton"]] = PySplusthonList()
18
+ for row in rows:
19
+ self.add_row(*row)
20
+
21
+ @classmethod
22
+ def expected_types(cls):
23
+ expected_types = super().expected_types()
24
+ expected_types["inline_keyboard"] = List[List[objects.InlineKeyboardButton]]
25
+ return expected_types
26
+
27
+ @classmethod
28
+ def wrap(cls, raw_object):
29
+ return Object.wrap.__func__(cls, raw_object)
30
+
31
+ def add_button(
32
+ self,
33
+ button: Union["objects.InlineKeyboardButton", Tuple[str, str]],
34
+ row_index: int = -1,
35
+ button_index: int = -1
36
+ ):
37
+ if isinstance(button, tuple):
38
+ button = InlineKeyboardButton(*button)
39
+ if button_index == -1:
40
+ self.inline_keyboard[row_index].append(button)
41
+ elif button_index < 0:
42
+ self.inline_keyboard[row_index].insert(button_index + 1, button)
43
+ else:
44
+ self.inline_keyboard[row_index].insert(button_index, button)
45
+
46
+ def add_row(self, *row: Union["objects.InlineKeyboardButton", Tuple[str, str]], row_index: int = -1):
47
+ if row_index == -1:
48
+ self.inline_keyboard.append(PySplusthonList())
49
+ elif row_index < 0:
50
+ self.inline_keyboard.insert(row_index + 1, PySplusthonList())
51
+ else:
52
+ self.inline_keyboard.insert(row_index, PySplusthonList())
53
+ for button in row:
54
+ self.add_button(button, row_index)
55
+
56
+ def on_click(self, row_index: int, button_index: int):
57
+ from ..conditions import click
58
+ return click(self, row_index, button_index)
59
+
60
+ def format(self, *args, **kwargs):
61
+ markup = deepcopy(self)
62
+ for i, row in enumerate(markup.inline_keyboard):
63
+ for j, button in enumerate(row):
64
+ markup.inline_keyboard[i][j] = button.format(*args, **kwargs)
65
+ return markup
@@ -0,0 +1,30 @@
1
+ from typing import Union
2
+ from copy import deepcopy
3
+
4
+ from . import Object
5
+ from PySPlusthon import objects
6
+
7
+
8
+ class InlineKeyboardButton(Object):
9
+
10
+ def __init__(
11
+ self,
12
+ text: str = None,
13
+ callback_data: str = None,
14
+ url: str = None,
15
+ **kwargs
16
+ ):
17
+ super().__init__(**kwargs)
18
+ self.text: str = text
19
+ self.callback_data: str = callback_data
20
+ self.url: str = url
21
+
22
+ def format(self, *args, **kwargs):
23
+ button = deepcopy(self)
24
+ if button.text:
25
+ button.text = button.text.format(*args, **kwargs)
26
+ if button.callback_data:
27
+ button.callback_data = button.callback_data.format(*args, **kwargs)
28
+ if button.url:
29
+ button.url = button.url.format(*args, **kwargs)
30
+ return button
@@ -0,0 +1,44 @@
1
+ from typing import Union, BinaryIO
2
+ from os.path import isfile
3
+
4
+ from sqlalchemy import Boolean
5
+
6
+ from . import Object
7
+
8
+
9
+ class InputMedia(Object):
10
+
11
+ def __init__(
12
+ self,
13
+ type: str = None,
14
+ media: Union[str, bytes, BinaryIO] = None,
15
+ caption: str = None,
16
+ parse_mode : str = None,
17
+ disable_content_type_detection : Boolean = None,
18
+ **kwargs
19
+ ):
20
+ super().__init__(**kwargs)
21
+ self.type: str = type
22
+ self.media: Union[str, bytes, BinaryIO] = resolve_media(media)
23
+ self.caption: str = caption
24
+
25
+ @property
26
+ def is_json_serializable(self):
27
+ return isinstance(self.media, str)
28
+
29
+
30
+ def resolve_media(media):
31
+ if isinstance(media, InputMedia):
32
+ return media.media
33
+
34
+ if isinstance(media, Object):
35
+ if getattr(media, "id", None):
36
+ return media.id
37
+
38
+ try:
39
+ if isfile(media):
40
+ return open(media, "rb")
41
+ except TypeError:
42
+ pass
43
+
44
+ return media
@@ -0,0 +1,14 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ from . import InputMedia
4
+
5
+
6
+ class InputMediaPhoto(InputMedia):
7
+
8
+ def __init__(
9
+ self,
10
+ media: Union[str, bytes, BinaryIO] = None,
11
+ caption: str = None,
12
+ **kwargs
13
+ ):
14
+ super().__init__("photo", media, caption, **kwargs)
@@ -0,0 +1,14 @@
1
+ from typing import Union, BinaryIO
2
+
3
+ from . import InputMedia
4
+
5
+
6
+ class InputMediaVideo(InputMedia):
7
+
8
+ def __init__(
9
+ self,
10
+ media: Union[str, bytes, BinaryIO] = None,
11
+ caption: str = None,
12
+ **kwargs
13
+ ):
14
+ super().__init__("video", media, caption, **kwargs)
@@ -0,0 +1,32 @@
1
+ from . import Object
2
+ from PySPlusthon import objects
3
+
4
+
5
+ class InviteLink(Object):
6
+ attribute_names = [
7
+ ("link", "invite_link")
8
+ ]
9
+
10
+ def __init__(
11
+ self,
12
+ link: str = None,
13
+ creator: "objects.User" = None,
14
+ creates_join_request: bool = None,
15
+ is_primary: bool = None,
16
+ is_revoked: bool = None,
17
+ name: str = None,
18
+ expire_date: int = None,
19
+ member_limit: int = None,
20
+ pending_join_request_count: int = None,
21
+ **kwargs
22
+ ):
23
+ super().__init__(**kwargs)
24
+ self.link: str = link
25
+ self.creator: "objects.User" = creator
26
+ self.creates_join_request: bool = creates_join_request
27
+ self.is_primary: bool = is_primary
28
+ self.is_revoked: bool = is_revoked
29
+ self.name: str = name
30
+ self.expire_date: int = expire_date
31
+ self.member_limit: int = member_limit
32
+ self.pending_join_request_count: int = pending_join_request_count
@@ -0,0 +1,24 @@
1
+ from . import Object, unwrap
2
+
3
+
4
+ class List(list, Object):
5
+ @classmethod
6
+ def wrap(cls, raw_object):
7
+ return cls(raw_object)
8
+
9
+ def bind(self, client):
10
+ self.client = client
11
+ for element in self:
12
+ if isinstance(element, Object):
13
+ element.bind(client)
14
+
15
+ def unwrap(self):
16
+ return unwrap(self)
17
+
18
+ def __repr__(self):
19
+ if not self:
20
+ return "[]"
21
+
22
+ elements = ",\n".join(f"{repr(element)}" for element in self)
23
+ elements = "\n".join(" "*4 + line for line in elements.splitlines())
24
+ return f"[\n{elements}\n]"
@@ -0,0 +1,14 @@
1
+ from . import Object
2
+
3
+
4
+ class Location(Object):
5
+
6
+ def __init__(
7
+ self,
8
+ longitude: float = None,
9
+ latitude: float = None,
10
+ **kwargs
11
+ ):
12
+ super().__init__(**kwargs)
13
+ self.longitude: float = longitude
14
+ self.latitude: float = latitude