mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
add emoji field for dice
This commit is contained in:
parent
e89a552e06
commit
99c63e9eba
@ -647,17 +647,18 @@ 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):
|
def send_dice(self, chat_id, emoji=None, disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
"""
|
"""
|
||||||
Use this method to send dices.
|
Use this method to send dices.
|
||||||
:param chat_id:
|
:param chat_id:
|
||||||
|
:param emoji:
|
||||||
:param disable_notification:
|
:param disable_notification:
|
||||||
:param reply_to_message_id:
|
:param reply_to_message_id:
|
||||||
:param reply_markup:
|
:param reply_markup:
|
||||||
:return: Message
|
:return: Message
|
||||||
"""
|
"""
|
||||||
return types.Message.de_json(
|
return types.Message.de_json(
|
||||||
apihelper.send_dice(self.token, chat_id, disable_notification, reply_to_message_id, reply_markup)
|
apihelper.send_dice(self.token, chat_id, emoji, 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,
|
||||||
|
@ -259,9 +259,11 @@ 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):
|
def send_dice(token, chat_id, emoji=None, disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
method_url = r'sendDice'
|
method_url = r'sendDice'
|
||||||
payload = {'chat_id': chat_id}
|
payload = {'chat_id': chat_id}
|
||||||
|
if emoji:
|
||||||
|
payload['emoji'] = emoji
|
||||||
if disable_notification:
|
if disable_notification:
|
||||||
payload['disable_notification'] = disable_notification
|
payload['disable_notification'] = disable_notification
|
||||||
if reply_to_message_id:
|
if reply_to_message_id:
|
||||||
|
@ -521,16 +521,19 @@ class Dice(JsonSerializable, Dictionaryable, JsonDeserializable):
|
|||||||
if (json_string is None): return None
|
if (json_string is None): return None
|
||||||
obj = cls.check_json(json_string)
|
obj = cls.check_json(json_string)
|
||||||
value = obj['value']
|
value = obj['value']
|
||||||
return cls(value)
|
emoji = obj['emoji']
|
||||||
|
return cls(value, emoji)
|
||||||
|
|
||||||
def __init__(self, value):
|
def __init__(self, value, emoji):
|
||||||
self.value = value
|
self.value = value
|
||||||
|
self.emoji = emoji
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return json.dumps(self.to_dic())
|
return json.dumps(self.to_dic())
|
||||||
|
|
||||||
def to_dic(self):
|
def to_dic(self):
|
||||||
return {'value': self.value}
|
return {'value': self.value,
|
||||||
|
'emoji': self.emoji}
|
||||||
|
|
||||||
|
|
||||||
class PhotoSize(JsonDeserializable):
|
class PhotoSize(JsonDeserializable):
|
||||||
|
@ -243,7 +243,7 @@ class TestTeleBot:
|
|||||||
|
|
||||||
def test_send_dice(self):
|
def test_send_dice(self):
|
||||||
tb = telebot.TeleBot(TOKEN)
|
tb = telebot.TeleBot(TOKEN)
|
||||||
ret_msg = tb.send_dice(CHAT_ID)
|
ret_msg = tb.send_dice(CHAT_ID, emoji='🎯')
|
||||||
assert ret_msg.message_id
|
assert ret_msg.message_id
|
||||||
assert ret_msg.content_type == 'dice'
|
assert ret_msg.content_type == 'dice'
|
||||||
|
|
||||||
|
@ -18,11 +18,12 @@ def test_json_message():
|
|||||||
|
|
||||||
|
|
||||||
def test_json_message_with_dice():
|
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}}'
|
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, "emoji": "\ud83c\udfb2"}}'
|
||||||
msg = types.Message.de_json(jsonstring)
|
msg = types.Message.de_json(jsonstring)
|
||||||
assert msg.content_type == 'dice'
|
assert msg.content_type == 'dice'
|
||||||
assert isinstance(msg.dice, types.Dice)
|
assert isinstance(msg.dice, types.Dice)
|
||||||
assert msg.dice.value == 4
|
assert msg.dice.value == 4
|
||||||
|
assert msg.dice.emoji == '🎯'
|
||||||
|
|
||||||
|
|
||||||
def test_json_message_group():
|
def test_json_message_group():
|
||||||
|
Loading…
Reference in New Issue
Block a user