Skip to content

Commit 7d061a1

Browse files
committed
Add Game type
1 parent 7cb1c99 commit 7d061a1

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus,
3333
UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply,
3434
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove,
35-
Poll, PollOption, ChatPreview, StopPropagation
35+
Poll, PollOption, ChatPreview, StopPropagation, Game
3636
)
3737
from .client import (
3838
Client, ChatAction, ParseMode, Emoji,

pyrogram/client/types/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .messages_and_media import (
3232
Audio, Contact, Document, Animation, Location, Photo, PhotoSize,
3333
Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos,
34-
Message, Messages, MessageEntity, Poll, PollOption
34+
Message, Messages, MessageEntity, Poll, PollOption, Game
3535
)
3636
from .user_and_chats import (
3737
Chat, ChatMember, ChatMembers, ChatPhoto,

pyrogram/client/types/messages_and_media/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
from .video import Video
3535
from .video_note import VideoNote
3636
from .voice import Voice
37+
from .game import Game
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import pyrogram
20+
from pyrogram.api import types
21+
from .animation import Animation
22+
from .photo import Photo
23+
from ..pyrogram_type import PyrogramType
24+
25+
26+
class Game(PyrogramType):
27+
"""This object represents a game.
28+
Use BotFather to create and edit games, their short names will act as unique identifiers.
29+
30+
Args:
31+
id (``int``):
32+
Unique identifier of the game.
33+
34+
title (``str``):
35+
Title of the game.
36+
37+
short_name (``str``):
38+
Unique short name of the game.
39+
40+
description (``str``):
41+
Description of the game.
42+
43+
photo (:obj:`Photo <pyrogram.Photo>`):
44+
Photo that will be displayed in the game message in chats.
45+
46+
animation (:obj:`Animation <pyrogram.Animation>`, *optional*):
47+
Animation that will be displayed in the game message in chats.
48+
Upload via BotFather.
49+
"""
50+
51+
def __init__(self,
52+
*,
53+
client: "pyrogram.client.ext.BaseClient",
54+
id: int,
55+
title: str,
56+
short_name: str,
57+
description: str,
58+
photo: Photo,
59+
animation: Animation = None):
60+
super().__init__(client)
61+
62+
self.id = id
63+
self.title = title
64+
self.short_name = short_name
65+
self.description = description
66+
self.photo = photo
67+
self.animation = animation
68+
69+
@staticmethod
70+
def _parse(client, message: types.Message) -> "Game":
71+
game = message.media.game # type: types.Game
72+
animation = None
73+
74+
if game.document:
75+
attributes = {type(i): i for i in game.document.attributes}
76+
77+
file_name = getattr(
78+
attributes.get(
79+
types.DocumentAttributeFilename, None
80+
), "file_name", None
81+
)
82+
83+
animation = Animation._parse(
84+
client,
85+
game.document,
86+
attributes.get(types.DocumentAttributeVideo, None),
87+
file_name
88+
)
89+
90+
return Game(
91+
id=game.id,
92+
title=game.title,
93+
short_name=game.short_name,
94+
description=game.description,
95+
photo=Photo._parse(client, game.photo),
96+
animation=animation,
97+
client=client
98+
)

0 commit comments

Comments
 (0)