2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Add Game type

This commit is contained in:
Dan 2019-01-05 23:11:39 +01:00
parent 7cb1c99e28
commit 7d061a1b5c
4 changed files with 101 additions and 2 deletions

View File

@ -32,7 +32,7 @@ from .client.types import (
Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus,
UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply,
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove,
Poll, PollOption, ChatPreview, StopPropagation
Poll, PollOption, ChatPreview, StopPropagation, Game
)
from .client import (
Client, ChatAction, ParseMode, Emoji,

View File

@ -31,7 +31,7 @@ from .input_media import (
from .messages_and_media import (
Audio, Contact, Document, Animation, Location, Photo, PhotoSize,
Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos,
Message, Messages, MessageEntity, Poll, PollOption
Message, Messages, MessageEntity, Poll, PollOption, Game
)
from .user_and_chats import (
Chat, ChatMember, ChatMembers, ChatPhoto,

View File

@ -34,3 +34,4 @@ from .venue import Venue
from .video import Video
from .video_note import VideoNote
from .voice import Voice
from .game import Game

View File

@ -0,0 +1,98 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2019 Dan Tès <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/>.
import pyrogram
from pyrogram.api import types
from .animation import Animation
from .photo import Photo
from ..pyrogram_type import PyrogramType
class Game(PyrogramType):
"""This object represents a game.
Use BotFather to create and edit games, their short names will act as unique identifiers.
Args:
id (``int``):
Unique identifier of the game.
title (``str``):
Title of the game.
short_name (``str``):
Unique short name of the game.
description (``str``):
Description of the game.
photo (:obj:`Photo <pyrogram.Photo>`):
Photo that will be displayed in the game message in chats.
animation (:obj:`Animation <pyrogram.Animation>`, *optional*):
Animation that will be displayed in the game message in chats.
Upload via BotFather.
"""
def __init__(self,
*,
client: "pyrogram.client.ext.BaseClient",
id: int,
title: str,
short_name: str,
description: str,
photo: Photo,
animation: Animation = None):
super().__init__(client)
self.id = id
self.title = title
self.short_name = short_name
self.description = description
self.photo = photo
self.animation = animation
@staticmethod
def _parse(client, message: types.Message) -> "Game":
game = message.media.game # type: types.Game
animation = None
if game.document:
attributes = {type(i): i for i in game.document.attributes}
file_name = getattr(
attributes.get(
types.DocumentAttributeFilename, None
), "file_name", None
)
animation = Animation._parse(
client,
game.document,
attributes.get(types.DocumentAttributeVideo, None),
file_name
)
return Game(
id=game.id,
title=game.title,
short_name=game.short_name,
description=game.description,
photo=Photo._parse(client, game.photo),
animation=animation,
client=client
)