mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge branch 'master' into master
This commit is contained in:
commit
39b4f0a068
@ -234,8 +234,8 @@ tb = telebot.TeleBot(TOKEN) #create a new Telegram Bot object
|
|||||||
# - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers
|
# - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers
|
||||||
# - interval: True/False (default False) - The interval between polling requests
|
# - interval: True/False (default False) - The interval between polling requests
|
||||||
# Note: Editing this parameter harms the bot's response time
|
# Note: Editing this parameter harms the bot's response time
|
||||||
# - block: True/False (default True) - Blocks upon calling this function
|
# - timeout: integer (default 20) - Timeout in seconds for long polling.
|
||||||
tb.polling(none_stop=False, interval=0, block=True)
|
tb.polling(none_stop=False, interval=0, timeout=20)
|
||||||
|
|
||||||
# getMe
|
# getMe
|
||||||
user = tb.get_me()
|
user = tb.get_me()
|
||||||
@ -582,5 +582,6 @@ Get help. Discuss. Chat.
|
|||||||
* [areajugonesbot](http://t.me/areajugonesbot)([link](http://t.me/areajugonesbot)) - The areajugonesbot sends news published on the videogames blog Areajugones to Telegram.
|
* [areajugonesbot](http://t.me/areajugonesbot)([link](http://t.me/areajugonesbot)) - The areajugonesbot sends news published on the videogames blog Areajugones to Telegram.
|
||||||
* [Send2Kindlebot](http://t.me/Send2KindleBot) ([source](https://github.com/GabrielRF/Send2KindleBot)) by *GabrielRF* - Send to Kindle service.
|
* [Send2Kindlebot](http://t.me/Send2KindleBot) ([source](https://github.com/GabrielRF/Send2KindleBot)) by *GabrielRF* - Send to Kindle service.
|
||||||
* [RastreioBot](http://t.me/RastreioBot) ([source](https://github.com/GabrielRF/RastreioBot)) by *GabrielRF* - Bot used to track packages on the Brazilian Mail Service.
|
* [RastreioBot](http://t.me/RastreioBot) ([source](https://github.com/GabrielRF/RastreioBot)) by *GabrielRF* - Bot used to track packages on the Brazilian Mail Service.
|
||||||
|
* [filex_bot](http://t.me/filex_bot)([link](https://github.com/victor141516/FileXbot-telegram))
|
||||||
|
|
||||||
Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh.
|
Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh.
|
||||||
|
@ -421,8 +421,8 @@ TeleBot
|
|||||||
# - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers
|
# - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers
|
||||||
# - interval: True/False (default False) - The interval between polling requests
|
# - interval: True/False (default False) - The interval between polling requests
|
||||||
# Note: Editing this parameter harms the bot's response time
|
# Note: Editing this parameter harms the bot's response time
|
||||||
# - block: True/False (default True) - Blocks upon calling this function
|
# - timeout: integer (default 20) - Timeout in seconds for long polling.
|
||||||
tb.polling(none_stop=False, interval=0, block=True)
|
tb.polling(none_stop=False, interval=0, timeout=20)
|
||||||
|
|
||||||
# getMe
|
# getMe
|
||||||
user = tb.get_me()
|
user = tb.get_me()
|
||||||
|
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ def readme():
|
|||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
setup(name='pyTelegramBotAPI',
|
setup(name='pyTelegramBotAPI',
|
||||||
version='3.1.1',
|
version='3.2.0',
|
||||||
description='Python Telegram bot api. ',
|
description='Python Telegram bot api. ',
|
||||||
long_description=readme(),
|
long_description=readme(),
|
||||||
author='eternnoir',
|
author='eternnoir',
|
||||||
|
@ -255,6 +255,7 @@ class TeleBot:
|
|||||||
Warning: Do not call this function more than once!
|
Warning: Do not call this function more than once!
|
||||||
|
|
||||||
Always get updates.
|
Always get updates.
|
||||||
|
:param interval:
|
||||||
:param none_stop: Do not stop polling when an ApiException occurs.
|
:param none_stop: Do not stop polling when an ApiException occurs.
|
||||||
:param timeout: Timeout in seconds for long polling.
|
:param timeout: Timeout in seconds for long polling.
|
||||||
:return:
|
:return:
|
||||||
@ -462,6 +463,7 @@ class TeleBot:
|
|||||||
disable_notification=None):
|
disable_notification=None):
|
||||||
"""
|
"""
|
||||||
Use this method to send photos.
|
Use this method to send photos.
|
||||||
|
:param disable_notification:
|
||||||
:param chat_id:
|
:param chat_id:
|
||||||
:param photo:
|
:param photo:
|
||||||
:param caption:
|
:param caption:
|
||||||
@ -871,6 +873,86 @@ class TeleBot:
|
|||||||
"""
|
"""
|
||||||
return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)
|
return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)
|
||||||
|
|
||||||
|
# def send_sticker(self, chat_id, sticker, disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
# """
|
||||||
|
# Use this method to send .webp stickers. On success, the sent Message is returned.
|
||||||
|
# :param chat_id:
|
||||||
|
# :param sticker:
|
||||||
|
# :param disable_notification:
|
||||||
|
# :param reply_to_message_id:
|
||||||
|
# :param reply_markup:
|
||||||
|
# :return:
|
||||||
|
# """
|
||||||
|
# result = apihelper.send_sticker(self.token, chat_id, sticker, disable_notification, reply_markup, reply_markup)
|
||||||
|
# return types.Message.de_json(result)
|
||||||
|
|
||||||
|
def get_sticker_set(self, name):
|
||||||
|
"""
|
||||||
|
Use this method to get a sticker set. On success, a StickerSet object is returned.
|
||||||
|
:param token:
|
||||||
|
:param name:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
result = apihelper.get_sticker_set(self.token, name)
|
||||||
|
return types.StickerSet.de_json(result)
|
||||||
|
|
||||||
|
def upload_sticker_file(self, user_id, png_sticker):
|
||||||
|
"""
|
||||||
|
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
|
||||||
|
methods (can be used multiple times). Returns the uploaded File on success.
|
||||||
|
:param user_id:
|
||||||
|
:param png_sticker:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
result = apihelper.upload_sticker_file(self.token, user_id, png_sticker)
|
||||||
|
return types.File.de_json(result)
|
||||||
|
|
||||||
|
def create_new_sticker_set(self, user_id, name, title, png_sticker, emojis, contains_masks=None,
|
||||||
|
mask_position=None):
|
||||||
|
"""
|
||||||
|
Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.
|
||||||
|
Returns True on success.
|
||||||
|
:param user_id:
|
||||||
|
:param name:
|
||||||
|
:param title:
|
||||||
|
:param png_sticker:
|
||||||
|
:param emojis:
|
||||||
|
:param contains_masks:
|
||||||
|
:param mask_position:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return apihelper.create_new_sticker_set(self.token, user_id, name, title, png_sticker, emojis, contains_masks,
|
||||||
|
mask_position)
|
||||||
|
|
||||||
|
def add_sticker_to_set(self, user_id, name, png_sticker, emojis, mask_position):
|
||||||
|
"""
|
||||||
|
Use this method to add a new sticker to a set created by the bot. Returns True on success.
|
||||||
|
:param user_id:
|
||||||
|
:param name:
|
||||||
|
:param png_sticker:
|
||||||
|
:param emojis:
|
||||||
|
:param mask_position:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return apihelper.add_sticker_to_set(self.token, user_id, name, png_sticker, emojis, mask_position)
|
||||||
|
|
||||||
|
def set_sticker_position_in_set(self, sticker, position):
|
||||||
|
"""
|
||||||
|
Use this method to move a sticker in a set created by the bot to a specific position . Returns True on success.
|
||||||
|
:param sticker:
|
||||||
|
:param position:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return apihelper.set_sticker_position_in_set(self.token, sticker, position)
|
||||||
|
|
||||||
|
def delete_sticker_from_set(self, sticker):
|
||||||
|
"""
|
||||||
|
Use this method to delete a sticker from a set created by the bot. Returns True on success.
|
||||||
|
:param sticker:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return apihelper.delete_sticker_from_set(self.token, sticker)
|
||||||
|
|
||||||
def register_for_reply(self, message, callback):
|
def register_for_reply(self, message, callback):
|
||||||
"""
|
"""
|
||||||
Registers a callback function to be notified when a reply to `message` arrives.
|
Registers a callback function to be notified when a reply to `message` arrives.
|
||||||
@ -1301,3 +1383,31 @@ class AsyncTeleBot(TeleBot):
|
|||||||
@util.async()
|
@util.async()
|
||||||
def answer_callback_query(self, *args, **kwargs):
|
def answer_callback_query(self, *args, **kwargs):
|
||||||
return TeleBot.answer_callback_query(self, *args, **kwargs)
|
return TeleBot.answer_callback_query(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def send_sticker(self, *args, **kwargs):
|
||||||
|
return TeleBot.send_sticker(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def get_sticker_set(self, *args, **kwargs):
|
||||||
|
return TeleBot.get_sticker_set(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def upload_sticker_file(self, *args, **kwargs):
|
||||||
|
return TeleBot.upload_sticker_file(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def create_new_sticker_set(self, *args, **kwargs):
|
||||||
|
return TeleBot.create_new_sticker_set(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def add_sticker_to_set(self, *args, **kwargs):
|
||||||
|
return TeleBot.add_sticker_to_set(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def set_sticker_position_in_set(self, *args, **kwargs):
|
||||||
|
return TeleBot.set_sticker_position_in_set(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def delete_sticker_from_set(self, *args, **kwargs):
|
||||||
|
return TeleBot.delete_sticker_from_set(self, *args, **kwargs)
|
||||||
|
@ -51,7 +51,7 @@ def _make_request(token, method_name, method='get', params=None, files=None, bas
|
|||||||
if 'timeout' in params: read_timeout = params['timeout'] + 10
|
if 'timeout' in params: read_timeout = params['timeout'] + 10
|
||||||
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
|
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
|
||||||
result = _get_req_session().request(method, request_url, params=params, files=files,
|
result = _get_req_session().request(method, request_url, params=params, files=files,
|
||||||
timeout=(connect_timeout, read_timeout), proxies=proxy)
|
timeout=(connect_timeout, read_timeout), proxies=proxy)
|
||||||
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
|
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
|
||||||
return _check_result(method_name, result)['result']
|
return _check_result(method_name, result)['result']
|
||||||
|
|
||||||
@ -791,6 +791,58 @@ def answer_inline_query(token, inline_query_id, results, cache_time=None, is_per
|
|||||||
return _make_request(token, method_url, params=payload, method='post')
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
def get_sticker_set(token, name):
|
||||||
|
method_url = 'getStickerSet'
|
||||||
|
return _make_request(token, method_url, params={'name': name})
|
||||||
|
|
||||||
|
|
||||||
|
def upload_sticker_file(token, user_id, png_sticker):
|
||||||
|
method_url = 'uploadStickerFile'
|
||||||
|
payload = {'user_id': user_id}
|
||||||
|
files = {'png_sticker': png_sticker}
|
||||||
|
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
def create_new_sticker_set(token, user_id, name, title, png_sticker, emojis, contains_masks=None, mask_position=None):
|
||||||
|
method_url = 'createNewStickerSet'
|
||||||
|
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
|
||||||
|
files = None
|
||||||
|
if not util.is_string(png_sticker):
|
||||||
|
files = {'png_sticker': png_sticker}
|
||||||
|
else:
|
||||||
|
payload['png_sticker'] = png_sticker
|
||||||
|
if contains_masks:
|
||||||
|
payload['contains_masks'] = contains_masks
|
||||||
|
if mask_position:
|
||||||
|
payload['mask_position'] = mask_position.to_json()
|
||||||
|
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
def add_sticker_to_set(token, user_id, name, png_sticker, emojis, mask_position):
|
||||||
|
method_url = 'addStickerToSet'
|
||||||
|
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
|
||||||
|
files = None
|
||||||
|
if not util.is_string(png_sticker):
|
||||||
|
files = {'png_sticker': png_sticker}
|
||||||
|
else:
|
||||||
|
payload['png_sticker'] = png_sticker
|
||||||
|
if mask_position:
|
||||||
|
payload['mask_position'] = mask_position.to_json()
|
||||||
|
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
def set_sticker_position_in_set(token, sticker, position):
|
||||||
|
method_url = 'setStickerPositionInSet'
|
||||||
|
payload = {'sticker': sticker, 'position': position}
|
||||||
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
def delete_sticker_from_set(token, sticker):
|
||||||
|
method_url = 'deleteStickerFromSet'
|
||||||
|
payload = {'sticker': sticker}
|
||||||
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
def _convert_list_json_serializable(results):
|
def _convert_list_json_serializable(results):
|
||||||
ret = ''
|
ret = ''
|
||||||
for r in results:
|
for r in results:
|
||||||
|
@ -902,8 +902,8 @@ class ChatMember(JsonDeserializable):
|
|||||||
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews)
|
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews)
|
||||||
|
|
||||||
def __init__(self, user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
|
def __init__(self, user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
|
||||||
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
|
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
|
||||||
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews):
|
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews):
|
||||||
self.user = user
|
self.user = user
|
||||||
self.status = status
|
self.status = status
|
||||||
self.until_date = until_date
|
self.until_date = until_date
|
||||||
@ -921,6 +921,7 @@ class ChatMember(JsonDeserializable):
|
|||||||
self.can_send_other_messages = can_send_other_messages
|
self.can_send_other_messages = can_send_other_messages
|
||||||
self.can_add_web_page_previews = can_add_web_page_previews
|
self.can_add_web_page_previews = can_add_web_page_previews
|
||||||
|
|
||||||
|
|
||||||
# InlineQuery
|
# InlineQuery
|
||||||
|
|
||||||
class InlineQuery(JsonDeserializable):
|
class InlineQuery(JsonDeserializable):
|
||||||
@ -1859,3 +1860,77 @@ class PreCheckoutQuery(JsonDeserializable):
|
|||||||
self.invoice_payload = invoice_payload
|
self.invoice_payload = invoice_payload
|
||||||
self.shipping_option_id = shipping_option_id
|
self.shipping_option_id = shipping_option_id
|
||||||
self.order_info = order_info
|
self.order_info = order_info
|
||||||
|
|
||||||
|
|
||||||
|
# Stickers
|
||||||
|
|
||||||
|
class StickerSet(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
name = obj['name']
|
||||||
|
title = obj['title']
|
||||||
|
contains_masks = obj['contains_masks']
|
||||||
|
stickers = []
|
||||||
|
for s in obj['stickers']:
|
||||||
|
stickers.append(Sticker.de_json(s))
|
||||||
|
return cls(name, title, contains_masks, stickers)
|
||||||
|
|
||||||
|
def __init__(self, name, title, contains_masks, stickers):
|
||||||
|
self.stickers = stickers
|
||||||
|
self.contains_masks = contains_masks
|
||||||
|
self.title = title
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
|
class Sticker(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
file_id = obj['file_id']
|
||||||
|
width = obj['width']
|
||||||
|
height = obj['height']
|
||||||
|
thumb = None
|
||||||
|
if 'thumb' in obj:
|
||||||
|
thumb = PhotoSize.de_json(obj['thumb'])
|
||||||
|
emoji = obj.get('emoji')
|
||||||
|
set_name = obj.get('set_name')
|
||||||
|
mask_position = None
|
||||||
|
if 'mask_position' in obj:
|
||||||
|
mask_position = MaskPosition.de_json(obj['mask_position'])
|
||||||
|
file_size = obj.get('file_size')
|
||||||
|
return cls(file_id, width, height, thumb, emoji, set_name, mask_position, file_size)
|
||||||
|
|
||||||
|
def __init__(self, file_id, width, height, thumb, emoji, set_name, mask_position, file_size):
|
||||||
|
self.file_id = file_id
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.thumb = thumb
|
||||||
|
self.emoji = emoji
|
||||||
|
self.set_name = set_name
|
||||||
|
self.mask_position = mask_position
|
||||||
|
self.file_size = file_size
|
||||||
|
|
||||||
|
|
||||||
|
class MaskPosition(JsonDeserializable, JsonSerializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
point = obj['point']
|
||||||
|
x_shift = obj['x_shift']
|
||||||
|
y_shift = obj['y_shift']
|
||||||
|
scale = obj['scale']
|
||||||
|
return cls(point, x_shift, y_shift, scale)
|
||||||
|
|
||||||
|
def __init__(self, point, x_shift, y_shift, scale):
|
||||||
|
self.point = point
|
||||||
|
self.x_shift = x_shift
|
||||||
|
self.y_shift = y_shift
|
||||||
|
self.scale = scale
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return json.dumps(self.to_dic())
|
||||||
|
|
||||||
|
def to_dic(self):
|
||||||
|
return {'point': self.point, 'x_shift': self.x_shift, 'y_shift': self.y_shift, 'scale': self.scale}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user