mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Add giveaway type
This commit is contained in:
parent
ce59ae2677
commit
c569901744
@ -69,5 +69,8 @@ class MessageMediaType(AutoName):
|
|||||||
GAME = auto()
|
GAME = auto()
|
||||||
"Game media"
|
"Game media"
|
||||||
|
|
||||||
|
GIVEAWAY = auto()
|
||||||
|
"Giveaway media"
|
||||||
|
|
||||||
STORY = auto()
|
STORY = auto()
|
||||||
"Story media"
|
"Story media"
|
||||||
|
@ -29,6 +29,7 @@ from .forum_topic_edited import ForumTopicEdited
|
|||||||
from .general_forum_topic_hidden import GeneralTopicHidden
|
from .general_forum_topic_hidden import GeneralTopicHidden
|
||||||
from .general_forum_topic_unhidden import GeneralTopicUnhidden
|
from .general_forum_topic_unhidden import GeneralTopicUnhidden
|
||||||
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
|
||||||
@ -56,7 +57,7 @@ from .my_boost import MyBoost
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"Animation", "Audio", "Contact", "Document", "ForumTopic", "ForumTopicCreated",
|
"Animation", "Audio", "Contact", "Document", "ForumTopic", "ForumTopicCreated",
|
||||||
"ForumTopicClosed", "ForumTopicReopened", "ForumTopicEdited", "GeneralTopicHidden",
|
"ForumTopicClosed", "ForumTopicReopened", "ForumTopicEdited", "GeneralTopicHidden",
|
||||||
"GeneralTopicUnhidden", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
|
"GeneralTopicUnhidden", "Game", "Giveaway", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||||
"StrippedThumbnail", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "Poll", "PollOption", "Sticker",
|
"StrippedThumbnail", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "Poll", "PollOption", "Sticker",
|
||||||
"Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction", "WebAppData",
|
"Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction", "WebAppData",
|
||||||
"MessageReactions", "MessageStory", "MyBoost"
|
"MessageReactions", "MessageStory", "MyBoost"
|
||||||
|
86
pyrogram/types/messages_and_media/giveaway.py
Normal file
86
pyrogram/types/messages_and_media/giveaway.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
# 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 datetime import datetime
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, utils
|
||||||
|
from pyrogram import types
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class Giveaway(Object):
|
||||||
|
"""An giveaway.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
chats (List of :obj:`~pyrogram.types.Chat`):
|
||||||
|
Get the list of channels you need to subscribe to.
|
||||||
|
|
||||||
|
quantity (``int``):
|
||||||
|
Number of subscriptions.
|
||||||
|
|
||||||
|
months (``int``):
|
||||||
|
Number of months for which a subscription is given.
|
||||||
|
|
||||||
|
until_date (:py:obj:`~datetime.datetime`):
|
||||||
|
Date when the giveaway will end.
|
||||||
|
|
||||||
|
only_new_subscribers (``bool``):
|
||||||
|
True if the giveaway is for new subscribers only.
|
||||||
|
|
||||||
|
only_for_countries (List of ``str`` , *optional*):
|
||||||
|
Countries for which the giveaway is available in iso2 format.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
client: "pyrogram.Client" = None,
|
||||||
|
chats: List["types.Chat"] = None,
|
||||||
|
quantity: int = None,
|
||||||
|
months: int = None,
|
||||||
|
until_date: datetime = None,
|
||||||
|
only_new_subscribers: bool = None,
|
||||||
|
only_for_countries: List[str] = None
|
||||||
|
|
||||||
|
):
|
||||||
|
super().__init__(client)
|
||||||
|
|
||||||
|
self.chats = chats
|
||||||
|
self.quantity = quantity
|
||||||
|
self.months = months
|
||||||
|
self.until_date = until_date
|
||||||
|
self.only_new_subscribers = only_new_subscribers
|
||||||
|
self.only_for_countries = only_for_countries
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse(
|
||||||
|
client,
|
||||||
|
giveaway: "raw.types.MessageMediaGiveaway",
|
||||||
|
chats: dict
|
||||||
|
) -> "Giveaway":
|
||||||
|
return Giveaway(
|
||||||
|
chats=types.List(types.Chat._parse_channel_chat(client, chats.get(i)) for i in giveaway.channels),
|
||||||
|
quantity=giveaway.quantity,
|
||||||
|
months=giveaway.months,
|
||||||
|
until_date=utils.timestamp_to_datetime(giveaway.until_date),
|
||||||
|
only_new_subscribers=giveaway.only_new_subscribers,
|
||||||
|
only_for_countries=types.List(giveaway.countries_iso2) or None,
|
||||||
|
client=client
|
||||||
|
)
|
@ -409,6 +409,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,
|
||||||
@ -503,6 +504,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
|
||||||
@ -787,6 +789,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
|
||||||
@ -820,6 +823,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, media, chats)
|
||||||
|
media_type = enums.MessageMediaType.GIVEAWAY
|
||||||
elif isinstance(media, raw.types.MessageMediaStory):
|
elif isinstance(media, raw.types.MessageMediaStory):
|
||||||
story = types.MessageStory._parse(client, media, users, chats)
|
story = types.MessageStory._parse(client, media, users, chats)
|
||||||
media_type = enums.MessageMediaType.STORY
|
media_type = enums.MessageMediaType.STORY
|
||||||
@ -952,6 +958,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 New Issue
Block a user