diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 0bad6380..1abd1a26 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -472,6 +472,7 @@ def pyrogram_api(): Sticker StickerSet Game + GiftedPremium Giveaway GiveawayLaunched GiveawayResult diff --git a/pyrogram/enums/message_service_type.py b/pyrogram/enums/message_service_type.py index 70bb94e0..bffa77fe 100644 --- a/pyrogram/enums/message_service_type.py +++ b/pyrogram/enums/message_service_type.py @@ -100,6 +100,9 @@ class MessageServiceType(AutoName): WEB_APP_DATA = auto() "Web app data" + GIFTED_PREMIUM = auto() + "Gifted Premium" + GIVEAWAY_LAUNCHED = auto() "Giveaway Launch" diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 890a3fe5..8abad8fc 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -23,6 +23,7 @@ from .contact import Contact from .dice import Dice from .document import Document from .game import Game +from .gifted_premium import GiftedPremium from .giveaway import Giveaway from .giveaway_launched import GiveawayLaunched from .giveaway_result import GiveawayResult @@ -63,7 +64,7 @@ from .story_views import StoryViews from .exported_story_link import ExportedStoryLink __all__ = [ - "Animation", "Audio", "Contact", "Document", "Game", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail", + "Animation", "Audio", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice", "Reaction", "WebAppData", "MessageReactions", "ReactionCount", "ReactionType", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink" ] diff --git a/pyrogram/types/messages_and_media/gifted_premium.py b/pyrogram/types/messages_and_media/gifted_premium.py new file mode 100644 index 00000000..6119b67a --- /dev/null +++ b/pyrogram/types/messages_and_media/gifted_premium.py @@ -0,0 +1,93 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# 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 . + +from random import choice + +from pyrogram import raw, types +from ..object import Object + + +class GiftedPremium(Object): + """Telegram Premium was gifted to the user + + Parameters: + gifter_user_id (``int``): + The identifier of a user that gifted Telegram Premium; 0 if the gift was anonymous + + currency (``str``): + Currency for the paid amount + + amount (``int``): + The paid amount, in the smallest units of the currency + + cryptocurrency (``str``): + Cryptocurrency used to pay for the gift; may be empty if none + + cryptocurrency_amount (``int``): + The paid amount, in the smallest units of the cryptocurrency; 0 if none + + month_count (``int``): + Number of months the Telegram Premium subscription will be active + + sticker (:obj:`~pyrogram.types.Sticker`): + A sticker to be shown in the message; may be null if unknown + + """ + + def __init__( + self, + *, + gifter_user_id: int = None, + currency: str = None, + amount: int = None, + cryptocurrency: str = None, + cryptocurrency_amount: int = None, + month_count: int = None, + sticker: "types.Sticker" = None, + ): + super().__init__() + + self.gifter_user_id = gifter_user_id + self.currency = currency + self.amount = amount + self.cryptocurrency = cryptocurrency + self.cryptocurrency_amount = cryptocurrency_amount + self.month_count = month_count + self.sticker = sticker + + @staticmethod + async def _parse( + client, + gifted_premium: "raw.types.MessageActionGiftPremium", + gifter_user_id: int + ) -> "GiftedPremium": + sticker = None + stickers, _ = await client._get_raw_stickers( + raw.types.InputStickerSetPremiumGifts() + ) + sticker = choice(stickers) + return GiftedPremium( + gifter_user_id=gifter_user_id, + currency=gifted_premium.currency, + amount=gifted_premium.amount, + cryptocurrency=getattr(gifted_premium, "crypto_currency", None), + cryptocurrency_amount=getattr(gifted_premium, "crypto_amount", None), + month_count=gifted_premium.months, + sticker=sticker + ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index e528acf4..f282f7c6 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -358,6 +358,9 @@ class Message(Object, Update): general_topic_unhidden (:obj:`~pyrogram.types.GeneralTopicUnhidden`, *optional*): Service message: forum general topic unhidden + gifted_premium (:obj:`~pyrogram.types.GiftedPremium`, *optional*): + Info about a gifted Telegram Premium subscription + giveaway_launcheded (:obj:`~pyrogram.types.GiveawayLaunched`, *optional*): Service message: giveaway launched. @@ -389,6 +392,12 @@ class Message(Object, Update): raw (``pyrogram.raw.types.Message``, *optional*): The raw message object, as received from the Telegram API. + gift_code (:obj:`~pyrogram.types.GiftCode`, *optional*): + Contains a `Telegram Premium giftcode link `_. + + gifted_premium (:obj:`~pyrogram.types.GiftedPremium`, *optional*): + Info about a gifted Telegram Premium subscription + link (``str``, *property*): Generate a link to this message, only for groups and channels. @@ -493,6 +502,7 @@ class Message(Object, Update): forum_topic_edited: "types.ForumTopicEdited" = None, general_topic_hidden: "types.GeneralTopicHidden" = None, general_topic_unhidden: "types.GeneralTopicUnhidden" = None, + gifted_premium: "types.GiftedPremium" = None, giveaway_launched: "types.GiveawayLaunched" = None, video_chat_scheduled: "types.VideoChatScheduled" = None, video_chat_started: "types.VideoChatStarted" = None, @@ -557,6 +567,7 @@ class Message(Object, Update): self.sticker = sticker self.animation = animation self.game = game + self.gifted_premium = gifted_premium self.giveaway = giveaway self.giveaway_result = giveaway_result self.boosts_applied = boosts_applied @@ -707,6 +718,7 @@ class Message(Object, Update): video_chat_ended = None video_chat_members_invited = None web_app_data = None + gifted_premium = None giveaway_launched = None giveaway_result = None boosts_applied = None @@ -795,6 +807,9 @@ class Message(Object, Update): elif isinstance(action, raw.types.MessageActionWebViewDataSentMe): web_app_data = types.WebAppData._parse(action) service_type = enums.MessageServiceType.WEB_APP_DATA + elif isinstance(action, raw.types.MessageActionGiftPremium): + gifted_premium = await types.GiftedPremium._parse(client, action, from_user.id) + service_type = enums.MessageServiceType.GIFTED_PREMIUM elif isinstance(action, raw.types.MessageActionGiveawayLaunch): giveaway_launched = types.GiveawayLaunched() service_type = enums.MessageServiceType.GIVEAWAY_LAUNCHED @@ -840,6 +855,7 @@ class Message(Object, Update): video_chat_ended=video_chat_ended, video_chat_members_invited=video_chat_members_invited, web_app_data=web_app_data, + gifted_premium=gifted_premium, giveaway_launched=giveaway_launched, giveaway_result=giveaway_result, boosts_applied=boosts_applied,