From ffe3a0c3d7f178dc6f772d8543ba032de0a7abab Mon Sep 17 00:00:00 2001 From: sviat9440 Date: Sun, 15 Apr 2018 19:19:29 +0300 Subject: [PATCH 1/9] Update types.py -- Fix encoding bug (emoji shifted offset) --- telebot/types.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/telebot/types.py b/telebot/types.py index f996436..da89bd4 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -468,8 +468,10 @@ class Message(JsonDeserializable): if hasattr(self, "custom_subs"): for type in self.custom_subs: _subs[type] = self.custom_subs[type] + utf16_text = self.text.encode("utf-16-le") html_text = "" def func(text, type=None, url=None, user=None): + text = text.decode("utf-16-le") if type == "text_mention": type = "url" url = "tg://user?id={0}".format(user.id) @@ -483,16 +485,13 @@ class Message(JsonDeserializable): offset = 0 for entity in self.entities: - if entity.type == "bot_command": - entity.offset -= 1 - entity.length += 1 if entity.offset > offset: - html_text += func(self.text[offset:entity.offset]) + html_text += func(utf16_text[offset * 2 : entity.offset * 2]) offset = entity.offset - html_text += func(self.text[offset:offset + entity.length], entity.type, entity.url, entity.user) + html_text += func(utf16_text[offset * 2 : (offset + entity.length) * 2], entity.type, entity.url, entity.user) offset += entity.length - if offset < len(self.text): - html_text += func(self.text[offset:]) + if offset * 2 < len(utf16_text): + html_text += func(utf16_text[offset * 2:]) return html_text From 10ec897fb541d1197c39ac6cc2fa7923041e2075 Mon Sep 17 00:00:00 2001 From: LeoNeeD <35986338+LeoNeeDpk1@users.noreply.github.com> Date: Wed, 18 Apr 2018 10:05:26 +1200 Subject: [PATCH 2/9] Update README.md Updated and 100% working info in SOCKS5 proxy block. --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5bda4ed..408b6be 100644 --- a/README.md +++ b/README.md @@ -503,13 +503,10 @@ from telebot import apihelper apihelper.proxy = {'http', 'http://10.10.1.10:3128'} ``` -If you want to use socket5 proxy you need install dependency `pip install requests[socks]`. +If you want to use socket5 proxy you need install dependency `pip install requests[socks]` and make sure, that you have the latest version of `gunicorn`, `PySocks`, `pyTelegramBotAPI`, `requests` and `urllib3`. ```python -proxies = { - 'http': 'socks5://user:pass@host:port', - 'https': 'socks5://user:pass@host:port' -} +apihelper.proxy = {'https', ' 'socks5://userproxy:password@proxy_address:port''} ``` From 5dd88f8223f33e0ddf83e4f264bb3c90ed2f26cb Mon Sep 17 00:00:00 2001 From: Benny Date: Wed, 18 Apr 2018 15:00:05 +0800 Subject: [PATCH 3/9] fix issue #403: UnicodeEncodeError when sending a non-ASCII file in Python 2.7 --- telebot/apihelper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 1173aa3..0bb536c 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -953,7 +953,7 @@ def _convert_input_media(array): def _no_encode(func): def wrapper(key, val): if key == 'filename': - return '{0}={1}'.format(key, val) + return u'{0}={1}'.format(key, val) else: return func(key, val) From 989cae597b58bd06643d6467fbebca4f6b5f2c05 Mon Sep 17 00:00:00 2001 From: Jay-T Date: Wed, 18 Apr 2018 13:10:22 +0500 Subject: [PATCH 4/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 408b6be..2ea415f 100644 --- a/README.md +++ b/README.md @@ -500,13 +500,13 @@ You can use proxy for request. `apihelper.proxy` object will use by call `reques ```python from telebot import apihelper -apihelper.proxy = {'http', 'http://10.10.1.10:3128'} +apihelper.proxy = {'http':'http://10.10.1.10:3128'} ``` If you want to use socket5 proxy you need install dependency `pip install requests[socks]` and make sure, that you have the latest version of `gunicorn`, `PySocks`, `pyTelegramBotAPI`, `requests` and `urllib3`. ```python -apihelper.proxy = {'https', ' 'socks5://userproxy:password@proxy_address:port''} +apihelper.proxy = {'https':'socks5://userproxy:password@proxy_address:port'} ``` From 99ff104a3f47592b3d6edb74e214f2ba6ba21914 Mon Sep 17 00:00:00 2001 From: khabibr Date: Tue, 24 Apr 2018 16:48:39 +0600 Subject: [PATCH 5/9] Update apihelper.py Correct files downloading when proxy used. --- telebot/apihelper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 0bb536c..3d9b53a 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -105,7 +105,7 @@ def get_file_url(token, file_id): def download_file(token, file_path): url = FILE_URL.format(token, file_path) - result = _get_req_session().get(url) + result = _get_req_session().get(url, proxies=proxy) if result.status_code != 200: msg = 'The server returned HTTP {0} {1}. Response body:\n[{2}]' \ .format(result.status_code, result.reason, result.text) From 8f5546092463b0ccdb5f6aff4c935657fc184610 Mon Sep 17 00:00:00 2001 From: eternnoir Date: Thu, 26 Apr 2018 09:53:55 +0800 Subject: [PATCH 6/9] Fix cache time is zero. --- telebot/apihelper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 3d9b53a..ceda96c 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -847,7 +847,7 @@ def answer_callback_query(token, callback_query_id, text=None, show_alert=None, payload['show_alert'] = show_alert if url: payload['url'] = url - if cache_time: + if cache_time is not None: payload['cache_time'] = cache_time return _make_request(token, method_url, params=payload, method='post') @@ -856,7 +856,7 @@ def answer_inline_query(token, inline_query_id, results, cache_time=None, is_per switch_pm_text=None, switch_pm_parameter=None): method_url = 'answerInlineQuery' payload = {'inline_query_id': inline_query_id, 'results': _convert_list_json_serializable(results)} - if cache_time: + if cache_time is not None: payload['cache_time'] = cache_time if is_personal: payload['is_personal'] = is_personal From 91f213ff3498eb78efa29db03fe775382fb82113 Mon Sep 17 00:00:00 2001 From: eternnoir Date: Fri, 27 Apr 2018 15:47:03 +0800 Subject: [PATCH 7/9] Fix #501 --- telebot/types.py | 1 - 1 file changed, 1 deletion(-) diff --git a/telebot/types.py b/telebot/types.py index f996436..fb6789b 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -127,7 +127,6 @@ class Update(JsonDeserializable): def __init__(self, update_id, message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query): self.update_id = update_id - self.edited_message = edited_message self.message = message self.edited_message = edited_message self.channel_post = channel_post From b5a217013a9387b87d3fac3c70254fb6a12e2238 Mon Sep 17 00:00:00 2001 From: fojetin Date: Mon, 30 Apr 2018 15:41:12 +0300 Subject: [PATCH 8/9] Fix #253 #231 #485 --- examples/webhook_examples/webhook_flask_echo_bot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/webhook_examples/webhook_flask_echo_bot.py b/examples/webhook_examples/webhook_flask_echo_bot.py index 92ffa21..d0327d7 100644 --- a/examples/webhook_examples/webhook_flask_echo_bot.py +++ b/examples/webhook_examples/webhook_flask_echo_bot.py @@ -7,6 +7,7 @@ import flask import telebot import logging +import time API_TOKEN = '' @@ -73,6 +74,8 @@ def echo_message(message): # Remove webhook, it fails sometimes the set if there is a previous webhook bot.remove_webhook() +time.sleep(0.1) + # Set webhook bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH, certificate=open(WEBHOOK_SSL_CERT, 'r')) From 3be21ae36163dd35d165ceae4f80063d21a78803 Mon Sep 17 00:00:00 2001 From: eternnoir Date: Mon, 14 May 2018 10:15:05 +0800 Subject: [PATCH 9/9] Update version. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1c5529a..1e76d03 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def readme(): return f.read() setup(name='pyTelegramBotAPI', - version='3.6.2', + version='3.6.3', description='Python Telegram bot api. ', long_description=readme(), author='eternnoir',