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,6 @@
1
+ from .rpc_error import RPCError
2
+
3
+
4
+ class ForbiddenError(RPCError):
5
+ name = "Forbidden"
6
+ code = 403
@@ -0,0 +1,6 @@
1
+ from .rpc_error import RPCError
2
+
3
+
4
+ class InternalError(RPCError):
5
+ name = "Internal"
6
+ code = 500
@@ -0,0 +1,6 @@
1
+ from .rpc_error import RPCError
2
+
3
+
4
+ class NotFoundError(RPCError):
5
+ name = "Not Found"
6
+ code = 404
@@ -0,0 +1,23 @@
1
+ class RPCError(Exception):
2
+ name = "RPC Error"
3
+ code = None
4
+
5
+ @classmethod
6
+ def create(cls, code: int = None, description: str = None, reason: str = None, parameters: dict = None):
7
+ for rpc_error in cls.__subclasses__():
8
+ if code == rpc_error.code:
9
+ return rpc_error(code, description, reason, parameters)
10
+ return cls(code, description, reason, parameters)
11
+
12
+ def __init__(self, code: int = None, description: str = None, reason: str = None, parameters: dict = None):
13
+ self.code = code or self.code
14
+ self.description = description
15
+ self.reason = reason
16
+ self.parameters = parameters
17
+ super().__init__(str(self))
18
+
19
+ def __str__(self):
20
+ code = "" if self.code is None else f" {self.code}"
21
+ description = "" if not self.description else f": {self.description}"
22
+ reason = "" if self.reason is None else f" (caused by {self.reason})"
23
+ return f"{self.name}{code}{description}{reason}"
@@ -0,0 +1,10 @@
1
+ from .rpc_error import RPCError
2
+
3
+
4
+ class TooManyRequestsError(RPCError):
5
+ name = "Too Many Requests"
6
+ code = 429
7
+
8
+ def __init__(self, code: int = None, description: str = None, reason: str = None, parameters: dict = None):
9
+ super().__init__(code, description, reason, parameters)
10
+ self.seconds = (parameters or {}).get("retry_after", 0)
@@ -0,0 +1,6 @@
1
+ from .rpc_error import RPCError
2
+
3
+
4
+ class UnauthorizedError(RPCError):
5
+ name = "Unauthorized"
6
+ code = 401
@@ -0,0 +1,12 @@
1
+ from .event_handler import EventHandler
2
+ from .connect_handler import ConnectHandler
3
+ from .disconnect_handler import DisconnectHandler
4
+ from .error_handler import ErrorHandler
5
+ from .update_handler import UpdateHandler
6
+ from .message_handler import MessageHandler
7
+ from .callback_query_handler import CallbackQueryHandler
8
+ from .command_handler import CommandHandler
9
+ from .shipping_query_handler import ShippingQueryHandler
10
+ from .edited_message_handler import EditedMessageHandler
11
+ from .initialize_handler import InitializeHandler
12
+ from .shutdown_handler import ShutdownHandler
@@ -0,0 +1,16 @@
1
+ from .update_handler import UpdateHandler
2
+ from ..objects import CallbackQuery
3
+
4
+
5
+ class CallbackQueryHandler(UpdateHandler):
6
+ can_handle = CallbackQuery
7
+
8
+ def __init__(self, callback, condition=None):
9
+ super().__init__(callback, condition)
10
+
11
+ def handle(self, *args, client=None, event=None, **kwargs):
12
+ if client is not None:
13
+ kwargs["client"] = client
14
+ if event is not None:
15
+ kwargs["callback_query"] = event
16
+ return super().handle(*args, **kwargs)
@@ -0,0 +1,46 @@
1
+ from inspect import getfullargspec
2
+
3
+ from .message_handler import MessageHandler
4
+ from ..conditions import command
5
+ from ..objects import Message
6
+
7
+
8
+ class CommandHandler(MessageHandler):
9
+ can_handle = Message
10
+
11
+ @staticmethod
12
+ def get_min_arguments(callback):
13
+ args, _, __, defaults, *___ = getfullargspec(callback)
14
+ args_count = len(args)
15
+ defaults_count = 0 if defaults is None else len(defaults)
16
+ return args_count - defaults_count
17
+
18
+ @staticmethod
19
+ def get_max_arguments(callback):
20
+ args, varargs, *_ = getfullargspec(callback)
21
+ if varargs is not None:
22
+ return None
23
+ return len(args)
24
+
25
+ def __init__(self, callback, condition=None, name=None, prefix="/", min_arguments=None, max_arguments=None):
26
+ if name is None:
27
+ name = callback.__name__
28
+ if min_arguments is None:
29
+ min_arguments = self.get_min_arguments(callback)
30
+ if max_arguments is None:
31
+ max_arguments = self.get_max_arguments(callback)
32
+ command_condition = command(name, prefix, min_arguments, max_arguments)
33
+ if condition is None:
34
+ condition = command_condition
35
+ else:
36
+ condition = command_condition & condition
37
+ super().__init__(callback, condition)
38
+
39
+ def handle(self, *args, client=None, event=None, **kwargs):
40
+ if client is not None:
41
+ kwargs["client"] = client
42
+ if event is not None:
43
+ kwargs["message"] = event
44
+ _, *arguments = event.text.split()
45
+ args += tuple(arguments)
46
+ return super().handle(*args, **kwargs)
@@ -0,0 +1,19 @@
1
+ from datetime import datetime
2
+
3
+ from .initialize_handler import EventHandler
4
+
5
+
6
+ class ConnectHandler(EventHandler):
7
+
8
+ @property
9
+ def can_handle(self):
10
+ return ConnectHandler
11
+
12
+ def __init__(self, callback):
13
+ super().__init__(callback)
14
+
15
+ async def handle(self, *args, client=None, event=None, **kwargs):
16
+ if client is not None:
17
+ kwargs["client"] = client
18
+ await super().handle(*args, **kwargs, time=datetime.now())
19
+
@@ -0,0 +1,18 @@
1
+ from datetime import datetime
2
+
3
+ from .shutdown_handler import EventHandler
4
+
5
+
6
+ class DisconnectHandler(EventHandler):
7
+
8
+ @property
9
+ def can_handle(self):
10
+ return DisconnectHandler
11
+
12
+ def __init__(self, callback):
13
+ super().__init__(callback)
14
+
15
+ async def handle(self, *args, client=None, event=None, **kwargs):
16
+ if client is not None:
17
+ kwargs["client"] = client
18
+ await super().handle(*args, **kwargs, time=datetime.now())
@@ -0,0 +1,16 @@
1
+ from .update_handler import UpdateHandler
2
+ from ..objects import EditedMessage
3
+
4
+
5
+ class EditedMessageHandler(UpdateHandler):
6
+ can_handle = EditedMessage
7
+
8
+ def __init__(self, callback, condition=None):
9
+ super().__init__(callback, condition)
10
+
11
+ def handle(self, *args, client=None, event=None, **kwargs):
12
+ if client is not None:
13
+ kwargs["client"] = client
14
+ if event is not None:
15
+ kwargs["edited_message"] = event
16
+ return super().handle(*args, **kwargs)
@@ -0,0 +1,15 @@
1
+ from .event_handler import EventHandler
2
+
3
+
4
+ class ErrorHandler(EventHandler):
5
+ can_handle = Exception
6
+
7
+ def __init__(self, callback, condition=None):
8
+ super().__init__(callback, condition)
9
+
10
+ async def handle(self, *args, client=None, event=None, **kwargs):
11
+ if client is not None:
12
+ kwargs["client"] = client
13
+ if event is not None:
14
+ kwargs["error"] = event
15
+ await super().handle(*args, **kwargs)
@@ -0,0 +1,53 @@
1
+ from typing import Callable
2
+ from inspect import iscoroutinefunction
3
+ from functools import partial
4
+
5
+ from ..conditions import Condition, create
6
+ from ..smart_call import remove_unwanted_parameters
7
+
8
+
9
+ class EventHandler:
10
+ can_handle = object
11
+
12
+ def __init__(self, callback: Callable, condition=None):
13
+ self.callback = callback
14
+ if not isinstance(condition, Condition) and condition is not None:
15
+ condition = create(condition)
16
+ self.condition = condition
17
+ self.self = None
18
+
19
+ def to_string(self, keyword="if", tabs=0):
20
+ result = []
21
+ condition = self.condition or self.can_handle.__name__
22
+ result.append(f"{keyword} {condition}:")
23
+ result.append(f" {type(self).__name__}({self.can_handle.__name__})")
24
+ return "\n".join(f"{' ' * tabs}{i}" for i in result)
25
+
26
+ def __repr__(self):
27
+ return self.to_string()
28
+
29
+ async def check(self, client, event):
30
+ if self.condition is None:
31
+ return True
32
+ return await self.condition(client, event)
33
+
34
+ async def handle(self, *args, client=None, event=None, **kwargs):
35
+ if client is not None:
36
+ kwargs["client"] = client
37
+ client = kwargs["client"]
38
+ if self.self is not None:
39
+ args = list(args)
40
+ args.insert(0, self.self)
41
+ if event is not None:
42
+ kwargs["event"] = event
43
+ args, kwargs = remove_unwanted_parameters(self.callback, *args, **kwargs)
44
+ if iscoroutinefunction(self.callback):
45
+ return await self.callback(*args, **kwargs)
46
+ return client.dispatcher.event_loop.run_in_executor(
47
+ client.dispatcher.sync_workers,
48
+ partial(self.callback, *args, **kwargs)
49
+ )
50
+
51
+ def __call__(self, *args, **kwargs):
52
+ args, kwargs = remove_unwanted_parameters(self.callback, *args, **kwargs)
53
+ return self.callback(*args, **kwargs)
@@ -0,0 +1,18 @@
1
+ from datetime import datetime
2
+
3
+ from .event_handler import EventHandler
4
+
5
+
6
+ class InitializeHandler(EventHandler):
7
+
8
+ @property
9
+ def can_handle(self):
10
+ return InitializeHandler
11
+
12
+ def __init__(self, callback):
13
+ super().__init__(callback)
14
+
15
+ async def handle(self, *args, client=None, event=None, **kwargs):
16
+ if client is not None:
17
+ kwargs["client"] = client
18
+ await super().handle(*args, **kwargs, time=datetime.now())
@@ -0,0 +1,16 @@
1
+ from .update_handler import UpdateHandler
2
+ from ..objects import Message
3
+
4
+
5
+ class MessageHandler(UpdateHandler):
6
+ can_handle = Message
7
+
8
+ def __init__(self, callback, condition=None):
9
+ super().__init__(callback, condition)
10
+
11
+ def handle(self, *args, client=None, event=None, **kwargs):
12
+ if client is not None:
13
+ kwargs["client"] = client
14
+ if event is not None:
15
+ kwargs["message"] = event
16
+ return super().handle(*args, **kwargs)
@@ -0,0 +1,16 @@
1
+ from .update_handler import UpdateHandler
2
+ from ..objects import ShippingQuery
3
+
4
+
5
+ class ShippingQueryHandler(UpdateHandler):
6
+ can_handle = ShippingQuery
7
+
8
+ def __init__(self, callback, condition=None):
9
+ super().__init__(callback, condition)
10
+
11
+ def handle(self, *args, client=None, event=None, **kwargs):
12
+ if client is not None:
13
+ kwargs["client"] = client
14
+ if event is not None:
15
+ kwargs["shipping_query"] = event
16
+ return super().handle(*args, **kwargs)
@@ -0,0 +1,18 @@
1
+ from datetime import datetime
2
+
3
+ from .event_handler import EventHandler
4
+
5
+
6
+ class ShutdownHandler(EventHandler):
7
+
8
+ @property
9
+ def can_handle(self):
10
+ return ShutdownHandler
11
+
12
+ def __init__(self, callback):
13
+ super().__init__(callback)
14
+
15
+ async def handle(self, *args, client=None, event=None, **kwargs):
16
+ if client is not None:
17
+ kwargs["client"] = client
18
+ await super().handle(*args, **kwargs, time=datetime.now())
@@ -0,0 +1,16 @@
1
+ from .event_handler import EventHandler
2
+ from ..objects import Object
3
+
4
+
5
+ class UpdateHandler(EventHandler):
6
+ can_handle = Object
7
+
8
+ def __init__(self, callback, condition=None):
9
+ super().__init__(callback, condition)
10
+
11
+ async def handle(self, *args, client=None, event=None, **kwargs):
12
+ if client is not None:
13
+ kwargs["client"] = client
14
+ if event is not None:
15
+ kwargs["update"] = event
16
+ await super().handle(*args, **kwargs)
@@ -0,0 +1 @@
1
+ from .httpconnection import HTTPConnection
@@ -0,0 +1,74 @@
1
+ from logging import getLogger
2
+
3
+ from httpx import AsyncClient
4
+ from httpx._types import ProxyTypes
5
+
6
+ from ..errors import RPCError
7
+
8
+ log = getLogger(__name__)
9
+
10
+
11
+ class HTTPConnection:
12
+ TIMEOUT = 20
13
+ BASE_URL = "https://api.splus.ir"
14
+ SHORT_URL = "https://splus.ir"
15
+
16
+ def __init__(
17
+ self,
18
+ token: str,
19
+ time_out: int = None,
20
+ proxy: ProxyTypes = None,
21
+ base_url: str = None,
22
+ short_url: str = None
23
+ ):
24
+ self.token = token
25
+ self.client = None
26
+ self.is_started = False
27
+ self.time_out = time_out or self.TIMEOUT
28
+ self.proxy = proxy
29
+ self.base_url = base_url or self.BASE_URL
30
+ self.short_url = short_url or self.SHORT_URL
31
+
32
+ async def start(self):
33
+ if self.is_started:
34
+ raise ConnectionError("Connection is already started")
35
+ self.is_started = True
36
+ self.client = AsyncClient(proxy=self.proxy)
37
+
38
+ async def stop(self):
39
+ if not self.is_started:
40
+ raise ConnectionError("Connection is already stopped")
41
+ self.is_started = False
42
+ await self.client.aclose()
43
+ self.client = None
44
+
45
+ def bot_url(self) -> str:
46
+ return f"{self.base_url}/bot{self.token}"
47
+
48
+ def file_url(self, file_id: str) -> str:
49
+ return f"{self.base_url}/file/bot{self.token}/{file_id}"
50
+
51
+ async def request(self, service: str, data: dict = None, json: dict = None, files: dict = None):
52
+ if json:
53
+ log.info(f"[{service}] JSON{json}")
54
+ if data:
55
+ log.info(f"[{service}] DATA{data} - FILES{files}")
56
+ response = await self.client.post(
57
+ f"{self.bot_url()}/{service}",
58
+ data=data,
59
+ files=files,
60
+ json=json,
61
+ timeout=self.time_out
62
+ )
63
+ response_json = response.json()
64
+ if response.status_code != 200:
65
+ code = response.status_code or response_json.get("error_code")
66
+ raise RPCError.create(code, response_json.get("description"), service, response_json.get("parameters"))
67
+ return response_json.get("result")
68
+
69
+ async def download_file(self, file_id: str):
70
+ response = await self.client.get(self.file_url(file_id))
71
+ if response.status_code != 200:
72
+ response_json = response.json()
73
+ raise RPCError.create(response.status_code, response_json.get("description"), "downloadFile")
74
+ return response.read()
@@ -0,0 +1,43 @@
1
+ from .object import Object, wrap, unwrap
2
+ from .user import User
3
+ from .date import Date
4
+ from .chat import Chat
5
+ from .update import Update
6
+ from .file import File
7
+ from .chat_member import ChatMember
8
+ from .message import Message
9
+ from .edited_message import EditedMessage
10
+ from .callback_query import CallbackQuery
11
+ from .reply_markup import ReplyMarkup
12
+ from .inline_keyboard_button import InlineKeyboardButton
13
+ from .inline_keyboard import InlineKeyboard
14
+ from .reply_keyboard_button import ReplyKeyboardButton
15
+ from .reply_keyboard import ReplyKeyboard
16
+ from .entity import Entity
17
+ from .shipping_query import ShippingQuery
18
+ from .shipping_address import ShippingAddress
19
+ from .order_info import OrderInfo
20
+ from .audio import Audio
21
+ from .contact import Contact
22
+ from .document import Document
23
+ from .location import Location
24
+ from .photo import Photo
25
+ from .video import Video
26
+ from .voice import Voice
27
+ from .transaction import Transaction
28
+ from .input_media import InputMedia, resolve_media
29
+ from .input_media_photo import InputMediaPhoto
30
+ from .input_media_video import InputMediaVideo
31
+ from .sticker import Sticker
32
+ from .sticker_set import StickerSet
33
+ from .reply_keyboard_remove import ReplyKeyboardRemove
34
+ from .animation import Animation
35
+ from .webhook_info import WebhookInfo
36
+ from .chat_photo import ChatPhoto
37
+ from .invite_link import InviteLink
38
+ from .list import List
39
+ from .poll_option import PollOption
40
+ from .poll import Poll
41
+ from .forward_origin import ForwardOrigin
42
+ from .message_id import MessageId, resolve_message_id
43
+ from .chat_permissions import ChatPermissions
@@ -0,0 +1,44 @@
1
+ from . import Object
2
+
3
+
4
+ class Animation(Object):
5
+ attribute_names = [
6
+ ("id", "file_id"),
7
+ ("unique_id", "file_unique_id"),
8
+ ("name", "file_name"),
9
+ ("size", "file_size")
10
+ ]
11
+
12
+ @classmethod
13
+ def from_protobuf(cls, protobuf_data):
14
+ return cls(
15
+ id=protobuf_data.file_id,
16
+ width=protobuf_data.ext.document_ex_gif.w,
17
+ height=protobuf_data.ext.document_ex_gif.h,
18
+ duration=protobuf_data.ext.document_ex_gif.duration,
19
+ name=protobuf_data.name,
20
+ mime_type=protobuf_data.mime_type,
21
+ size=protobuf_data.file_size
22
+ )
23
+
24
+ def __init__(
25
+ self,
26
+ id: str = None,
27
+ unique_id: str = None,
28
+ width: int = None,
29
+ height: int = None,
30
+ duration: int = None,
31
+ name: str = None,
32
+ mime_type: str = None,
33
+ size: int = None,
34
+ **kwargs
35
+ ):
36
+ self.id: str = id
37
+ self.unique_id: str = unique_id
38
+ self.width: int = width
39
+ self.height: int = height
40
+ self.duration: int = duration
41
+ self.name: str = name
42
+ self.mime_type: str = mime_type
43
+ self.size: int = size
44
+ super().__init__(**kwargs)
@@ -0,0 +1,36 @@
1
+ from . import Object
2
+
3
+
4
+ class Audio(Object):
5
+ attribute_names = [
6
+ ("id", "file_id"),
7
+ ("size", "file_size")
8
+ ]
9
+
10
+ @classmethod
11
+ def from_protobuf(cls, protobuf_data):
12
+ return cls(
13
+ id=protobuf_data.file_id,
14
+ duration=protobuf_data.ext.document_ex_audio.duration,
15
+ title=protobuf_data.ext.document_ex_audio.track,
16
+ mime_type=protobuf_data.mime_type,
17
+ size=protobuf_data.file_size
18
+ )
19
+
20
+ def __init__(
21
+ self,
22
+ id: str = None,
23
+ duration: int = None,
24
+ performer: str = None,
25
+ title: str = None,
26
+ mime_type: str = None,
27
+ size: int = None,
28
+ **kwargs
29
+ ):
30
+ super().__init__(**kwargs)
31
+ self.id: str = id
32
+ self.duration: int = duration
33
+ self.performer: str = performer
34
+ self.title: str = title
35
+ self.mime_type: str = mime_type
36
+ self.size: int = size
@@ -0,0 +1,37 @@
1
+ from . import Object
2
+ from PySPlusthon import objects
3
+ from ..sync_support import add_sync_support_to_object
4
+
5
+
6
+ @add_sync_support_to_object
7
+ class CallbackQuery(Object):
8
+ attribute_names = [
9
+ ("author", "from")
10
+ ]
11
+
12
+ def __init__(
13
+ self,
14
+ id: str = None,
15
+ author: "objects.User" = None,
16
+ message: "objects.Message" = None,
17
+ inline_message_id: str = None,
18
+ chat_instance: str = None,
19
+ data: str = None,
20
+ game_short_name: str = None,
21
+ **kwargs
22
+ ):
23
+ super().__init__(**kwargs)
24
+ self.id: str = id
25
+ self.author: "objects.User" = author
26
+ self.message: "objects.Message" = message
27
+ self.inline_message_id: str = inline_message_id
28
+ self.chat_instance: str = chat_instance
29
+ self.data: str = data
30
+ self.game_short_name: str = game_short_name
31
+
32
+ async def answer(
33
+ self,
34
+ text: str,
35
+ show_alert: bool = False
36
+ ) -> bool:
37
+ return await self.client.answer_callback_query(self.id, text, show_alert)