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

Merge pull request #1 from eternnoir/master

Updating fork
This commit is contained in:
CoconutWaffle 2018-05-19 00:35:58 +03:00 committed by GitHub
commit 9267da205d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 19 deletions

View File

@ -500,16 +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]`.
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'}
```

View File

@ -7,6 +7,7 @@
import flask
import telebot
import logging
import time
API_TOKEN = '<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'))

View File

@ -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',

View File

@ -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)
@ -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
@ -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)

View File

@ -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
@ -468,8 +467,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 +484,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