PySPlusthon 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PySPlusthon/__init__.py +3 -0
- PySPlusthon/client/__init__.py +1 -0
- PySPlusthon/client/attachments/__init__.py +29 -0
- PySPlusthon/client/attachments/get_file.py +22 -0
- PySPlusthon/client/attachments/send_animation.py +71 -0
- PySPlusthon/client/attachments/send_audio.py +54 -0
- PySPlusthon/client/attachments/send_contact.py +47 -0
- PySPlusthon/client/attachments/send_document.py +63 -0
- PySPlusthon/client/attachments/send_location.py +45 -0
- PySPlusthon/client/attachments/send_media_group.py +88 -0
- PySPlusthon/client/attachments/send_photo.py +67 -0
- PySPlusthon/client/attachments/send_sticker.py +51 -0
- PySPlusthon/client/attachments/send_video.py +56 -0
- PySPlusthon/client/attachments/send_voice.py +52 -0
- PySPlusthon/client/attachments/upload_file.py +82 -0
- PySPlusthon/client/chats/__init__.py +43 -0
- PySPlusthon/client/chats/ban_chat_member.py +24 -0
- PySPlusthon/client/chats/delete_chat_photo.py +32 -0
- PySPlusthon/client/chats/get_chat.py +69 -0
- PySPlusthon/client/chats/get_chat_administrators.py +18 -0
- PySPlusthon/client/chats/get_chat_history.py +39 -0
- PySPlusthon/client/chats/get_chat_member.py +16 -0
- PySPlusthon/client/chats/get_chat_members.py +29 -0
- PySPlusthon/client/chats/get_chat_members_count.py +21 -0
- PySPlusthon/client/chats/join_chat.py +31 -0
- PySPlusthon/client/chats/leave_chat.py +22 -0
- PySPlusthon/client/chats/pin_chat_message.py +31 -0
- PySPlusthon/client/chats/promote_chat_member.py +64 -0
- PySPlusthon/client/chats/restrict_chat_member.py +25 -0
- PySPlusthon/client/chats/set_chat_description.py +23 -0
- PySPlusthon/client/chats/set_chat_photo.py +33 -0
- PySPlusthon/client/chats/set_chat_title.py +23 -0
- PySPlusthon/client/chats/unban_chat_member.py +24 -0
- PySPlusthon/client/chats/unpin_all_chat_messages.py +38 -0
- PySPlusthon/client/chats/unpin_chat_message.py +33 -0
- PySPlusthon/client/client.py +223 -0
- PySPlusthon/client/invite_links/__init__.py +7 -0
- PySPlusthon/client/invite_links/create_chat_invite_link.py +14 -0
- PySPlusthon/client/invite_links/export_chat_invite_link.py +21 -0
- PySPlusthon/client/invite_links/revoke_chat_invite_link.py +23 -0
- PySPlusthon/client/messages/__init__.py +21 -0
- PySPlusthon/client/messages/answer_callback_query.py +12 -0
- PySPlusthon/client/messages/copy_message.py +43 -0
- PySPlusthon/client/messages/delete_message.py +29 -0
- PySPlusthon/client/messages/edit_message_caption.py +40 -0
- PySPlusthon/client/messages/edit_message_reply_markup.py +17 -0
- PySPlusthon/client/messages/edit_message_text.py +40 -0
- PySPlusthon/client/messages/forward_message.py +35 -0
- PySPlusthon/client/messages/send_message.py +39 -0
- PySPlusthon/client/stickers/__init__.py +9 -0
- PySPlusthon/client/stickers/add_sticker_to_set.py +15 -0
- PySPlusthon/client/stickers/create_new_sticker_set.py +16 -0
- PySPlusthon/client/stickers/delete_sticker_from_set.py +10 -0
- PySPlusthon/client/stickers/get_sticker_set.py +11 -0
- PySPlusthon/client/stickers/upload_sticker_file.py +16 -0
- PySPlusthon/client/updates/__init__.py +8 -0
- PySPlusthon/client/updates/delete_webhook.py +9 -0
- PySPlusthon/client/updates/get_updates.py +14 -0
- PySPlusthon/client/updates/get_webhook_info.py +10 -0
- PySPlusthon/client/updates/set_webhook.py +10 -0
- PySPlusthon/client/users/__init__.py +6 -0
- PySPlusthon/client/users/ask_review.py +14 -0
- PySPlusthon/client/users/get_me.py +16 -0
- PySPlusthon/conditions/__init__.py +43 -0
- PySPlusthon/conditions/all.py +6 -0
- PySPlusthon/conditions/animation.py +7 -0
- PySPlusthon/conditions/at_state.py +18 -0
- PySPlusthon/conditions/audio.py +7 -0
- PySPlusthon/conditions/author.py +13 -0
- PySPlusthon/conditions/caption.py +7 -0
- PySPlusthon/conditions/channel.py +11 -0
- PySPlusthon/conditions/channel_chat_created.py +7 -0
- PySPlusthon/conditions/chat.py +14 -0
- PySPlusthon/conditions/click.py +24 -0
- PySPlusthon/conditions/command.py +23 -0
- PySPlusthon/conditions/condition.py +88 -0
- PySPlusthon/conditions/contact.py +7 -0
- PySPlusthon/conditions/content.py +7 -0
- PySPlusthon/conditions/delete_chat_photo.py +7 -0
- PySPlusthon/conditions/document.py +7 -0
- PySPlusthon/conditions/entities.py +7 -0
- PySPlusthon/conditions/equals.py +14 -0
- PySPlusthon/conditions/forward.py +7 -0
- PySPlusthon/conditions/group.py +11 -0
- PySPlusthon/conditions/group_chat_created.py +7 -0
- PySPlusthon/conditions/is_admin.py +17 -0
- PySPlusthon/conditions/is_instance.py +10 -0
- PySPlusthon/conditions/is_joined.py +61 -0
- PySPlusthon/conditions/left_chat_member.py +7 -0
- PySPlusthon/conditions/location.py +7 -0
- PySPlusthon/conditions/media.py +7 -0
- PySPlusthon/conditions/media_group.py +7 -0
- PySPlusthon/conditions/new_chat_members.py +7 -0
- PySPlusthon/conditions/new_chat_photo.py +7 -0
- PySPlusthon/conditions/new_chat_title.py +7 -0
- PySPlusthon/conditions/number.py +12 -0
- PySPlusthon/conditions/photo.py +7 -0
- PySPlusthon/conditions/pinned_message.py +7 -0
- PySPlusthon/conditions/poll.py +7 -0
- PySPlusthon/conditions/private.py +11 -0
- PySPlusthon/conditions/regex.py +17 -0
- PySPlusthon/conditions/reply.py +7 -0
- PySPlusthon/conditions/sticker.py +7 -0
- PySPlusthon/conditions/supergroup_chat_created.py +7 -0
- PySPlusthon/conditions/text.py +7 -0
- PySPlusthon/conditions/video.py +7 -0
- PySPlusthon/conditions/voice.py +7 -0
- PySPlusthon/dispatcher/__init__.py +5 -0
- PySPlusthon/dispatcher/chain.py +165 -0
- PySPlusthon/dispatcher/dispatcher.py +124 -0
- PySPlusthon/dispatcher/logging_chain.py +36 -0
- PySPlusthon/dispatcher/monitoring_chain.py +19 -0
- PySPlusthon/dispatcher/printing_chain.py +21 -0
- PySPlusthon/enums/__init__.py +7 -0
- PySPlusthon/enums/chat_member_status.py +9 -0
- PySPlusthon/enums/chat_type.py +9 -0
- PySPlusthon/enums/message_media_type.py +16 -0
- PySPlusthon/enums/name_enum.py +13 -0
- PySPlusthon/enums/peer_type.py +8 -0
- PySPlusthon/enums/poll_type.py +8 -0
- PySPlusthon/enums/transaction_status.py +10 -0
- PySPlusthon/errors/__init__.py +11 -0
- PySPlusthon/errors/dispatching_errors/__init__.py +2 -0
- PySPlusthon/errors/dispatching_errors/break_dispatching.py +2 -0
- PySPlusthon/errors/dispatching_errors/continue_dispatching.py +2 -0
- PySPlusthon/errors/rpc_errors/__init__.py +8 -0
- PySPlusthon/errors/rpc_errors/bad_request_error.py +6 -0
- PySPlusthon/errors/rpc_errors/flood_error.py +6 -0
- PySPlusthon/errors/rpc_errors/forbidden_error.py +6 -0
- PySPlusthon/errors/rpc_errors/internal_error.py +6 -0
- PySPlusthon/errors/rpc_errors/not_found_error.py +6 -0
- PySPlusthon/errors/rpc_errors/rpc_error.py +23 -0
- PySPlusthon/errors/rpc_errors/too_many_requests.py +10 -0
- PySPlusthon/errors/rpc_errors/unauthorized_error.py +6 -0
- PySPlusthon/event_handlers/__init__.py +12 -0
- PySPlusthon/event_handlers/callback_query_handler.py +16 -0
- PySPlusthon/event_handlers/command_handler.py +46 -0
- PySPlusthon/event_handlers/connect_handler.py +19 -0
- PySPlusthon/event_handlers/disconnect_handler.py +18 -0
- PySPlusthon/event_handlers/edited_message_handler.py +16 -0
- PySPlusthon/event_handlers/error_handler.py +15 -0
- PySPlusthon/event_handlers/event_handler.py +53 -0
- PySPlusthon/event_handlers/initialize_handler.py +18 -0
- PySPlusthon/event_handlers/message_handler.py +16 -0
- PySPlusthon/event_handlers/shipping_query_handler.py +16 -0
- PySPlusthon/event_handlers/shutdown_handler.py +18 -0
- PySPlusthon/event_handlers/update_handler.py +16 -0
- PySPlusthon/network/__init__.py +1 -0
- PySPlusthon/network/httpconnection.py +74 -0
- PySPlusthon/objects/__init__.py +43 -0
- PySPlusthon/objects/animation.py +44 -0
- PySPlusthon/objects/audio.py +36 -0
- PySPlusthon/objects/callback_query.py +37 -0
- PySPlusthon/objects/chat.py +118 -0
- PySPlusthon/objects/chat_member.py +53 -0
- PySPlusthon/objects/chat_permissions.py +26 -0
- PySPlusthon/objects/chat_photo.py +24 -0
- PySPlusthon/objects/contact.py +18 -0
- PySPlusthon/objects/date.py +35 -0
- PySPlusthon/objects/document.py +36 -0
- PySPlusthon/objects/edited_message.py +27 -0
- PySPlusthon/objects/entity.py +21 -0
- PySPlusthon/objects/file.py +21 -0
- PySPlusthon/objects/forward_origin.py +22 -0
- PySPlusthon/objects/inline_keyboard.py +65 -0
- PySPlusthon/objects/inline_keyboard_button.py +30 -0
- PySPlusthon/objects/input_media.py +44 -0
- PySPlusthon/objects/input_media_photo.py +14 -0
- PySPlusthon/objects/input_media_video.py +14 -0
- PySPlusthon/objects/invite_link.py +32 -0
- PySPlusthon/objects/list.py +24 -0
- PySPlusthon/objects/location.py +14 -0
- PySPlusthon/objects/message.py +478 -0
- PySPlusthon/objects/message_id.py +31 -0
- PySPlusthon/objects/object.py +154 -0
- PySPlusthon/objects/order_info.py +19 -0
- PySPlusthon/objects/photo.py +31 -0
- PySPlusthon/objects/poll.py +34 -0
- PySPlusthon/objects/poll_option.py +16 -0
- PySPlusthon/objects/reply_keyboard.py +79 -0
- PySPlusthon/objects/reply_keyboard_button.py +27 -0
- PySPlusthon/objects/reply_keyboard_remove.py +10 -0
- PySPlusthon/objects/reply_markup.py +12 -0
- PySPlusthon/objects/shipping_address.py +22 -0
- PySPlusthon/objects/shipping_query.py +20 -0
- PySPlusthon/objects/sticker.py +54 -0
- PySPlusthon/objects/sticker_set.py +29 -0
- PySPlusthon/objects/transaction.py +25 -0
- PySPlusthon/objects/update.py +33 -0
- PySPlusthon/objects/user.py +60 -0
- PySPlusthon/objects/video.py +45 -0
- PySPlusthon/objects/voice.py +31 -0
- PySPlusthon/objects/webhook_info.py +16 -0
- PySPlusthon/proto/__init__.py +2 -0
- PySPlusthon/proto/enums_pb2.py +46 -0
- PySPlusthon/proto/enums_pb2.pyi +99 -0
- PySPlusthon/proto/enums_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/__init__.py +209 -0
- PySPlusthon/proto/requests/abacus_pb2.py +40 -0
- PySPlusthon/proto/requests/abacus_pb2.pyi +31 -0
- PySPlusthon/proto/requests/abacus_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/auth_pb2.py +49 -0
- PySPlusthon/proto/requests/auth_pb2.pyi +67 -0
- PySPlusthon/proto/requests/auth_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/configs_pb2.py +37 -0
- PySPlusthon/proto/requests/configs_pb2.pyi +15 -0
- PySPlusthon/proto/requests/configs_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/files_pb2.py +40 -0
- PySPlusthon/proto/requests/files_pb2.pyi +34 -0
- PySPlusthon/proto/requests/files_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/groups_pb2.py +82 -0
- PySPlusthon/proto/requests/groups_pb2.pyi +213 -0
- PySPlusthon/proto/requests/groups_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/messaging_pb2.py +56 -0
- PySPlusthon/proto/requests/messaging_pb2.pyi +119 -0
- PySPlusthon/proto/requests/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/presence_pb2.py +40 -0
- PySPlusthon/proto/requests/presence_pb2.pyi +24 -0
- PySPlusthon/proto/requests/presence_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/request_pb2.py +42 -0
- PySPlusthon/proto/requests/request_pb2.pyi +35 -0
- PySPlusthon/proto/requests/request_pb2_grpc.py +24 -0
- PySPlusthon/proto/requests/users_pb2.py +43 -0
- PySPlusthon/proto/requests/users_pb2.pyi +34 -0
- PySPlusthon/proto/requests/users_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/__init__.py +6 -0
- PySPlusthon/proto/responses/abacus_pb2.py +37 -0
- PySPlusthon/proto/responses/abacus_pb2.pyi +14 -0
- PySPlusthon/proto/responses/abacus_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/auth_pb2.py +42 -0
- PySPlusthon/proto/responses/auth_pb2.pyi +40 -0
- PySPlusthon/proto/responses/auth_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/files_pb2.py +39 -0
- PySPlusthon/proto/responses/files_pb2.pyi +27 -0
- PySPlusthon/proto/responses/files_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/groups_pb2.py +59 -0
- PySPlusthon/proto/responses/groups_pb2.pyi +90 -0
- PySPlusthon/proto/responses/groups_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/messaging_pb2.py +44 -0
- PySPlusthon/proto/responses/messaging_pb2.pyi +37 -0
- PySPlusthon/proto/responses/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/responses/users_pb2.py +41 -0
- PySPlusthon/proto/responses/users_pb2.pyi +28 -0
- PySPlusthon/proto/responses/users_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/__init__.py +7 -0
- PySPlusthon/proto/structs/collections_pb2.py +54 -0
- PySPlusthon/proto/structs/collections_pb2.pyi +79 -0
- PySPlusthon/proto/structs/collections_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/files_pb2.py +52 -0
- PySPlusthon/proto/structs/files_pb2.pyi +93 -0
- PySPlusthon/proto/structs/files_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/groups_pb2.py +49 -0
- PySPlusthon/proto/structs/groups_pb2.pyi +144 -0
- PySPlusthon/proto/structs/groups_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/messaging_pb2.py +81 -0
- PySPlusthon/proto/structs/messaging_pb2.pyi +296 -0
- PySPlusthon/proto/structs/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/peers_pb2.py +47 -0
- PySPlusthon/proto/structs/peers_pb2.pyi +56 -0
- PySPlusthon/proto/structs/peers_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/set_updates_pb2.py +37 -0
- PySPlusthon/proto/structs/set_updates_pb2.pyi +15 -0
- PySPlusthon/proto/structs/set_updates_pb2_grpc.py +24 -0
- PySPlusthon/proto/structs/users_pb2.py +54 -0
- PySPlusthon/proto/structs/users_pb2.pyi +122 -0
- PySPlusthon/proto/structs/users_pb2_grpc.py +24 -0
- PySPlusthon/proto/updates/__init__.py +1 -0
- PySPlusthon/proto/updates/messaging_pb2.py +38 -0
- PySPlusthon/proto/updates/messaging_pb2.pyi +26 -0
- PySPlusthon/proto/updates/messaging_pb2_grpc.py +24 -0
- PySPlusthon/proto/ws_pb2.py +52 -0
- PySPlusthon/proto/ws_pb2.pyi +76 -0
- PySPlusthon/proto/ws_pb2_grpc.py +24 -0
- PySPlusthon/smart_call.py +73 -0
- PySPlusthon/states/__init__.py +3 -0
- PySPlusthon/states/state.py +11 -0
- PySPlusthon/states/state_group.py +13 -0
- PySPlusthon/states/state_machine.py +83 -0
- PySPlusthon/sync_support.py +48 -0
- pysplusthon-0.5.3.dist-info/METADATA +65 -0
- pysplusthon-0.5.3.dist-info/RECORD +284 -0
- pysplusthon-0.5.3.dist-info/WHEEL +5 -0
- pysplusthon-0.5.3.dist-info/licenses/LICENSE +19 -0
- pysplusthon-0.5.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,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,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)
|