Skip to content

Commit

Permalink
Fix and align reply_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Badiboy authored Jan 3, 2024
1 parent 4359f4f commit 9831ae2
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,6 @@ def send_dice(
payload['emoji'] = emoji
if disable_notification is not None:
payload['disable_notification'] = disable_notification
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
if reply_markup:
payload['reply_markup'] = _convert_markup(reply_markup)
if timeout:
Expand All @@ -458,6 +455,9 @@ def send_dice(
payload['protect_content'] = protect_content
if message_thread_id:
payload['message_thread_id'] = message_thread_id
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(token, method_url, params=payload)


Expand Down Expand Up @@ -509,15 +509,15 @@ def send_media_group(
payload = {'chat_id': chat_id, 'media': media_json}
if disable_notification is not None:
payload['disable_notification'] = disable_notification
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
if timeout:
payload['timeout'] = timeout
if protect_content is not None:
payload['protect_content'] = protect_content
if message_thread_id is not None:
payload['message_thread_id'] = message_thread_id
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(
token, method_url, params=payload,
method='post' if files else 'get',
Expand Down Expand Up @@ -625,6 +625,9 @@ def send_venue(
payload['protect_content'] = protect_content
if message_thread_id is not None:
payload['message_thread_id'] = message_thread_id
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(token, method_url, params=payload)


Expand Down Expand Up @@ -750,9 +753,6 @@ def send_animation(
payload['thumbnail'] = thumbnail
if caption_entities:
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
if protect_content is not None:
payload['protect_content'] = protect_content
if width:
Expand All @@ -763,6 +763,9 @@ def send_animation(
payload['message_thread_id'] = message_thread_id
if has_spoiler is not None:
payload['has_spoiler'] = has_spoiler
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(token, method_url, params=payload, files=files, method='post')


Expand Down Expand Up @@ -830,13 +833,13 @@ def send_video_note(token, chat_id, data, duration=None, length=None, reply_mark
files = {'thumbnail': thumbnail}
else:
payload['thumbnail'] = thumbnail
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
if protect_content is not None:
payload['protect_content'] = protect_content
if message_thread_id:
payload['message_thread_id'] = message_thread_id
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(token, method_url, params=payload, files=files, method='post')


Expand Down Expand Up @@ -883,7 +886,6 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())

return _make_request(token, method_url, params=payload, files=files, method='post')


Expand Down Expand Up @@ -921,9 +923,6 @@ def send_data(token, chat_id, data, data_type, reply_markup=None, parse_mode=Non
payload['thumbnail'] = thumbnail
if caption_entities:
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
if protect_content is not None:
payload['protect_content'] = protect_content
if method_url == 'sendDocument' and disable_content_type_detection is not None:
Expand All @@ -932,6 +931,9 @@ def send_data(token, chat_id, data, data_type, reply_markup=None, parse_mode=Non
payload['message_thread_id'] = message_thread_id
if emoji:
payload['emoji'] = emoji
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(token, method_url, params=payload, files=files, method='post')


Expand Down Expand Up @@ -1390,13 +1392,13 @@ def send_game(
payload['reply_markup'] = _convert_markup(reply_markup)
if timeout:
payload['timeout'] = timeout
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
if protect_content is not None:
payload['protect_content'] = protect_content
if message_thread_id:
payload['message_thread_id'] = message_thread_id
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(token, method_url, params=payload)


Expand Down Expand Up @@ -1786,9 +1788,8 @@ def create_invoice_link(token, title, description, payload, provider_token,
def send_poll(
token, chat_id,
question, options,
is_anonymous = None, type = None, allows_multiple_answers = None, correct_option_id = None,
explanation = None, explanation_parse_mode=None, open_period = None, close_date = None, is_closed = None,
disable_notification=False,
is_anonymous = None, type = None, allows_multiple_answers = None, correct_option_id = None, explanation = None,
explanation_parse_mode=None, open_period = None, close_date = None, is_closed = None, disable_notification=False,
reply_markup=None, timeout=None, explanation_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None):
method_url = r'sendPoll'
payload = {
Expand Down Expand Up @@ -1817,11 +1818,8 @@ def send_poll(
payload['close_date'] = close_date
if is_closed is not None:
payload['is_closed'] = is_closed

if disable_notification:
payload['disable_notification'] = disable_notification
if reply_parameters is not None:
payload['reply_parameters'] = reply_parameters.to_json()
if reply_markup is not None:
payload['reply_markup'] = _convert_markup(reply_markup)
if timeout:
Expand All @@ -1833,6 +1831,9 @@ def send_poll(
payload['protect_content'] = protect_content
if message_thread_id:
payload['message_thread_id'] = message_thread_id
if reply_parameters is not None:
# to json
payload['reply_parameters'] = json.dumps(reply_parameters.to_dict())
return _make_request(token, method_url, params=payload)

def create_forum_topic(token, chat_id, name, icon_color=None, icon_custom_emoji_id=None):
Expand Down Expand Up @@ -1931,9 +1932,7 @@ def forward_messages(token, chat_id, from_chat_id, message_ids, disable_notifica
payload['message_thread_id'] = message_thread_id
if protect_content is not None:
payload['protect_content'] = protect_content

result = _make_request(token, method_url, params=payload)
return result
return _make_request(token, method_url, params=payload)

def copy_messages(token, chat_id, from_chat_id, message_ids, disable_notification=None,
message_thread_id=None, protect_content=None, remove_caption=None):
Expand All @@ -1951,9 +1950,7 @@ def copy_messages(token, chat_id, from_chat_id, message_ids, disable_notificatio
payload['protect_content'] = protect_content
if remove_caption is not None:
payload['remove_caption'] = remove_caption

result = _make_request(token, method_url, params=payload)
return result
return _make_request(token, method_url, params=payload)


def _convert_list_json_serializable(results):
Expand Down

0 comments on commit 9831ae2

Please sign in to comment.