mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 20:14:51 +00:00
pyrofork: Add gifted_premium to Message
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
8ea36645c0
commit
b7dcc5b298
5 changed files with 115 additions and 1 deletions
|
|
@ -472,6 +472,7 @@ def pyrogram_api():
|
|||
Sticker
|
||||
StickerSet
|
||||
Game
|
||||
GiftedPremium
|
||||
Giveaway
|
||||
GiveawayLaunched
|
||||
GiveawayResult
|
||||
|
|
|
|||
|
|
@ -100,6 +100,9 @@ class MessageServiceType(AutoName):
|
|||
WEB_APP_DATA = auto()
|
||||
"Web app data"
|
||||
|
||||
GIFTED_PREMIUM = auto()
|
||||
"Gifted Premium"
|
||||
|
||||
GIVEAWAY_LAUNCHED = auto()
|
||||
"Giveaway Launch"
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
]
|
||||
|
|
|
|||
93
pyrogram/types/messages_and_media/gifted_premium.py
Normal file
93
pyrogram/types/messages_and_media/gifted_premium.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
)
|
||||
|
|
@ -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 <https://core.telegram.org/api/links#premium-giftcode-links>`_.
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue