Add GameHighScore and GameHighScores types

This commit is contained in:
Dan 2019-01-07 22:30:33 +01:00
parent 633fefe178
commit dc737ab7bb
7 changed files with 131 additions and 9 deletions

View File

@ -186,6 +186,12 @@ Input Media
.. autoclass:: Game .. autoclass:: Game
:members: :members:
.. autoclass:: GameHighScore
:members:
.. autoclass:: GameHighScores
:members:
.. Input Media .. Input Media
----------- -----------

View File

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

View File

@ -18,11 +18,8 @@
from .bots import ( from .bots import (
CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, CallbackGame,
) GameHighScore, GameHighScores
from .bots import (
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove
) )
from .input_media import ( from .input_media import (
InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto, InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto,
@ -33,8 +30,8 @@ from .messages_and_media import (
Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos, Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos,
Message, Messages, MessageEntity, Poll, PollOption, Game Message, Messages, MessageEntity, Poll, PollOption, Game
) )
from .update import StopPropagation
from .user_and_chats import ( from .user_and_chats import (
Chat, ChatMember, ChatMembers, ChatPhoto, Chat, ChatMember, ChatMembers, ChatPhoto,
Dialog, Dialogs, User, UserStatus, ChatPreview Dialog, Dialogs, User, UserStatus, ChatPreview
) )
from .update import StopPropagation

View File

@ -16,11 +16,13 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from .callback_game import CallbackGame
from .callback_query import CallbackQuery from .callback_query import CallbackQuery
from .force_reply import ForceReply from .force_reply import ForceReply
from .game_high_score import GameHighScore
from .game_high_scores import GameHighScores
from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_button import InlineKeyboardButton
from .inline_keyboard_markup import InlineKeyboardMarkup from .inline_keyboard_markup import InlineKeyboardMarkup
from .keyboard_button import KeyboardButton from .keyboard_button import KeyboardButton
from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_markup import ReplyKeyboardMarkup
from .reply_keyboard_remove import ReplyKeyboardRemove from .reply_keyboard_remove import ReplyKeyboardRemove
from .callback_game import CallbackGame

View File

@ -0,0 +1,61 @@
# 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 pyrogram.client.types.pyrogram_type import PyrogramType
from pyrogram.client.types.user_and_chats import User
class GameHighScore(PyrogramType):
"""This object represents one row of the high scores table for a game.
Args:
user (:obj:`User`):
User.
score (``int``):
Score.
position (``position``):
Position in high score table for the game.
"""
def __init__(self,
*,
client: "pyrogram.client.ext.BaseClient",
user: User,
score: int,
position: int):
super().__init__(client)
self.user = user
self.score = score
self.position = position
@staticmethod
def _parse(client, game_high_score: types.HighScore, users: dict) -> "GameHighScore":
users = {i.id: i for i in users}
return GameHighScore(
user=User._parse(client, users[game_high_score.user_id]),
score=game_high_score.score,
position=game_high_score.pos,
client=client
)

View File

@ -0,0 +1,56 @@
# 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/>.
from typing import List
import pyrogram
from pyrogram.api import types
from pyrogram.client.types.pyrogram_type import PyrogramType
from .game_high_score import GameHighScore
class GameHighScores(PyrogramType):
"""This object represents the high scores table for a game.
Args:
total_count (``int``):
Total number of scores the target game has.
game_high_scores (List of :obj:`GameHighScore <pyrogram.GameHighScore>`):
Game scores.
"""
def __init__(self,
*,
client: "pyrogram.client.ext.BaseClient",
total_count: int,
game_high_scores: List[GameHighScore]):
super().__init__(client)
self.total_count = total_count
self.game_high_scores = game_high_scores
@staticmethod
def _parse(client, game_high_scores: types.messages.HighScores) -> "GameHighScores":
return GameHighScores(
total_count=len(game_high_scores.scores),
game_high_scores=[
GameHighScore._parse(client, score, game_high_scores.users)
for score in game_high_scores.scores],
client=client
)

View File

@ -20,6 +20,7 @@ from .animation import Animation
from .audio import Audio from .audio import Audio
from .contact import Contact from .contact import Contact
from .document import Document from .document import Document
from .game import Game
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
@ -34,4 +35,3 @@ from .venue import Venue
from .video import Video from .video import Video
from .video_note import VideoNote from .video_note import VideoNote
from .voice import Voice from .voice import Voice
from .game import Game