Skip to content

Commit 1b76721

Browse files
authored
Merge pull request eternnoir#243 from Kondra007/patch-10
Added setGameScore and getGameHighScores
2 parents d149897 + 6f8ebba commit 1b76721

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

telebot/apihelper.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,55 @@ def send_game(token, chat_id, game_short_name, disable_notification=None, reply_
442442
return _make_request(token, method_url, params=payload)
443443

444444

445+
# https://core.telegram.org/bots/api#setgamescore
446+
def set_game_score(token, user_id, score, chat_id=None, message_id=None, inline_message_id=None, edit_message=None):
447+
"""
448+
Use this method to set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat.
449+
:param token: Bot's token (you don't need to fill this)
450+
:param user_id: User identifier
451+
:param score: New score, must be positive
452+
:param chat_id: (Optional, required if inline_message_id is not specified) Unique identifier for the target chat (or username of the target channel in the format @channelusername)
453+
:param message_id: (Optional, required if inline_message_id is not specified) Unique identifier of the sent message
454+
:param inline_message_id: (Optional, required if chat_id and message_id are not specified) Identifier of the inline message
455+
:param edit_message: (Optional) Pass True, if the game message should be automatically edited to include the current scoreboard
456+
:return:
457+
"""
458+
method_url = r'setGameScore'
459+
payload = {'user_id': user_id, 'score': score}
460+
if chat_id:
461+
payload['chat_id'] = chat_id
462+
if message_id:
463+
payload['message_id'] = message_id
464+
if inline_message_id:
465+
payload['inline_message_id'] = inline_message_id
466+
if edit_message:
467+
payload['edit_message'] = edit_message
468+
return _make_request(token, method_url, params=payload)
469+
470+
471+
# https://core.telegram.org/bots/api#getgamehighscores
472+
def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_message_id=None):
473+
"""
474+
Use this method to get data for high score tables. Will return the score of the specified user and several of his neighbors in a game. On success, returns an Array of GameHighScore objects.
475+
This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change.
476+
:param token: Bot's token (you don't need to fill this)
477+
:param user_id: Target user id
478+
:param chat_id: (Optional, required if inline_message_id is not specified) Unique identifier for the target chat (or username of the target channel in the format @channelusername)
479+
:param message_id: (Optional, required if inline_message_id is not specified) Unique identifier of the sent message
480+
:param inline_message_id: (Optional, required if chat_id and message_id are not specified) Identifier of the inline message
481+
:return:
482+
"""
483+
method_url = r'getGameHighScores'
484+
payload = {'user_id': user_id}
485+
if chat_id:
486+
payload['chat_id'] = chat_id
487+
if message_id:
488+
payload['message_id'] = message_id
489+
if inline_message_id:
490+
payload['inline_message_id'] = inline_message_id
491+
return _make_request(token, method_url, params=payload)
492+
493+
445494
# InlineQuery
446495

447496
def answer_callback_query(token, callback_query_id, text=None, show_alert=None, url=None):

0 commit comments

Comments
 (0)