mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Pyrofork: Add Giveaway media type
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
06da19f109
commit
3e3a861b50
5 changed files with 102 additions and 1 deletions
|
|
@ -446,6 +446,7 @@ def pyrogram_api():
|
||||||
Sticker
|
Sticker
|
||||||
StickerSet
|
StickerSet
|
||||||
Game
|
Game
|
||||||
|
Giveaway
|
||||||
MessageStory
|
MessageStory
|
||||||
WebPage
|
WebPage
|
||||||
WebPageEmpty
|
WebPageEmpty
|
||||||
|
|
|
||||||
|
|
@ -69,5 +69,8 @@ class MessageMediaType(AutoName):
|
||||||
GAME = auto()
|
GAME = auto()
|
||||||
"Game media"
|
"Game media"
|
||||||
|
|
||||||
|
GIVEAWAY = auto()
|
||||||
|
"Giveaway media"
|
||||||
|
|
||||||
STORY = auto()
|
STORY = auto()
|
||||||
"Forwarded story media"
|
"Forwarded story media"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ from .contact import Contact
|
||||||
from .dice import Dice
|
from .dice import Dice
|
||||||
from .document import Document
|
from .document import Document
|
||||||
from .game import Game
|
from .game import Game
|
||||||
|
from .giveaway import Giveaway
|
||||||
from .location import Location
|
from .location import Location
|
||||||
from .message import Message
|
from .message import Message
|
||||||
from .message_entity import MessageEntity
|
from .message_entity import MessageEntity
|
||||||
|
|
@ -51,7 +52,7 @@ from .story_views import StoryViews
|
||||||
from .exported_story_link import ExportedStoryLink
|
from .exported_story_link import ExportedStoryLink
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
|
"Animation", "Audio", "Contact", "Document", "Game", "Giveaway", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||||
"Reaction", "WebAppData", "MessageReactions", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoriesPrivacyRules", "ExportedStoryLink"
|
"Reaction", "WebAppData", "MessageReactions", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
86
pyrogram/types/messages_and_media/giveaway.py
Normal file
86
pyrogram/types/messages_and_media/giveaway.py
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from pyrogram import raw, types, utils
|
||||||
|
from ..object import Object
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
class Giveaway(Object):
|
||||||
|
"""A giveaway.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
channel_ids (List of ``int``):
|
||||||
|
List Unique identifier of the channel(s) which host the giveaway.
|
||||||
|
|
||||||
|
quantity (``int``):
|
||||||
|
Quantity of the giveaway prize.
|
||||||
|
|
||||||
|
months (``int``):
|
||||||
|
How long the telegram premium last (in month).
|
||||||
|
|
||||||
|
expire_date (:py:obj:`~datetime.datetime`):
|
||||||
|
Date the giveaway winner(s) will be choosen.
|
||||||
|
|
||||||
|
new_subscribers (``bool``):
|
||||||
|
True, if the giveaway only for new subscribers.
|
||||||
|
|
||||||
|
countries_iso2 (List of ``str``, *optional*):
|
||||||
|
List of ISO country codes which eligible to join the giveaway.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
client: "pyrogram.Client" = None,
|
||||||
|
channel_ids: List[int],
|
||||||
|
quantity: int,
|
||||||
|
months: int,
|
||||||
|
expire_date: datetime,
|
||||||
|
new_subscribers : bool,
|
||||||
|
countries_iso2: List[str] = None
|
||||||
|
):
|
||||||
|
super().__init__(client)
|
||||||
|
|
||||||
|
self.channel_ids = channel_ids
|
||||||
|
self.quantity = quantity
|
||||||
|
self.months = months
|
||||||
|
self.expire_date = expire_date
|
||||||
|
self.new_subscribers = new_subscribers
|
||||||
|
self.countries_iso2 = countries_iso2
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse(client, message: "raw.types.Message") -> "Giveaway":
|
||||||
|
giveaway: "raw.types.MessageMediaGiveaway" = message.media
|
||||||
|
channel_ids = []
|
||||||
|
for raw_channel_id in giveaway.channels:
|
||||||
|
channel_id = utils.get_channel_id(raw_channel_id)
|
||||||
|
channel_ids.append(channel_id)
|
||||||
|
|
||||||
|
return Giveaway(
|
||||||
|
channel_ids=channel_ids,
|
||||||
|
quantity=giveaway.quantity,
|
||||||
|
months=giveaway.months,
|
||||||
|
expire_date=utils.timestamp_to_datetime(giveaway.until_date),
|
||||||
|
new_subscribers=giveaway.only_new_subscribers,
|
||||||
|
countries_iso2=giveaway.countries_iso2 if len(giveaway.countries_iso2) > 0 else None,
|
||||||
|
client=client
|
||||||
|
)
|
||||||
|
|
@ -191,6 +191,9 @@ class Message(Object, Update):
|
||||||
game (:obj:`~pyrogram.types.Game`, *optional*):
|
game (:obj:`~pyrogram.types.Game`, *optional*):
|
||||||
Message is a game, information about the game.
|
Message is a game, information about the game.
|
||||||
|
|
||||||
|
giveaway (:obj:`~pyrogram.types.Giveaway`, *optional*):
|
||||||
|
Message is a giveaway, information about the giveaway.
|
||||||
|
|
||||||
story (:obj:`~pyrogram.types.MessageStory`, *optional*):
|
story (:obj:`~pyrogram.types.MessageStory`, *optional*):
|
||||||
Message is a forwarded story, information about the forwarded story.
|
Message is a forwarded story, information about the forwarded story.
|
||||||
|
|
||||||
|
|
@ -402,6 +405,7 @@ class Message(Object, Update):
|
||||||
sticker: "types.Sticker" = None,
|
sticker: "types.Sticker" = None,
|
||||||
animation: "types.Animation" = None,
|
animation: "types.Animation" = None,
|
||||||
game: "types.Game" = None,
|
game: "types.Game" = None,
|
||||||
|
giveaway: "types.Giveaway" = None,
|
||||||
story: "types.MessageStory" = None,
|
story: "types.MessageStory" = None,
|
||||||
video: "types.Video" = None,
|
video: "types.Video" = None,
|
||||||
voice: "types.Voice" = None,
|
voice: "types.Voice" = None,
|
||||||
|
|
@ -495,6 +499,7 @@ class Message(Object, Update):
|
||||||
self.sticker = sticker
|
self.sticker = sticker
|
||||||
self.animation = animation
|
self.animation = animation
|
||||||
self.game = game
|
self.game = game
|
||||||
|
self.giveaway = giveaway
|
||||||
self.story = story
|
self.story = story
|
||||||
self.video = video
|
self.video = video
|
||||||
self.voice = voice
|
self.voice = voice
|
||||||
|
|
@ -800,6 +805,7 @@ class Message(Object, Update):
|
||||||
contact = None
|
contact = None
|
||||||
venue = None
|
venue = None
|
||||||
game = None
|
game = None
|
||||||
|
giveaway = None
|
||||||
story = None
|
story = None
|
||||||
audio = None
|
audio = None
|
||||||
voice = None
|
voice = None
|
||||||
|
|
@ -833,6 +839,9 @@ class Message(Object, Update):
|
||||||
elif isinstance(media, raw.types.MessageMediaGame):
|
elif isinstance(media, raw.types.MessageMediaGame):
|
||||||
game = types.Game._parse(client, message)
|
game = types.Game._parse(client, message)
|
||||||
media_type = enums.MessageMediaType.GAME
|
media_type = enums.MessageMediaType.GAME
|
||||||
|
elif isinstance(media, raw.types.MessageMediaGiveaway):
|
||||||
|
giveaway = types.Giveaway._parse(client, message)
|
||||||
|
media_type = enums.MessageMediaType.GIVEAWAY
|
||||||
elif isinstance(media, raw.types.MessageMediaStory):
|
elif isinstance(media, raw.types.MessageMediaStory):
|
||||||
story = types.MessageStory._parse(media)
|
story = types.MessageStory._parse(media)
|
||||||
media_type = enums.MessageMediaType.STORY
|
media_type = enums.MessageMediaType.STORY
|
||||||
|
|
@ -964,6 +973,7 @@ class Message(Object, Update):
|
||||||
voice=voice,
|
voice=voice,
|
||||||
animation=animation,
|
animation=animation,
|
||||||
game=game,
|
game=game,
|
||||||
|
giveaway=giveaway,
|
||||||
story=story,
|
story=story,
|
||||||
video=video,
|
video=video,
|
||||||
video_note=video_note,
|
video_note=video_note,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue