|
23 | 23 | import logging |
24 | 24 |
|
25 | 25 | from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File, |
26 | | - ReplyMarkup, TelegramObject, WebhookInfo) |
| 26 | + ReplyMarkup, TelegramObject, WebhookInfo, GameHighScore) |
27 | 27 | from telegram.error import InvalidToken |
28 | 28 | from telegram.utils.request import Request |
29 | 29 |
|
@@ -1514,6 +1514,52 @@ def getWebhookInfo(self, **kwargs): |
1514 | 1514 |
|
1515 | 1515 | return WebhookInfo.de_json(result, self) |
1516 | 1516 |
|
| 1517 | + def setGameScore(self, |
| 1518 | + user_id, |
| 1519 | + score, |
| 1520 | + chat_id=None, |
| 1521 | + message_id=None, |
| 1522 | + inline_message_id=None, |
| 1523 | + edit_message=None, |
| 1524 | + **kwargs): |
| 1525 | + url = '{0}/setGameScore'.format(self.base_url) |
| 1526 | + |
| 1527 | + data = {'user_id': user_id, 'score': score} |
| 1528 | + |
| 1529 | + if chat_id: |
| 1530 | + data['chat_id'] = chat_id |
| 1531 | + if message_id: |
| 1532 | + data['chat_id'] = chat_id |
| 1533 | + if inline_message_id: |
| 1534 | + data['chat_id'] = inline_message_id |
| 1535 | + if edit_message: |
| 1536 | + data['edit_message'] = edit_message |
| 1537 | + |
| 1538 | + result = self._request.post(url, data, timeout=kwargs.get('timeout')) |
| 1539 | + del result # To satisfy flake8 |
| 1540 | + # Help: Result is either Message or True or an error |
| 1541 | + |
| 1542 | + def getGameHighScores(self, |
| 1543 | + user_id, |
| 1544 | + chat_id=None, |
| 1545 | + message_id=None, |
| 1546 | + inline_message_id=None, |
| 1547 | + **kwargs): |
| 1548 | + url = '{0}/setGameScore'.format(self.base_url) |
| 1549 | + |
| 1550 | + data = {'user_id': user_id} |
| 1551 | + |
| 1552 | + if chat_id: |
| 1553 | + data['chat_id'] = chat_id |
| 1554 | + if message_id: |
| 1555 | + data['chat_id'] = chat_id |
| 1556 | + if inline_message_id: |
| 1557 | + data['chat_id'] = inline_message_id |
| 1558 | + |
| 1559 | + result = self._request.post(url, data, timeout=kwargs.get('timeout')) |
| 1560 | + |
| 1561 | + return [GameHighScore.de_json(hs, self) for hs in result] |
| 1562 | + |
1517 | 1563 | @staticmethod |
1518 | 1564 | def de_json(data, bot): |
1519 | 1565 | data = super(Bot, Bot).de_json(data, bot) |
@@ -1565,3 +1611,5 @@ def __reduce__(self): |
1565 | 1611 | get_chat_member = getChatMember |
1566 | 1612 | get_chat_members_count = getChatMembersCount |
1567 | 1613 | get_webhook_info = getWebhookInfo |
| 1614 | + set_game_score = setGameScore |
| 1615 | + get_game_high_scores = getGameHighScores |
0 commit comments