mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
New method for v3.2
This commit is contained in:
parent
aefd666062
commit
af70313721
@ -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,72 @@ 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 send_sticker(token, chat_id, sticker, disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
method_url = 'sendSticker'
|
||||||
|
payload = {'chat_id': chat_id}
|
||||||
|
if not util.is_string(sticker):
|
||||||
|
files = {'sticker': sticker}
|
||||||
|
else:
|
||||||
|
payload['sticker'] = sticker
|
||||||
|
if disable_notification:
|
||||||
|
payload['disable_notification'] = disable_notification
|
||||||
|
if reply_to_message_id:
|
||||||
|
payload['reply_to_message_id'] = reply_to_message_id
|
||||||
|
if reply_markup:
|
||||||
|
payload['reply_markup'] = _convert_markup(reply_markup)
|
||||||
|
return _make_request(token, method_url, params=payload, files=files, 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}
|
||||||
|
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}
|
||||||
|
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:
|
||||||
|
@ -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):
|
||||||
@ -1860,6 +1861,7 @@ class PreCheckoutQuery(JsonDeserializable):
|
|||||||
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
|
# Stickers
|
||||||
|
|
||||||
class StickerSet(JsonDeserializable):
|
class StickerSet(JsonDeserializable):
|
||||||
@ -1869,19 +1871,18 @@ class StickerSet(JsonDeserializable):
|
|||||||
name = obj['name']
|
name = obj['name']
|
||||||
title = obj['title']
|
title = obj['title']
|
||||||
contains_masks = obj['contains_masks']
|
contains_masks = obj['contains_masks']
|
||||||
stickers=[]
|
stickers = []
|
||||||
for s in obj['stickers']
|
for s in obj['stickers']:
|
||||||
stickers.append(Sticker.de_json(s))
|
stickers.append(Sticker.de_json(s))
|
||||||
return cls(name, title, contains_masks, stickers)
|
return cls(name, title, contains_masks, stickers)
|
||||||
|
|
||||||
def __init__(self, name, title, contains_masks,stickers):
|
def __init__(self, name, title, contains_masks, stickers):
|
||||||
self.stickers = stickers
|
self.stickers = stickers
|
||||||
self.contains_masks = contains_masks
|
self.contains_masks = contains_masks
|
||||||
self.title = title
|
self.title = title
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Sticker(JsonDeserializable):
|
class Sticker(JsonDeserializable):
|
||||||
@classmethod
|
@classmethod
|
||||||
def de_json(cls, json_string):
|
def de_json(cls, json_string):
|
||||||
@ -1898,19 +1899,20 @@ class Sticker(JsonDeserializable):
|
|||||||
if 'mask_position' in obj:
|
if 'mask_position' in obj:
|
||||||
mask_position = MaskPosition.de_json(obj['mask_position'])
|
mask_position = MaskPosition.de_json(obj['mask_position'])
|
||||||
file_size = obj.get('file_size')
|
file_size = obj.get('file_size')
|
||||||
return cls(file_id, width, height, thumb,emoji, set_name, mask_position, 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):
|
def __init__(self, file_id, width, height, thumb, emoji, set_name, mask_position, file_size):
|
||||||
self.file_id = file_id
|
self.file_id = file_id
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.thumb=thumb
|
self.thumb = thumb
|
||||||
self.emoji = emoji
|
self.emoji = emoji
|
||||||
self.set_name = set_name
|
self.set_name = set_name
|
||||||
self.mask_position = mask_position
|
self.mask_position = mask_position
|
||||||
self.file_size=file_size
|
self.file_size = file_size
|
||||||
|
|
||||||
class MaskPosition(JsonDeserializable):
|
|
||||||
|
class MaskPosition(JsonDeserializable, JsonSerializable):
|
||||||
@classmethod
|
@classmethod
|
||||||
def de_json(cls, json_string):
|
def de_json(cls, json_string):
|
||||||
obj = cls.check_json(json_string)
|
obj = cls.check_json(json_string)
|
||||||
@ -1925,3 +1927,10 @@ class MaskPosition(JsonDeserializable):
|
|||||||
self.x_shift = x_shift
|
self.x_shift = x_shift
|
||||||
self.y_shift = y_shift
|
self.y_shift = y_shift
|
||||||
self.scale = scale
|
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