Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Sep 4, 2024
1 parent 2683e04 commit f05e333
Show file tree
Hide file tree
Showing 22 changed files with 1,044 additions and 20 deletions.
12 changes: 12 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def get_title_list(s: str) -> list:
""",
payments="""
Payments
apply_gift_code
check_gift_code
get_payment_form
send_payment_form
Expand Down Expand Up @@ -355,6 +356,7 @@ def get_title_list(s: str) -> list:
get_chat_menu_button
answer_web_app_query
answer_pre_checkout_query
answer_shipping_query
create_invoice_link
refund_star_payment
""",
Expand Down Expand Up @@ -535,6 +537,7 @@ def get_title_list(s: str) -> list:
PaidMediaInfo
PaidMediaPreview
PaymentForm
ChatBoost
""",
bot_keyboards="""
Bot keyboards
Expand Down Expand Up @@ -562,6 +565,11 @@ def get_title_list(s: str) -> list:
OrderInfo
PreCheckoutQuery
ShippingAddress
ShippingQuery
MessageReactionUpdated
MessageReactionCountUpdated
ChatBoostUpdated
ShippingOption
""",
bot_commands="""
Bot commands
Expand Down Expand Up @@ -751,6 +759,10 @@ def get_title_list(s: str) -> list:
PreCheckoutQuery
PreCheckoutQuery.answer
""",
shipping_query="""
ShippingQuery
ShippingQuery.answer
""",
chat_join_request="""
ChatJoinRequest
ChatJoinRequest.approve
Expand Down
46 changes: 40 additions & 6 deletions pyrogram/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from pyrogram.handlers import (
CallbackQueryHandler, MessageHandler, EditedMessageHandler, DeletedMessagesHandler,
UserStatusHandler, RawUpdateHandler, InlineQueryHandler, PollHandler, PreCheckoutQueryHandler,
ChosenInlineResultHandler, ChatMemberUpdatedHandler, ChatJoinRequestHandler, StoryHandler
ChosenInlineResultHandler, ChatMemberUpdatedHandler, ChatJoinRequestHandler, StoryHandler,
ShippingQueryHandler, MessageReactionHandler, MessageReactionCountHandler, ChatBoostHandler
)
from pyrogram.raw.types import (
UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage,
Expand All @@ -38,7 +39,8 @@
UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery, UpdateBotPrecheckoutQuery,
UpdateUserStatus, UpdateBotInlineQuery, UpdateMessagePoll,
UpdateBotInlineSend, UpdateChatParticipant, UpdateChannelParticipant,
UpdateBotChatInviteRequester, UpdateStory
UpdateBotChatInviteRequester, UpdateStory, UpdateBotShippingQuery, UpdateBotMessageReaction,
UpdateBotMessageReactions, UpdateBotChatBoost, UpdateBusinessBotCallbackQuery
)

log = logging.getLogger(__name__)
Expand All @@ -48,7 +50,7 @@ class Dispatcher:
NEW_MESSAGE_UPDATES = (UpdateNewMessage, UpdateNewChannelMessage, UpdateNewScheduledMessage, UpdateBotNewBusinessMessage)
EDIT_MESSAGE_UPDATES = (UpdateEditMessage, UpdateEditChannelMessage, UpdateBotEditBusinessMessage)
DELETE_MESSAGES_UPDATES = (UpdateDeleteMessages, UpdateDeleteChannelMessages, UpdateBotDeleteBusinessMessage)
CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery)
CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery, UpdateBusinessBotCallbackQuery)
CHAT_MEMBER_UPDATES = (UpdateChatParticipant, UpdateChannelParticipant)
USER_STATUS_UPDATES = (UpdateUserStatus,)
BOT_INLINE_QUERY_UPDATES = (UpdateBotInlineQuery,)
Expand All @@ -57,6 +59,10 @@ class Dispatcher:
CHAT_JOIN_REQUEST_UPDATES = (UpdateBotChatInviteRequester,)
NEW_STORY_UPDATES = (UpdateStory,)
PRE_CHECKOUT_QUERY_UPDATES = (UpdateBotPrecheckoutQuery,)
SHIPPING_QUERY_UPDATES = (UpdateBotShippingQuery,)
MESSAGE_REACTION_UPDATES = (UpdateBotMessageReaction,)
MESSAGE_REACTION_COUNT_UPDATES = (UpdateBotMessageReactions,)
CHAT_BOOST_UPDATES = (UpdateBotChatBoost,)

def __init__(self, client: "pyrogram.Client"):
self.client = client
Expand All @@ -70,7 +76,7 @@ def __init__(self, client: "pyrogram.Client"):

async def message_parser(update, users, chats):
connection_id = getattr(update, "connection_id", None)

return (
await pyrogram.types.Message._parse(
self.client,
Expand Down Expand Up @@ -102,7 +108,7 @@ async def deleted_messages_parser(update, users, chats):

async def callback_query_parser(update, users, chats):
return (
await pyrogram.types.CallbackQuery._parse(self.client, update, users),
await pyrogram.types.CallbackQuery._parse(self.client, update, users, chats),
CallbackQueryHandler
)

Expand Down Expand Up @@ -154,6 +160,30 @@ async def pre_checkout_query_parser(update, users, chats):
PreCheckoutQueryHandler
)

async def shipping_query_parser(update, users, chats):
return (
await pyrogram.types.ShippingQuery._parse(self.client, update, users),
ShippingQueryHandler
)

async def message_reaction_parser(update, users, chats):
return (
pyrogram.types.MessageReactionUpdated._parse(self.client, update, users, chats),
MessageReactionHandler
)

async def message_reaction_count_parser(update, users, chats):
return (
pyrogram.types.MessageReactionCountUpdated._parse(self.client, update, users, chats),
MessageReactionCountHandler
)

async def chat_boost_parser(update, users, chats):
return (
pyrogram.types.ChatBoostUpdated._parse(self.client, update, users, chats),
ChatBoostHandler
)

self.update_parsers = {
Dispatcher.NEW_MESSAGE_UPDATES: message_parser,
Dispatcher.EDIT_MESSAGE_UPDATES: edited_message_parser,
Expand All @@ -166,7 +196,11 @@ async def pre_checkout_query_parser(update, users, chats):
Dispatcher.CHAT_MEMBER_UPDATES: chat_member_updated_parser,
Dispatcher.CHAT_JOIN_REQUEST_UPDATES: chat_join_request_parser,
Dispatcher.NEW_STORY_UPDATES: story_parser,
Dispatcher.PRE_CHECKOUT_QUERY_UPDATES: pre_checkout_query_parser
Dispatcher.PRE_CHECKOUT_QUERY_UPDATES: pre_checkout_query_parser,
Dispatcher.SHIPPING_QUERY_UPDATES: shipping_query_parser,
Dispatcher.MESSAGE_REACTION_UPDATES: message_reaction_parser,
Dispatcher.MESSAGE_REACTION_COUNT_UPDATES: message_reaction_count_parser,
Dispatcher.CHAT_BOOST_UPDATES: chat_boost_parser
}

self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}
Expand Down
4 changes: 4 additions & 0 deletions pyrogram/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from .callback_query_handler import CallbackQueryHandler
from .chat_boost_handler import ChatBoostHandler
from .chat_join_request_handler import ChatJoinRequestHandler
from .chat_member_updated_handler import ChatMemberUpdatedHandler
from .chosen_inline_result_handler import ChosenInlineResultHandler
Expand All @@ -25,8 +26,11 @@
from .edited_message_handler import EditedMessageHandler
from .inline_query_handler import InlineQueryHandler
from .message_handler import MessageHandler
from .message_reaction_count_handler import MessageReactionCountHandler
from .message_reaction_handler import MessageReactionHandler
from .poll_handler import PollHandler
from .pre_checkout_query_handler import PreCheckoutQueryHandler
from .raw_update_handler import RawUpdateHandler
from .shipping_query_handler import ShippingQueryHandler
from .story_handler import StoryHandler
from .user_status_handler import UserStatusHandler
49 changes: 49 additions & 0 deletions pyrogram/handlers/chat_boost_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable

from .handler import Handler


class ChatBoostHandler(Handler):
"""The Story handler class. Used to handle new stories.
It is intended to be used with :meth:`~pyrogram.Client.add_handler`
For a nicer way to register this handler, have a look at the
:meth:`~pyrogram.Client.on_story` decorator.
Parameters:
callback (``Callable``):
Pass a function that will be called when a new Stories arrives. It takes *(client, story)*
as positional arguments (look at the section below for a detailed description).
filters (:obj:`Filters`):
Pass one or more filters to allow only a subset of stories to be passed
in your callback function.
Other parameters:
client (:obj:`~pyrogram.Client`):
The Client itself, useful when you want to call other API methods inside the story handler.
story (:obj:`~pyrogram.types.Story`):
The received story.
"""

def __init__(self, callback: Callable, filters=None):
super().__init__(callback, filters)
49 changes: 49 additions & 0 deletions pyrogram/handlers/message_reaction_count_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable

from .handler import Handler


class MessageReactionCountHandler(Handler):
"""The Story handler class. Used to handle new stories.
It is intended to be used with :meth:`~pyrogram.Client.add_handler`
For a nicer way to register this handler, have a look at the
:meth:`~pyrogram.Client.on_story` decorator.
Parameters:
callback (``Callable``):
Pass a function that will be called when a new Stories arrives. It takes *(client, story)*
as positional arguments (look at the section below for a detailed description).
filters (:obj:`Filters`):
Pass one or more filters to allow only a subset of stories to be passed
in your callback function.
Other parameters:
client (:obj:`~pyrogram.Client`):
The Client itself, useful when you want to call other API methods inside the story handler.
story (:obj:`~pyrogram.types.Story`):
The received story.
"""

def __init__(self, callback: Callable, filters=None):
super().__init__(callback, filters)
49 changes: 49 additions & 0 deletions pyrogram/handlers/message_reaction_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable

from .handler import Handler


class MessageReactionHandler(Handler):
"""The Story handler class. Used to handle new stories.
It is intended to be used with :meth:`~pyrogram.Client.add_handler`
For a nicer way to register this handler, have a look at the
:meth:`~pyrogram.Client.on_story` decorator.
Parameters:
callback (``Callable``):
Pass a function that will be called when a new Stories arrives. It takes *(client, story)*
as positional arguments (look at the section below for a detailed description).
filters (:obj:`Filters`):
Pass one or more filters to allow only a subset of stories to be passed
in your callback function.
Other parameters:
client (:obj:`~pyrogram.Client`):
The Client itself, useful when you want to call other API methods inside the story handler.
story (:obj:`~pyrogram.types.Story`):
The received story.
"""

def __init__(self, callback: Callable, filters=None):
super().__init__(callback, filters)
49 changes: 49 additions & 0 deletions pyrogram/handlers/shipping_query_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable

from .handler import Handler


class ShippingQueryHandler(Handler):
"""The Story handler class. Used to handle new stories.
It is intended to be used with :meth:`~pyrogram.Client.add_handler`
For a nicer way to register this handler, have a look at the
:meth:`~pyrogram.Client.on_story` decorator.
Parameters:
callback (``Callable``):
Pass a function that will be called when a new Stories arrives. It takes *(client, story)*
as positional arguments (look at the section below for a detailed description).
filters (:obj:`Filters`):
Pass one or more filters to allow only a subset of stories to be passed
in your callback function.
Other parameters:
client (:obj:`~pyrogram.Client`):
The Client itself, useful when you want to call other API methods inside the story handler.
story (:obj:`~pyrogram.types.Story`):
The received story.
"""

def __init__(self, callback: Callable, filters=None):
super().__init__(callback, filters)
6 changes: 4 additions & 2 deletions pyrogram/methods/bots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .answer_callback_query import AnswerCallbackQuery
from .answer_inline_query import AnswerInlineQuery
from .answer_pre_checkout_query import AnswerPreCheckoutQuery
from .answer_shipping_query import AnswerShippingQuery
from .answer_web_app_query import AnswerWebAppQuery
from .create_invoice_link import CreateInvoiceLink
from .delete_bot_commands import DeleteBotCommands
Expand All @@ -41,6 +42,8 @@
class Bots(
AnswerCallbackQuery,
AnswerInlineQuery,
AnswerPreCheckoutQuery,
AnswerShippingQuery,
CreateInvoiceLink,
GetInlineBotResults,
RefundStarPayment,
Expand All @@ -57,7 +60,6 @@ class Bots(
GetBotDefaultPrivileges,
SetChatMenuButton,
GetChatMenuButton,
AnswerWebAppQuery,
AnswerPreCheckoutQuery
AnswerWebAppQuery
):
pass
Loading

0 comments on commit f05e333

Please sign in to comment.