X Tutup
Skip to content

Commit 151a441

Browse files
committed
Add send_game
1 parent 1f67623 commit 151a441

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

telegram/bot.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,57 @@ def sendContact(self, chat_id, phone_number, first_name, last_name=None, **kwarg
741741

742742
return url, data
743743

744+
@log
745+
@message
746+
def sendGame(self,
747+
chat_id,
748+
game_short_name,
749+
parse_mode=None,
750+
disable_web_page_preview=None,
751+
**kwargs):
752+
"""Use this method to send game messages.
753+
754+
Args:
755+
chat_id (str): Unique identifier for the target chat or
756+
username of the target channel (in the format
757+
@channelusername).
758+
game_short_name (str): Short name of the game, serves as the unique
759+
identifier for the game.
760+
**kwargs (dict): Arbitrary keyword arguments.
761+
762+
Keyword Args:
763+
disable_notification (Optional[bool]): Sends the message silently.
764+
iOS users will not receive a notification, Android users will
765+
receive a notification with no sound.
766+
reply_to_message_id (Optional[int]): If the message is a reply,
767+
ID of the original message.
768+
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional
769+
interface options. A JSON-serialized object for an inline
770+
keyboard, custom reply keyboard, instructions to hide reply
771+
keyboard or to force a reply from the user.
772+
timeout (Optional[float]): If this value is specified, use it as
773+
the definitive timeout (in seconds) for urlopen() operations.
774+
775+
Returns:
776+
:class:`telegram.Message`: On success, the sent message is
777+
returned.
778+
779+
Raises:
780+
:class:`telegram.TelegramError`
781+
782+
"""
783+
784+
url = '{0}/sendMessage'.format(self.base_url)
785+
786+
data = {'chat_id': chat_id, 'game_short_name': game_short_name}
787+
788+
if parse_mode:
789+
data['parse_mode'] = parse_mode
790+
if disable_web_page_preview:
791+
data['disable_web_page_preview'] = disable_web_page_preview
792+
793+
return url, data
794+
744795
@log
745796
@message
746797
def sendChatAction(self, chat_id, action, **kwargs):
@@ -1481,7 +1532,7 @@ def __reduce__(self):
14811532
return (self.__class__, (self.token, self.base_url.replace(self.token, ''),
14821533
self.base_file_url.replace(self.token, '')))
14831534

1484-
# snake_case (PEP8) aliases
1535+
# snake_case (PEP8) aliases
14851536

14861537
get_me = getMe
14871538
send_message = sendMessage
@@ -1495,6 +1546,7 @@ def __reduce__(self):
14951546
send_location = sendLocation
14961547
send_venue = sendVenue
14971548
send_contact = sendContact
1549+
send_game = sendGame
14981550
send_chat_action = sendChatAction
14991551
answer_inline_query = answerInlineQuery
15001552
get_user_profile_photos = getUserProfilePhotos

telegram/message.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from time import mktime
2525

2626
from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject,
27-
User, Video, Voice, Venue, MessageEntity)
27+
User, Video, Voice, Venue, MessageEntity, Game)
2828

2929

3030
class Message(TelegramObject):
@@ -45,6 +45,7 @@ class Message(TelegramObject):
4545
text (str):
4646
audio (:class:`telegram.Audio`):
4747
document (:class:`telegram.Document`):
48+
game (:class:`telegram.Game`):
4849
photo (List[:class:`telegram.PhotoSize`]):
4950
sticker (:class:`telegram.Sticker`):
5051
video (:class:`telegram.Video`):
@@ -86,6 +87,7 @@ class Message(TelegramObject):
8687
text (Optional[str]):
8788
audio (Optional[:class:`telegram.Audio`]):
8889
document (Optional[:class:`telegram.Document`]):
90+
game (Optional[:class:`telegram.Game`]):
8991
photo (Optional[List[:class:`telegram.PhotoSize`]]):
9092
sticker (Optional[:class:`telegram.Sticker`]):
9193
video (Optional[:class:`telegram.Video`]):
@@ -173,6 +175,7 @@ def de_json(data, bot):
173175
data['edit_date'] = Message._fromtimestamp(data.get('edit_date'))
174176
data['audio'] = Audio.de_json(data.get('audio'), bot)
175177
data['document'] = Document.de_json(data.get('document'), bot)
178+
data['game'] = Game.de_json(data.get('game'), bot)
176179
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
177180
data['sticker'] = Sticker.de_json(data.get('sticker'), bot)
178181
data['video'] = Video.de_json(data.get('video'), bot)

0 commit comments

Comments
 (0)
X Tutup