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,16 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
import PySPlusthon
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CreateNewStickerSet:
|
|
7
|
+
|
|
8
|
+
async def create_new_sticker_set(
|
|
9
|
+
self: "PySPlusthon.Client",
|
|
10
|
+
user_id: Union[int, str],
|
|
11
|
+
name: str,
|
|
12
|
+
title: str,
|
|
13
|
+
sticker=None
|
|
14
|
+
) -> bool:
|
|
15
|
+
user_id = await self.resolve_peer_id(user_id)
|
|
16
|
+
return await self.auto_execute("createNewStickerSet", locals())
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Union, BinaryIO
|
|
2
|
+
|
|
3
|
+
import PySPlusthon
|
|
4
|
+
from ...objects import InputMedia, resolve_media
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class UploadStickerFile:
|
|
8
|
+
|
|
9
|
+
async def upload_sticker_file(
|
|
10
|
+
self: "PySPlusthon.Client",
|
|
11
|
+
user_id: Union[int, str],
|
|
12
|
+
sticker: Union[str, bytes, BinaryIO, InputMedia]
|
|
13
|
+
) -> str:
|
|
14
|
+
user_id = await self.resolve_peer_id(user_id)
|
|
15
|
+
sticker = resolve_media(sticker)
|
|
16
|
+
return await self.auto_execute("uploadStickerFile", locals())
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
import PySPlusthon
|
|
4
|
+
from ...objects import Update
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GetUpdates:
|
|
8
|
+
|
|
9
|
+
async def get_updates(
|
|
10
|
+
self: "PySPlusthon.Client",
|
|
11
|
+
offset: int = None,
|
|
12
|
+
limit: int = None
|
|
13
|
+
) -> List[Update]:
|
|
14
|
+
return await self.auto_execute("getUpdates", locals())
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
import PySPlusthon
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AskReview:
|
|
7
|
+
|
|
8
|
+
async def ask_review(
|
|
9
|
+
self: "PySPlusthon.Client",
|
|
10
|
+
user_id: Union[int, str],
|
|
11
|
+
delay_seconds: int = 0
|
|
12
|
+
) -> bool:
|
|
13
|
+
user_id = await self.resolve_peer_id(user_id)
|
|
14
|
+
return await self.auto_execute("askReview", locals())
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import PySPlusthon
|
|
2
|
+
from ...objects import User
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class GetMe:
|
|
6
|
+
|
|
7
|
+
async def get_me(
|
|
8
|
+
self: "PySPlusthon.Client"
|
|
9
|
+
) -> User:
|
|
10
|
+
if self.is_userbot():
|
|
11
|
+
jwt = self.load_session()
|
|
12
|
+
data = self.decode_jwt(jwt)
|
|
13
|
+
my_id = data["payload"]["payload"]["user_id"]
|
|
14
|
+
return await self.get_chat(f"{my_id}|1")
|
|
15
|
+
|
|
16
|
+
return await self.auto_execute("getMe", locals())
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from .condition import Condition, AllCondition, AnyCondition, NotCondition, create
|
|
2
|
+
from .all import all
|
|
3
|
+
from .forward import forward
|
|
4
|
+
from .reply import reply
|
|
5
|
+
from .text import text
|
|
6
|
+
from .entities import entities
|
|
7
|
+
from .document import document
|
|
8
|
+
from .photo import photo
|
|
9
|
+
from .video import video
|
|
10
|
+
from .voice import voice
|
|
11
|
+
from .caption import caption
|
|
12
|
+
from .contact import contact
|
|
13
|
+
from .location import location
|
|
14
|
+
from .new_chat_members import new_chat_members
|
|
15
|
+
from .left_chat_member import left_chat_member
|
|
16
|
+
from .new_chat_title import new_chat_title
|
|
17
|
+
from .new_chat_photo import new_chat_photo
|
|
18
|
+
from .delete_chat_photo import delete_chat_photo
|
|
19
|
+
from .group_chat_created import group_chat_created
|
|
20
|
+
from .supergroup_chat_created import supergroup_chat_created
|
|
21
|
+
from .channel_chat_created import channel_chat_created
|
|
22
|
+
from .pinned_message import pinned_message
|
|
23
|
+
from .media import media
|
|
24
|
+
from .command import Command as command
|
|
25
|
+
from .private import private
|
|
26
|
+
from .group import group
|
|
27
|
+
from .channel import channel
|
|
28
|
+
from .regex import Regex as regex
|
|
29
|
+
from .at_state import AtState as at_state
|
|
30
|
+
from .is_instance import IsInstance as is_instance
|
|
31
|
+
from .chat import Chat as chat
|
|
32
|
+
from .is_joined import IsJoined as is_joined
|
|
33
|
+
from .is_admin import IsAdmin as is_admin
|
|
34
|
+
from .author import Author as author
|
|
35
|
+
from .equals import Equals as equals
|
|
36
|
+
from .content import content
|
|
37
|
+
from .media_group import media_group
|
|
38
|
+
from .sticker import sticker
|
|
39
|
+
from .number import number
|
|
40
|
+
from .click import Click as click
|
|
41
|
+
from .audio import audio
|
|
42
|
+
from .animation import animation
|
|
43
|
+
from .poll import poll
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from .condition import Condition
|
|
2
|
+
from ..objects import Message, CallbackQuery
|
|
3
|
+
from ..states import State
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AtState(Condition):
|
|
7
|
+
def __init__(self, state, state_machine=None):
|
|
8
|
+
super().__init__(can_process=(Message, CallbackQuery))
|
|
9
|
+
self.state = str(state) if isinstance(state, State) else state
|
|
10
|
+
self.state_machine = state_machine
|
|
11
|
+
|
|
12
|
+
async def process(self, client, event) -> bool:
|
|
13
|
+
if not event.author:
|
|
14
|
+
return False
|
|
15
|
+
if self.state_machine is None:
|
|
16
|
+
return event.author.get_state() == self.state
|
|
17
|
+
else:
|
|
18
|
+
return self.state_machine[event.author.id] == self.state
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .condition import Condition
|
|
2
|
+
from ..objects import Message, CallbackQuery
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Author(Condition):
|
|
6
|
+
def __init__(self, *authors):
|
|
7
|
+
super().__init__(can_process=(Message, CallbackQuery))
|
|
8
|
+
self.authors = set(authors)
|
|
9
|
+
|
|
10
|
+
async def process(self, client, event) -> bool:
|
|
11
|
+
if not event.author:
|
|
12
|
+
return False
|
|
13
|
+
return event.author.id in self.authors
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .condition import create
|
|
2
|
+
from ..objects import Message, CallbackQuery
|
|
3
|
+
from ..enums import ChatType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@create(can_process=(Message, CallbackQuery))
|
|
7
|
+
def channel(event) -> bool:
|
|
8
|
+
if isinstance(event, Message):
|
|
9
|
+
return event.chat.type == ChatType.CHANNEL
|
|
10
|
+
elif isinstance(event, CallbackQuery):
|
|
11
|
+
return event.message.chat.type == ChatType.CHANNEL
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .condition import Condition
|
|
2
|
+
from ..objects import Message, CallbackQuery
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Chat(Condition):
|
|
6
|
+
def __init__(self, *chats):
|
|
7
|
+
super().__init__(can_process=(Message, CallbackQuery))
|
|
8
|
+
self.chats = set(chats)
|
|
9
|
+
|
|
10
|
+
async def process(self, client, event) -> bool:
|
|
11
|
+
if isinstance(event, Message):
|
|
12
|
+
return event.chat.id in self.chats
|
|
13
|
+
elif isinstance(event, CallbackQuery):
|
|
14
|
+
return event.message.chat.id in self.chats
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from .condition import Condition
|
|
4
|
+
from ..objects import Message, CallbackQuery, ReplyKeyboard, InlineKeyboard
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Click(Condition):
|
|
8
|
+
def __init__(self, keyboard, row_index: int, button_index: int):
|
|
9
|
+
super().__init__(can_process=(Message, CallbackQuery))
|
|
10
|
+
self.keyboard = keyboard
|
|
11
|
+
self.row_index = row_index
|
|
12
|
+
self.button_index = button_index
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def create_regex(text):
|
|
16
|
+
return "^" + re.sub(r"{.*?}", ".*", text) + "$"
|
|
17
|
+
|
|
18
|
+
async def process(self, client, event) -> bool:
|
|
19
|
+
if isinstance(self.keyboard, ReplyKeyboard) and isinstance(event, Message):
|
|
20
|
+
button = self.keyboard.keyboard[self.row_index][self.button_index]
|
|
21
|
+
return bool(re.match(self.create_regex(button.text), event.text))
|
|
22
|
+
elif isinstance(self.keyboard, InlineKeyboard) and isinstance(event, CallbackQuery):
|
|
23
|
+
button = self.keyboard.inline_keyboard[self.row_index][self.button_index]
|
|
24
|
+
return bool(re.match(self.create_regex(button.callback_data), event.data))
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .condition import Condition
|
|
2
|
+
from ..objects import Message
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Command(Condition):
|
|
6
|
+
def __init__(self, name, prefix="/", min_arguments=None, max_arguments=None):
|
|
7
|
+
super().__init__(can_process=Message)
|
|
8
|
+
self.name = name
|
|
9
|
+
self.prefix = prefix
|
|
10
|
+
self.min_arguments = min_arguments
|
|
11
|
+
self.max_arguments = max_arguments
|
|
12
|
+
|
|
13
|
+
async def process(self, client, event) -> bool:
|
|
14
|
+
if not event.text:
|
|
15
|
+
return False
|
|
16
|
+
name, *arguments = event.text.split()
|
|
17
|
+
if name.lower() != f"{self.prefix}{self.name.lower()}":
|
|
18
|
+
return False
|
|
19
|
+
if self.min_arguments is not None and len(arguments) < self.min_arguments:
|
|
20
|
+
return False
|
|
21
|
+
if self.max_arguments is not None and len(arguments) > self.max_arguments:
|
|
22
|
+
return False
|
|
23
|
+
return True
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from inspect import iscoroutinefunction
|
|
2
|
+
|
|
3
|
+
from ..smart_call import remove_unwanted_keyword_parameters
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Condition:
|
|
7
|
+
def __init__(self, function=None, can_process=None):
|
|
8
|
+
self.function = function
|
|
9
|
+
self.can_process = can_process
|
|
10
|
+
|
|
11
|
+
def is_not_processable(self, event):
|
|
12
|
+
return self.can_process is not None and not isinstance(event, self.can_process)
|
|
13
|
+
|
|
14
|
+
async def __call__(self, client, event) -> bool:
|
|
15
|
+
if self.is_not_processable(event):
|
|
16
|
+
return False
|
|
17
|
+
return await self.process(client, event)
|
|
18
|
+
|
|
19
|
+
async def process(self, client, event) -> bool:
|
|
20
|
+
kwargs = dict(condition=self, client=client, event=event)
|
|
21
|
+
kwargs = remove_unwanted_keyword_parameters(self.function, **kwargs)
|
|
22
|
+
if iscoroutinefunction(self.function):
|
|
23
|
+
return await self.function(**kwargs)
|
|
24
|
+
return self.function(**kwargs)
|
|
25
|
+
|
|
26
|
+
def __and__(self, other):
|
|
27
|
+
return AllCondition(self, other)
|
|
28
|
+
|
|
29
|
+
def __or__(self, other):
|
|
30
|
+
return AnyCondition(self, other)
|
|
31
|
+
|
|
32
|
+
def __invert__(self):
|
|
33
|
+
return NotCondition(self)
|
|
34
|
+
|
|
35
|
+
def __repr__(self):
|
|
36
|
+
return type(self).__name__
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class AllCondition(Condition):
|
|
40
|
+
def __init__(self, *conditions):
|
|
41
|
+
super().__init__()
|
|
42
|
+
self.conditions = conditions
|
|
43
|
+
|
|
44
|
+
async def __call__(self, client, event) -> bool:
|
|
45
|
+
for condition in self.conditions:
|
|
46
|
+
if not await condition(client, event):
|
|
47
|
+
return False
|
|
48
|
+
return True
|
|
49
|
+
|
|
50
|
+
def __repr__(self):
|
|
51
|
+
conditions_string = ", ".join(map(str, self.conditions))
|
|
52
|
+
return f"All({conditions_string})"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class AnyCondition(Condition):
|
|
56
|
+
def __init__(self, *conditions):
|
|
57
|
+
super().__init__()
|
|
58
|
+
self.conditions = conditions
|
|
59
|
+
|
|
60
|
+
async def __call__(self, client, event) -> bool:
|
|
61
|
+
for condition in self.conditions:
|
|
62
|
+
if await condition(client, event):
|
|
63
|
+
return True
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
def __repr__(self):
|
|
67
|
+
conditions_string = ", ".join(map(str, self.conditions))
|
|
68
|
+
return f"Any({conditions_string})"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class NotCondition(Condition):
|
|
72
|
+
def __init__(self, condition):
|
|
73
|
+
super().__init__()
|
|
74
|
+
self.condition = condition
|
|
75
|
+
|
|
76
|
+
async def __call__(self, client, event) -> bool:
|
|
77
|
+
return not await self.condition(client, event)
|
|
78
|
+
|
|
79
|
+
def __repr__(self):
|
|
80
|
+
return f"Not({self.condition})"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def create(name: str = None, can_process=None):
|
|
84
|
+
def decorator(function):
|
|
85
|
+
CustomCondition = type(name or function.__name__ or "CustomCondition", (Condition,), {})
|
|
86
|
+
return CustomCondition(function, can_process)
|
|
87
|
+
|
|
88
|
+
return decorator
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .condition import Condition
|
|
2
|
+
from ..objects import Message, CallbackQuery
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Equals(Condition):
|
|
6
|
+
def __init__(self, *values):
|
|
7
|
+
super().__init__(can_process=(Message, CallbackQuery))
|
|
8
|
+
self.values = values
|
|
9
|
+
|
|
10
|
+
async def process(self, client, event) -> bool:
|
|
11
|
+
if isinstance(event, Message):
|
|
12
|
+
return event.content in self.values
|
|
13
|
+
elif isinstance(event, CallbackQuery):
|
|
14
|
+
return event.data in self.values
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .condition import create
|
|
2
|
+
from ..objects import Message, CallbackQuery
|
|
3
|
+
from ..enums import ChatType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@create(can_process=(Message, CallbackQuery))
|
|
7
|
+
def group(event) -> bool:
|
|
8
|
+
if isinstance(event, Message):
|
|
9
|
+
return event.chat.type == ChatType.GROUP
|
|
10
|
+
elif isinstance(event, CallbackQuery):
|
|
11
|
+
return event.message.chat.type == ChatType.GROUP
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from typing import Union, Tuple
|
|
2
|
+
|
|
3
|
+
from .is_joined import IsJoined
|
|
4
|
+
from ..enums import ChatMemberStatus
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class IsAdmin(IsJoined):
|
|
8
|
+
ACCEPTED_STATUSES = ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.CREATOR
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
*chat_ids: Union[int, str],
|
|
13
|
+
accepted_statuses: Tuple[str, ...] = None,
|
|
14
|
+
source_chat: bool = False
|
|
15
|
+
):
|
|
16
|
+
super().__init__(*chat_ids, accepted_statuses=accepted_statuses)
|
|
17
|
+
self.source_chat = source_chat
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from typing import Union, Tuple
|
|
2
|
+
from copy import copy
|
|
3
|
+
|
|
4
|
+
from .condition import Condition
|
|
5
|
+
from ..objects import Message, CallbackQuery
|
|
6
|
+
from ..enums import ChatMemberStatus
|
|
7
|
+
from ..errors import RPCError, ForbiddenError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class IsJoined(Condition):
|
|
11
|
+
ACCEPTED_STATUSES = ChatMemberStatus.MEMBER, ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.CREATOR
|
|
12
|
+
|
|
13
|
+
def __init__(self, *chat_ids: Union[int, str], accepted_statuses: Tuple[str, ...] = None):
|
|
14
|
+
super().__init__(can_process=(Message, CallbackQuery))
|
|
15
|
+
self.chat_ids = list(chat_ids)
|
|
16
|
+
self.chats = []
|
|
17
|
+
self.accepted_statuses = accepted_statuses or self.ACCEPTED_STATUSES
|
|
18
|
+
self.source_chat = False
|
|
19
|
+
|
|
20
|
+
async def update_chats(self, client):
|
|
21
|
+
self.chats = []
|
|
22
|
+
for chat_id in self.chat_ids:
|
|
23
|
+
chat = await client.get_chat(chat_id)
|
|
24
|
+
self.chats.append(chat)
|
|
25
|
+
self.chat_ids = [chat.id for chat in self.chats]
|
|
26
|
+
|
|
27
|
+
async def add_chat(self, client, chat_id):
|
|
28
|
+
chat = await client.get_chat(chat_id)
|
|
29
|
+
self.chats.append(chat)
|
|
30
|
+
self.chat_ids.append(chat.id)
|
|
31
|
+
return chat
|
|
32
|
+
|
|
33
|
+
async def remove_chat(self, client, chat_id):
|
|
34
|
+
chat = await client.get_chat(chat_id)
|
|
35
|
+
for c in self.chats:
|
|
36
|
+
if c.id == chat.id:
|
|
37
|
+
index = self.chats.index(c)
|
|
38
|
+
self.chats.pop(index)
|
|
39
|
+
self.chat_ids.remove(chat.id)
|
|
40
|
+
return chat
|
|
41
|
+
|
|
42
|
+
async def process(self, client, event) -> bool:
|
|
43
|
+
if self.chat_ids and not self.chats:
|
|
44
|
+
await self.update_chats(client)
|
|
45
|
+
if not event.author:
|
|
46
|
+
return False
|
|
47
|
+
chats = copy(self.chats)
|
|
48
|
+
if self.source_chat:
|
|
49
|
+
chats.append(event.chat if isinstance(event, Message) else event.message.chat)
|
|
50
|
+
event.not_accepted_chats = []
|
|
51
|
+
for chat in chats:
|
|
52
|
+
try:
|
|
53
|
+
chat_member = await client.get_chat_member(chat.id, event.author.id)
|
|
54
|
+
except ForbiddenError as error:
|
|
55
|
+
raise error
|
|
56
|
+
except RPCError:
|
|
57
|
+
event.not_accepted_chats.append(chat)
|
|
58
|
+
else:
|
|
59
|
+
if chat_member.status not in self.accepted_statuses:
|
|
60
|
+
event.not_accepted_chats.append(chat)
|
|
61
|
+
return not bool(event.not_accepted_chats)
|