Skip to content

Commit 9267da2

Browse files
authored
Merge pull request eternnoir#1 from eternnoir/master
Updating fork
2 parents 3ba9799 + 3be21ae commit 9267da2

5 files changed

Lines changed: 17 additions & 19 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,16 +500,13 @@ You can use proxy for request. `apihelper.proxy` object will use by call `reques
500500
```python
501501
from telebot import apihelper
502502

503-
apihelper.proxy = {'http', 'http://10.10.1.10:3128'}
503+
apihelper.proxy = {'http':'http://10.10.1.10:3128'}
504504
```
505505

506-
If you want to use socket5 proxy you need install dependency `pip install requests[socks]`.
506+
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`.
507507

508508
```python
509-
proxies = {
510-
'http': 'socks5://user:pass@host:port',
511-
'https': 'socks5://user:pass@host:port'
512-
}
509+
apihelper.proxy = {'https':'socks5://userproxy:password@proxy_address:port'}
513510
```
514511

515512

‎examples/webhook_examples/webhook_flask_echo_bot.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import flask
88
import telebot
99
import logging
10+
import time
1011

1112

1213
API_TOKEN = '<api_token>'
@@ -73,6 +74,8 @@ def echo_message(message):
7374
# Remove webhook, it fails sometimes the set if there is a previous webhook
7475
bot.remove_webhook()
7576

77+
time.sleep(0.1)
78+
7679
# Set webhook
7780
bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH,
7881
certificate=open(WEBHOOK_SSL_CERT, 'r'))

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def readme():
77
return f.read()
88

99
setup(name='pyTelegramBotAPI',
10-
version='3.6.2',
10+
version='3.6.3',
1111
description='Python Telegram bot api. ',
1212
long_description=readme(),
1313
author='eternnoir',

‎telebot/apihelper.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_file_url(token, file_id):
105105

106106
def download_file(token, file_path):
107107
url = FILE_URL.format(token, file_path)
108-
result = _get_req_session().get(url)
108+
result = _get_req_session().get(url, proxies=proxy)
109109
if result.status_code != 200:
110110
msg = 'The server returned HTTP {0} {1}. Response body:\n[{2}]' \
111111
.format(result.status_code, result.reason, result.text)
@@ -847,7 +847,7 @@ def answer_callback_query(token, callback_query_id, text=None, show_alert=None,
847847
payload['show_alert'] = show_alert
848848
if url:
849849
payload['url'] = url
850-
if cache_time:
850+
if cache_time is not None:
851851
payload['cache_time'] = cache_time
852852
return _make_request(token, method_url, params=payload, method='post')
853853

@@ -856,7 +856,7 @@ def answer_inline_query(token, inline_query_id, results, cache_time=None, is_per
856856
switch_pm_text=None, switch_pm_parameter=None):
857857
method_url = 'answerInlineQuery'
858858
payload = {'inline_query_id': inline_query_id, 'results': _convert_list_json_serializable(results)}
859-
if cache_time:
859+
if cache_time is not None:
860860
payload['cache_time'] = cache_time
861861
if is_personal:
862862
payload['is_personal'] = is_personal
@@ -953,7 +953,7 @@ def _convert_input_media(array):
953953
def _no_encode(func):
954954
def wrapper(key, val):
955955
if key == 'filename':
956-
return '{0}={1}'.format(key, val)
956+
return u'{0}={1}'.format(key, val)
957957
else:
958958
return func(key, val)
959959

‎telebot/types.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def de_json(cls, json_type):
127127
def __init__(self, update_id, message, edited_message, channel_post, edited_channel_post, inline_query,
128128
chosen_inline_result, callback_query, shipping_query, pre_checkout_query):
129129
self.update_id = update_id
130-
self.edited_message = edited_message
131130
self.message = message
132131
self.edited_message = edited_message
133132
self.channel_post = channel_post
@@ -468,8 +467,10 @@ def html_text(self):
468467
if hasattr(self, "custom_subs"):
469468
for type in self.custom_subs:
470469
_subs[type] = self.custom_subs[type]
470+
utf16_text = self.text.encode("utf-16-le")
471471
html_text = ""
472472
def func(text, type=None, url=None, user=None):
473+
text = text.decode("utf-16-le")
473474
if type == "text_mention":
474475
type = "url"
475476
url = "tg://user?id={0}".format(user.id)
@@ -483,16 +484,13 @@ def func(text, type=None, url=None, user=None):
483484

484485
offset = 0
485486
for entity in self.entities:
486-
if entity.type == "bot_command":
487-
entity.offset -= 1
488-
entity.length += 1
489487
if entity.offset > offset:
490-
html_text += func(self.text[offset:entity.offset])
488+
html_text += func(utf16_text[offset * 2 : entity.offset * 2])
491489
offset = entity.offset
492-
html_text += func(self.text[offset:offset + entity.length], entity.type, entity.url, entity.user)
490+
html_text += func(utf16_text[offset * 2 : (offset + entity.length) * 2], entity.type, entity.url, entity.user)
493491
offset += entity.length
494-
if offset < len(self.text):
495-
html_text += func(self.text[offset:])
492+
if offset * 2 < len(utf16_text):
493+
html_text += func(utf16_text[offset * 2:])
496494
return html_text
497495

498496

0 commit comments

Comments
 (0)