From 32175f33c04b526f252d7ac9e93fa5de72ec4b91 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Sun, 7 Jul 2024 21:13:31 +0700 Subject: [PATCH 1/5] pyrofork: Update API schema to Layer 184 Signed-off-by: wulan17 --- compiler/api/source/main_api.tl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index aa2ea4e0..48d2460f 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -111,7 +111,7 @@ channel#aadfc8f flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5 channelForbidden#17d493d5 flags:# broadcast:flags.5?true megagroup:flags.8?true id:long access_hash:long title:string until_date:flags.16?int = Chat; chatFull#2633421b flags:# can_set_username:flags.7?true has_scheduled:flags.8?true translations_disabled:flags.19?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string requests_pending:flags.17?int recent_requesters:flags.17?Vector available_reactions:flags.18?ChatReactions reactions_limit:flags.20?int = ChatFull; -channelFull#bbab348d flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true participants_hidden:flags2.2?true translations_disabled:flags2.3?true stories_pinned_available:flags2.5?true view_forum_as_messages:flags2.6?true restricted_sponsored:flags2.11?true can_view_revenue:flags2.12?true paid_media_allowed:flags2.14?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions reactions_limit:flags2.13?int stories:flags2.4?PeerStories wallpaper:flags2.7?WallPaper boosts_applied:flags2.8?int boosts_unrestrict:flags2.9?int emojiset:flags2.10?StickerSet = ChatFull; +channelFull#bbab348d flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true flags2:# can_delete_channel:flags2.0?true antispam:flags2.1?true participants_hidden:flags2.2?true translations_disabled:flags2.3?true stories_pinned_available:flags2.5?true view_forum_as_messages:flags2.6?true restricted_sponsored:flags2.11?true can_view_revenue:flags2.12?true paid_media_allowed:flags2.14?true can_view_stars_revenue:flags2.15?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string requests_pending:flags.28?int recent_requesters:flags.28?Vector default_send_as:flags.29?Peer available_reactions:flags.30?ChatReactions reactions_limit:flags2.13?int stories:flags2.4?PeerStories wallpaper:flags2.7?WallPaper boosts_applied:flags2.8?int boosts_unrestrict:flags2.9?int emojiset:flags2.10?StickerSet = ChatFull; chatParticipant#c02d4007 user_id:long inviter_id:long date:int = ChatParticipant; chatParticipantCreator#e46bcee4 user_id:long = ChatParticipant; @@ -188,6 +188,7 @@ messageActionGiveawayLaunch#332ba9ed = MessageAction; messageActionGiveawayResults#2a9fadc5 winners_count:int unclaimed_count:int = MessageAction; messageActionBoostApply#cc02aa6d boosts:int = MessageAction; messageActionRequestedPeerSentMe#93b31848 button_id:int peers:Vector = MessageAction; +messageActionPaymentRefunded#41b3e202 flags:# peer:Peer currency:string total_amount:long payload:flags.0?bytes charge:PaymentCharge = MessageAction; dialog#d58a08c6 flags:# pinned:flags.2?true unread_mark:flags.3?true view_forum_as_messages:flags.6?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int unread_reactions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage folder_id:flags.4?int ttl_period:flags.5?int = Dialog; dialogFolder#71bd134c flags:# pinned:flags.2?true folder:Folder peer:Peer top_message:int unread_muted_peers_count:int unread_unmuted_peers_count:int unread_muted_messages_count:int unread_unmuted_messages_count:int = Dialog; @@ -2502,4 +2503,4 @@ smsjobs.finishJob#4f1ebf24 flags:# job_id:string error:flags.0?string = Bool; fragment.getCollectibleInfo#be1e85ba collectible:InputCollectible = fragment.CollectibleInfo; -// LAYER 183 +// LAYER 184 From 5130e0a2e52d7c8caa5c585f38377afea7832841 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Sun, 7 Jul 2024 21:18:52 +0700 Subject: [PATCH 2/5] pyrofork: Add payload parameter to send_invoice Signed-off-by: wulan17 --- pyrogram/methods/messages/send_invoice.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyrogram/methods/messages/send_invoice.py b/pyrogram/methods/messages/send_invoice.py index 6fc090a6..51308814 100644 --- a/pyrogram/methods/messages/send_invoice.py +++ b/pyrogram/methods/messages/send_invoice.py @@ -30,6 +30,7 @@ class SendInvoice: prices: List["types.LabeledPrice"], provider: str = None, provider_data: str = None, + payload: str = None, photo_url: str = None, photo_size: int = None, photo_mime_type: str = None, @@ -69,6 +70,10 @@ class SendInvoice: provider_data (``str``, *optional*): Provider data in json format. + payload (``str``, *optional*): + Bot-defined invoice payload, 1-128 bytes. + This will not be displayed to the user, use for your internal processes. + photo_url (``str``, *optional*): Photo URL. @@ -151,6 +156,10 @@ class SendInvoice: quote_entities=quote_entities ) + if payload is not None: + encoded_payload = payload.encode() + else: + encoded_payload = f"{(title)}".encode() r = await self.invoke( raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), @@ -161,7 +170,7 @@ class SendInvoice: currency=currency, prices=[price.write() for price in prices] ), - payload=f"{(title)}".encode(), + payload=encoded_payload, provider=provider, provider_data=raw.types.DataJSON(data=provider_data if provider_data else "{}"), photo=raw.types.InputWebDocument( From de5d2e747b8034dcad2c982833daed2d58d0d2e9 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Sun, 7 Jul 2024 21:22:19 +0700 Subject: [PATCH 3/5] pyrofork: fix derp in successful_payment Signed-off-by: wulan17 --- pyrogram/types/bots_and_keyboards/successful_payment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/bots_and_keyboards/successful_payment.py b/pyrogram/types/bots_and_keyboards/successful_payment.py index c0887903..b71bedd7 100644 --- a/pyrogram/types/bots_and_keyboards/successful_payment.py +++ b/pyrogram/types/bots_and_keyboards/successful_payment.py @@ -106,7 +106,7 @@ class SuccessfulPayment(Object): total_amount=successful_payment.total_amount, payload=payload, telegram_payment_charge_id=telegram_payment_charge_id, - provider_payment_charge_id=shipping_option_id, + provider_payment_charge_id=provider_payment_charge_id, shipping_option_id=shipping_option_id, payment_info=payment_info ) From 918a55de3bd2ed1c13952c28d1e67424475f36fe Mon Sep 17 00:00:00 2001 From: wulan17 Date: Sun, 7 Jul 2024 21:42:23 +0700 Subject: [PATCH 4/5] pyrofork: Add PaymentRefunded Signed-off-by: wulan17 --- compiler/docs/compiler.py | 1 + pyrogram/enums/message_service_type.py | 3 + pyrogram/types/bots_and_keyboards/__init__.py | 2 + .../bots_and_keyboards/payment_refunded.py | 82 +++++++++++++++++++ pyrogram/types/messages_and_media/message.py | 12 ++- 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/bots_and_keyboards/payment_refunded.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c5aaef30..f6479d74 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -550,6 +550,7 @@ def pyrogram_api(): BotApp BotBusinessConnection PaymentInfo + PaymentRefunded ShippingAddress ShippingOption ShippingQuery diff --git a/pyrogram/enums/message_service_type.py b/pyrogram/enums/message_service_type.py index d89cedde..5c7b9942 100644 --- a/pyrogram/enums/message_service_type.py +++ b/pyrogram/enums/message_service_type.py @@ -115,5 +115,8 @@ class MessageServiceType(AutoName): SUCCESSFUL_PAYMENT = auto() "Successful payment" + PAYMENT_REFUNDED = auto() + "Payment refunded" + BOT_ALLOWED = auto() "Bot allowed" \ No newline at end of file diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 70d2c703..5286ba28 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -45,6 +45,7 @@ from .menu_button_commands import MenuButtonCommands from .menu_button_default import MenuButtonDefault from .menu_button_web_app import MenuButtonWebApp from .payment_info import PaymentInfo +from .payment_refunded import PaymentRefunded from .pre_checkout_query import PreCheckoutQuery from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove @@ -97,6 +98,7 @@ __all__ = [ "ShippingOption", "ShippingQuery", "PaymentInfo", + "PaymentRefunded", "PreCheckoutQuery", "SuccessfulPayment" ] diff --git a/pyrogram/types/bots_and_keyboards/payment_refunded.py b/pyrogram/types/bots_and_keyboards/payment_refunded.py new file mode 100644 index 00000000..91056166 --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/payment_refunded.py @@ -0,0 +1,82 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +import pyrogram + +from pyrogram import raw +from pyrogram import types +from ..object import Object + + +class PaymentRefunded(Object): + """Contains information about a refunded payment. + + Parameters: + user (:obj:`~pyrogram.types.User`): + The user that refunded the payment. + + currency (``str``): + Three-letter ISO 4217 currency code. + + total_amount (``int``): + Total price in the smallest units of the currency. + + payload (``str``, *optional*): + Bot specified invoice payload. Only available to the bot that received the payment. + + telegram_payment_charge_id (``str``, *optional*): + Telegram payment identifier. + + provider_payment_charge_id (``str``, *optional*): + Provider payment identifier. + """ + + def __init__( + self, *, + user: "types.User", + currency: str, + total_amount: str, + telegram_payment_charge_id: str, + provider_payment_charge_id: str, + payload: str = None + ): + self.user = user + self.currency = currency + self.total_amount = total_amount + self.telegram_payment_charge_id = telegram_payment_charge_id + self.provider_payment_charge_id = provider_payment_charge_id + self.payload = payload + + @staticmethod + async def _parse( + client: "pyrogram.Client", + payment_refunded: "raw.types.MessageActionPaymentRefunded" + ) -> "PaymentRefunded": + try: + payload = payment_refunded.payload.decode() + except (UnicodeDecodeError, AttributeError): + payload = payment_refunded.payload + + return PaymentRefunded( + user=await client.get_users(payment_refunded.peer.user_id), + currency=payment_refunded.currency, + total_amount=payment_refunded.total_amount, + telegram_payment_charge_id=payment_refunded.charge.id if payment_refunded.charge.id != "" else None, + provider_payment_charge_id=payment_refunded.charge.provider_charge_id if payment_refunded.charge.provider_charge_id != "" else None, + payload=payload + ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index c18fefca..f1b56b37 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -395,6 +395,9 @@ class Message(Object, Update): successful_payment (:obj:`~pyrogram.types.SuccessfulPayment`, *optional*): Service message: successful payment. + payment_refunded (:obj:`~pyrogram.types.PaymentRefunded`, *optional*): + Service message: payment refunded. + boosts_applied (``int``, *optional*): Service message: how many boosts were applied. @@ -424,7 +427,7 @@ class Message(Object, Update): Message is a scheduled message and has been sent. """ - # TODO: Add game missing field. Also invoice, successful_payment, connected_website + # TODO: Add game missing field, Also connected_website def __init__( self, @@ -530,6 +533,7 @@ class Message(Object, Update): video_chat_members_invited: "types.VideoChatMembersInvited" = None, web_app_data: "types.WebAppData" = None, successful_payment: "types.SuccessfulPayment" = None, + payment_refunded: "types.PaymentRefunded" = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -642,6 +646,7 @@ class Message(Object, Update): self.video_chat_members_invited = video_chat_members_invited self.web_app_data = web_app_data self.successful_payment = successful_payment + self.payment_refunded = payment_refunded self.reactions = reactions self.raw = raw @@ -749,6 +754,7 @@ class Message(Object, Update): giveaway_launched = None giveaway_result = None successful_payment = None + payment_refunded = None boosts_applied = None service_type = None @@ -856,6 +862,9 @@ class Message(Object, Update): elif isinstance(action, (raw.types.MessageActionPaymentSent, raw.types.MessageActionPaymentSentMe)): successful_payment = types.SuccessfulPayment._parse(client, action) service_type = enums.MessageServiceType.SUCCESSFUL_PAYMENT + elif isinstance(action, raw.types.MessageActionPaymentRefunded): + payment_refunded = await types.PaymentRefunded._parse(client, action) + service_type = enums.MessageServiceType.PAYMENT_REFUNDED parsed_message = Message( id=message.id, @@ -894,6 +903,7 @@ class Message(Object, Update): giveaway_launched=giveaway_launched, giveaway_result=giveaway_result, successful_payment=successful_payment, + payment_refunded=payment_refunded, boosts_applied=boosts_applied, raw=message, client=client From 30dad015aed4a97c9884ab1e9b8228d72d94892c Mon Sep 17 00:00:00 2001 From: wulan17 Date: Sun, 7 Jul 2024 21:52:50 +0700 Subject: [PATCH 5/5] pyrofork: Bump version to 2.3.32 Signed-off-by: wulan17 --- pyrogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index e1c1c869..6a9e4b04 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -18,7 +18,7 @@ # along with Pyrofork. If not, see . __fork_name__ = "PyroFork" -__version__ = "2.3.31" +__version__ = "2.3.32" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __copyright__ = "Copyright (C) 2022-present Mayuri-Chan "