mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
commit
646bbb8330
@ -58,6 +58,7 @@ class TeleBot:
|
|||||||
sendVideoNote
|
sendVideoNote
|
||||||
sendLocation
|
sendLocation
|
||||||
sendChatAction
|
sendChatAction
|
||||||
|
sendDice
|
||||||
getUserProfilePhotos
|
getUserProfilePhotos
|
||||||
getUpdates
|
getUpdates
|
||||||
getFile
|
getFile
|
||||||
@ -646,6 +647,19 @@ class TeleBot:
|
|||||||
"""
|
"""
|
||||||
return apihelper.delete_message(self.token, chat_id, message_id)
|
return apihelper.delete_message(self.token, chat_id, message_id)
|
||||||
|
|
||||||
|
def send_dice(self, chat_id, disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
"""
|
||||||
|
Use this method to send dices.
|
||||||
|
:param chat_id:
|
||||||
|
:param disable_notification:
|
||||||
|
:param reply_to_message_id:
|
||||||
|
:param reply_markup:
|
||||||
|
:return: Message
|
||||||
|
"""
|
||||||
|
return types.Message.de_json(
|
||||||
|
apihelper.send_dice(self.token, chat_id, disable_notification, reply_to_message_id, reply_markup)
|
||||||
|
)
|
||||||
|
|
||||||
def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None,
|
def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None,
|
||||||
parse_mode=None, disable_notification=None):
|
parse_mode=None, disable_notification=None):
|
||||||
"""
|
"""
|
||||||
@ -1942,6 +1956,10 @@ class AsyncTeleBot(TeleBot):
|
|||||||
def send_message(self, *args, **kwargs):
|
def send_message(self, *args, **kwargs):
|
||||||
return TeleBot.send_message(self, *args, **kwargs)
|
return TeleBot.send_message(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async_dec()
|
||||||
|
def send_dice(self, *args, **kwargs):
|
||||||
|
return TeleBot.send_dice(self, *args, **kwargs)
|
||||||
|
|
||||||
@util.async_dec()
|
@util.async_dec()
|
||||||
def forward_message(self, *args, **kwargs):
|
def forward_message(self, *args, **kwargs):
|
||||||
return TeleBot.forward_message(self, *args, **kwargs)
|
return TeleBot.forward_message(self, *args, **kwargs)
|
||||||
|
@ -259,6 +259,18 @@ def forward_message(token, chat_id, from_chat_id, message_id, disable_notificati
|
|||||||
return _make_request(token, method_url, params=payload)
|
return _make_request(token, method_url, params=payload)
|
||||||
|
|
||||||
|
|
||||||
|
def send_dice(token, chat_id, disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
method_url = r'sendDice'
|
||||||
|
payload = {'chat_id': chat_id}
|
||||||
|
if disable_notification:
|
||||||
|
payload['disable_notification'] = disable_notification
|
||||||
|
if reply_to_message_id:
|
||||||
|
payload['reply_to_message_id'] = reply_to_message_id
|
||||||
|
if reply_markup:
|
||||||
|
payload['reply_markup'] = _convert_markup(reply_markup)
|
||||||
|
return _make_request(token, method_url, params=payload)
|
||||||
|
|
||||||
|
|
||||||
def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None,
|
def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None,
|
||||||
parse_mode=None, disable_notification=None):
|
parse_mode=None, disable_notification=None):
|
||||||
method_url = r'sendPhoto'
|
method_url = r'sendPhoto'
|
||||||
|
@ -293,6 +293,9 @@ class Message(JsonDeserializable):
|
|||||||
if 'venue' in obj:
|
if 'venue' in obj:
|
||||||
opts['venue'] = Venue.de_json(obj['venue'])
|
opts['venue'] = Venue.de_json(obj['venue'])
|
||||||
content_type = 'venue'
|
content_type = 'venue'
|
||||||
|
if 'dice' in obj:
|
||||||
|
opts['dice'] = Dice.de_json(obj['dice'])
|
||||||
|
content_type = 'dice'
|
||||||
if 'new_chat_members' in obj:
|
if 'new_chat_members' in obj:
|
||||||
new_chat_members = []
|
new_chat_members = []
|
||||||
for member in obj['new_chat_members']:
|
for member in obj['new_chat_members']:
|
||||||
@ -397,6 +400,7 @@ class Message(JsonDeserializable):
|
|||||||
self.location = None
|
self.location = None
|
||||||
self.venue = None
|
self.venue = None
|
||||||
self.animation = None
|
self.animation = None
|
||||||
|
self.dice = None
|
||||||
self.new_chat_member = None # Deprecated since Bot API 3.0. Not processed anymore
|
self.new_chat_member = None # Deprecated since Bot API 3.0. Not processed anymore
|
||||||
self.new_chat_members = None
|
self.new_chat_members = None
|
||||||
self.left_chat_member = None
|
self.left_chat_member = None
|
||||||
@ -511,6 +515,24 @@ class MessageEntity(JsonDeserializable):
|
|||||||
self.user = user
|
self.user = user
|
||||||
|
|
||||||
|
|
||||||
|
class Dice(JsonSerializable, Dictionaryable, JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
if (json_string is None): return None
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
value = obj['value']
|
||||||
|
return cls(value)
|
||||||
|
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return json.dumps({'value': self.value})
|
||||||
|
|
||||||
|
def to_dic(self):
|
||||||
|
return {'value': self.value}
|
||||||
|
|
||||||
|
|
||||||
class PhotoSize(JsonDeserializable):
|
class PhotoSize(JsonDeserializable):
|
||||||
@classmethod
|
@classmethod
|
||||||
def de_json(cls, json_string):
|
def de_json(cls, json_string):
|
||||||
|
@ -241,6 +241,12 @@ class TestTeleBot:
|
|||||||
ret_msg = tb.send_message(CHAT_ID, text)
|
ret_msg = tb.send_message(CHAT_ID, text)
|
||||||
assert ret_msg.message_id
|
assert ret_msg.message_id
|
||||||
|
|
||||||
|
def test_send_dice(self):
|
||||||
|
tb = telebot.TeleBot(TOKEN)
|
||||||
|
ret_msg = tb.send_dice(CHAT_ID)
|
||||||
|
assert ret_msg.message_id
|
||||||
|
assert ret_msg.content_type == 'dice'
|
||||||
|
|
||||||
def test_send_message_dis_noti(self):
|
def test_send_message_dis_noti(self):
|
||||||
text = 'CI Test Message'
|
text = 'CI Test Message'
|
||||||
tb = telebot.TeleBot(TOKEN)
|
tb = telebot.TeleBot(TOKEN)
|
||||||
|
@ -17,6 +17,14 @@ def test_json_message():
|
|||||||
assert msg.text == 'HIHI'
|
assert msg.text == 'HIHI'
|
||||||
|
|
||||||
|
|
||||||
|
def test_json_message_with_dice():
|
||||||
|
jsonstring = r'{"message_id":5560,"from":{"id":879343317,"is_bot":false,"first_name":"George","last_name":"Forse","username":"dr_fxrse","language_code":"ru"},"chat":{"id":879343317,"first_name":"George","last_name":"Forse","username":"dr_fxrse","type":"private"},"date":1586926330,"dice":{"value":4}}'
|
||||||
|
msg = types.Message.de_json(jsonstring)
|
||||||
|
assert msg.content_type == 'dice'
|
||||||
|
assert isinstance(msg.dice, types.Dice)
|
||||||
|
assert msg.dice.value == 4
|
||||||
|
|
||||||
|
|
||||||
def test_json_message_group():
|
def test_json_message_group():
|
||||||
json_string = r'{"message_id":10,"from":{"id":12345,"first_name":"g","last_name":"G","username":"GG","is_bot":true},"chat":{"id":-866,"type":"private","title":"\u4ea4"},"date":1435303157,"text":"HIHI"}'
|
json_string = r'{"message_id":10,"from":{"id":12345,"first_name":"g","last_name":"G","username":"GG","is_bot":true},"chat":{"id":-866,"type":"private","title":"\u4ea4"},"date":1435303157,"text":"HIHI"}'
|
||||||
msg = types.Message.de_json(json_string)
|
msg = types.Message.de_json(json_string)
|
||||||
|
Loading…
Reference in New Issue
Block a user