From 27d442fabfa8b1c94b59ea788797af1dbbd0d3e5 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Tue, 24 Jul 2018 00:33:13 +0300 Subject: [PATCH 1/3] timeout for send_message Add optional "timeout" parameter to send_message (the same as exists in all other send_*). Equal rights for all send functions! :) --- telebot/__init__.py | 4 ++-- telebot/apihelper.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index fb7770b..5106f87 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -459,7 +459,7 @@ class TeleBot: return types.ChatMember.de_json(result) def send_message(self, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None, - parse_mode=None, disable_notification=None): + parse_mode=None, disable_notification=None, timeout=None): """ Use this method to send text messages. @@ -477,7 +477,7 @@ class TeleBot: """ return types.Message.de_json( apihelper.send_message(self.token, chat_id, text, disable_web_page_preview, reply_to_message_id, - reply_markup, parse_mode, disable_notification)) + reply_markup, parse_mode, disable_notification, timeout)) def forward_message(self, chat_id, from_chat_id, message_id, disable_notification=None): """ diff --git a/telebot/apihelper.py b/telebot/apihelper.py index ceda96c..e919b5a 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -114,7 +114,7 @@ def download_file(token, file_path): def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None, - parse_mode=None, disable_notification=None): + parse_mode=None, disable_notification=None, timeout=None): """ Use this method to send text messages. On success, the sent Message is returned. :param token: @@ -137,6 +137,8 @@ def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_m payload['parse_mode'] = parse_mode if disable_notification: payload['disable_notification'] = disable_notification + if timeout: + payload['connect-timeout'] = timeout return _make_request(token, method_url, params=payload, method='post') From 8634e652497065178dd5f538327fddd04a53f963 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Wed, 25 Jul 2018 12:44:18 +0300 Subject: [PATCH 2/3] Fix kick_chat_member decription Fix kick_chat_member return value type description (should be boolean according to API and is boolean by fact). --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 5106f87..061d4d3 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -723,7 +723,7 @@ class TeleBot: :param user_id: Int : Unique identifier of the target user :param until_date: Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever - :return: types.Message + :return: boolean """ return apihelper.kick_chat_member(self.token, chat_id, user_id, until_date) From bf844ed2026ee9334d33e32331f120b79ed1e7e8 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Wed, 1 Jan 2020 13:46:18 +0300 Subject: [PATCH 3/3] HTML symbols not replaced HTML symbols not replaced because return is before replace. --- telebot/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index 6165c94..d8fe236 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -477,10 +477,10 @@ class Message(JsonDeserializable): url = "tg://user?id={0}".format(user.id) elif type == "mention": url = "https://t.me/{0}".format(text[1:]) + text = text.replace("&", "&").replace("<", "<").replace(">", ">") if not type or not _subs.get(type): return text subs = _subs.get(type) - text = text.replace("&", "&").replace("<", "<").replace(">", ">") return subs.format(text=text, url=url) offset = 0