1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Minor updates in code

This commit is contained in:
Badiboy 2020-07-21 01:20:01 +03:00
parent 38694a9173
commit dbe9ce49df
3 changed files with 47 additions and 36 deletions

View File

@ -648,14 +648,14 @@ class TeleBot:
return types.Message.de_json( return types.Message.de_json(
apihelper.forward_message(self.token, chat_id, from_chat_id, message_id, disable_notification, timeout)) apihelper.forward_message(self.token, chat_id, from_chat_id, message_id, disable_notification, timeout))
def delete_message(self, chat_id, message_id): def delete_message(self, chat_id, message_id, timeout=None):
""" """
Use this method to delete message. Returns True on success. Use this method to delete message. Returns True on success.
:param chat_id: in which chat to delete :param chat_id: in which chat to delete
:param message_id: which message to delete :param message_id: which message to delete
:return: API reply. :return: API reply.
""" """
return apihelper.delete_message(self.token, chat_id, message_id) return apihelper.delete_message(self.token, chat_id, message_id, timeout)
def send_dice( def send_dice(
self, chat_id, self, chat_id,
@ -1252,39 +1252,41 @@ class TeleBot:
def send_invoice(self, chat_id, title, description, invoice_payload, provider_token, currency, prices, def send_invoice(self, chat_id, title, description, invoice_payload, provider_token, currency, prices,
start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None, start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None,
is_flexible=None, disable_notification=None, reply_to_message_id=None, reply_markup=None, send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None,
provider_data=None, timeout=None): disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None, timeout=None):
""" """
Sends invoice Sends invoice
:param chat_id: :param chat_id: Unique identifier for the target private chat
:param title: :param title: Product name
:param description: :param description: Product description
:param invoice_payload: :param invoice_payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
:param provider_token: :param provider_token: Payments provider token, obtained via @Botfather
:param currency: :param currency: Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
:param prices: :param prices: Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
:param start_parameter: :param start_parameter: Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
:param photo_url: :param photo_url: URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
:param photo_size: :param photo_size: Photo size
:param photo_width: :param photo_width: Photo width
:param photo_height: :param photo_height: Photo height
:param need_name: :param need_name: Pass True, if you require the user's full name to complete the order
:param need_phone_number: :param need_phone_number: Pass True, if you require the user's phone number to complete the order
:param need_email: :param need_email: Pass True, if you require the user's email to complete the order
:param need_shipping_address: :param need_shipping_address: Pass True, if you require the user's shipping address to complete the order
:param is_flexible: :param is_flexible: Pass True, if the final price depends on the shipping method
:param disable_notification: :param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider
:param reply_to_message_id: :param send_email_to_provider: Pass True, if user's email address should be sent to provider
:param reply_markup: :param disable_notification: Sends the message silently. Users will receive a notification with no sound.
:param provider_data: :param reply_to_message_id: If the message is a reply, ID of the original message
:param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button
:param provider_data: A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
:return: :return:
""" """
result = apihelper.send_invoice( result = apihelper.send_invoice(
self.token, chat_id, title, description, invoice_payload, provider_token, self.token, chat_id, title, description, invoice_payload, provider_token,
currency, prices, start_parameter, photo_url, photo_size, photo_width, currency, prices, start_parameter, photo_url, photo_size, photo_width,
photo_height, need_name, need_phone_number, need_email, need_shipping_address, photo_height, need_name, need_phone_number, need_email, need_shipping_address,
is_flexible, disable_notification, reply_to_message_id, reply_markup, send_phone_number_to_provider, send_email_to_provider, is_flexible, disable_notification,
provider_data, timeout) reply_to_message_id, reply_markup, provider_data, timeout)
return types.Message.de_json(result) return types.Message.de_json(result)
def send_poll( def send_poll(

View File

@ -320,7 +320,7 @@ def send_media_group(
disable_notification=None, reply_to_message_id=None, disable_notification=None, reply_to_message_id=None,
timeout=None): timeout=None):
method_url = r'sendMediaGroup' method_url = r'sendMediaGroup'
media_json, files = _convert_input_media_array(media) media_json, files = convert_input_media_array(media)
payload = {'chat_id': chat_id, 'media': media_json} payload = {'chat_id': chat_id, 'media': media_json}
if disable_notification is not None: if disable_notification is not None:
payload['disable_notification'] = disable_notification payload['disable_notification'] = disable_notification
@ -781,7 +781,7 @@ def edit_message_caption(token, caption, chat_id=None, message_id=None, inline_m
def edit_message_media(token, media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None): def edit_message_media(token, media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None):
method_url = r'editMessageMedia' method_url = r'editMessageMedia'
media_json, file = _convert_input_media(media) media_json, file = convert_input_media(media)
payload = {'media': media_json} payload = {'media': media_json}
if chat_id: if chat_id:
payload['chat_id'] = chat_id payload['chat_id'] = chat_id
@ -808,9 +808,11 @@ def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_messa
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')
def delete_message(token, chat_id, message_id): def delete_message(token, chat_id, message_id, timeout=None):
method_url = r'deleteMessage' method_url = r'deleteMessage'
payload = {'chat_id': chat_id, 'message_id': message_id} payload = {'chat_id': chat_id, 'message_id': message_id}
if timeout:
payload['connect-timeout'] = timeout
return _make_request(token, method_url, params=payload, method='post') return _make_request(token, method_url, params=payload, method='post')
@ -890,7 +892,8 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m
def send_invoice( def send_invoice(
token, chat_id, title, description, invoice_payload, provider_token, currency, prices, token, chat_id, title, description, invoice_payload, provider_token, currency, prices,
start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None, start_parameter, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None,
send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None,
disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None, disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None,
timeout=None): timeout=None):
""" """
@ -913,10 +916,12 @@ def send_invoice(
:param need_email: Pass True, if you require the user's email to complete the order :param need_email: Pass True, if you require the user's email to complete the order
:param need_shipping_address: Pass True, if you require the user's shipping address to complete the order :param need_shipping_address: Pass True, if you require the user's shipping address to complete the order
:param is_flexible: Pass True, if the final price depends on the shipping method :param is_flexible: Pass True, if the final price depends on the shipping method
:param send_phone_number_to_provider: Pass True, if user's phone number should be sent to provider
:param send_email_to_provider: Pass True, if user's email address should be sent to provider
:param disable_notification: Sends the message silently. Users will receive a notification with no sound. :param disable_notification: Sends the message silently. Users will receive a notification with no sound.
:param reply_to_message_id: If the message is a reply, ID of the original message :param reply_to_message_id: If the message is a reply, ID of the original message
:param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button :param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button
:param provider_data: :param provider_data: A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
:return: :return:
""" """
method_url = r'sendInvoice' method_url = r'sendInvoice'
@ -939,6 +944,10 @@ def send_invoice(
payload['need_email'] = need_email payload['need_email'] = need_email
if need_shipping_address is not None: if need_shipping_address is not None:
payload['need_shipping_address'] = need_shipping_address payload['need_shipping_address'] = need_shipping_address
if send_phone_number_to_provider is not None:
payload['send_phone_number_to_provider'] = send_phone_number_to_provider
if send_email_to_provider is not None:
payload['send_email_to_provider'] = send_email_to_provider
if is_flexible is not None: if is_flexible is not None:
payload['is_flexible'] = is_flexible payload['is_flexible'] = is_flexible
if disable_notification is not None: if disable_notification is not None:
@ -1154,13 +1163,13 @@ def _convert_markup(markup):
return markup return markup
def _convert_input_media(media): def convert_input_media(media):
if isinstance(media, types.InputMedia): if isinstance(media, types.InputMedia):
return media._convert_input_media() return media.convert_input_media()
return None, None return None, None
def _convert_input_media_array(array): def convert_input_media_array(array):
media = [] media = []
files = {} files = {}
for input_media in array: for input_media in array:

View File

@ -2268,7 +2268,7 @@ class InputMedia(Dictionaryable, JsonSerializable):
json_dict['parse_mode'] = self.parse_mode json_dict['parse_mode'] = self.parse_mode
return json_dict return json_dict
def _convert_input_media(self): def convert_input_media(self):
if util.is_string(self.media): if util.is_string(self.media):
return self.to_json(), None return self.to_json(), None