Skip to content

Commit 39b4f0a

Browse files
authored
Merge branch 'master' into master
2 parents e92dc37 + 246e7e3 commit 39b4f0a

6 files changed

Lines changed: 246 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ tb = telebot.TeleBot(TOKEN) #create a new Telegram Bot object
234234
# - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers
235235
# - interval: True/False (default False) - The interval between polling requests
236236
# Note: Editing this parameter harms the bot's response time
237-
# - block: True/False (default True) - Blocks upon calling this function
238-
tb.polling(none_stop=False, interval=0, block=True)
237+
# - timeout: integer (default 20) - Timeout in seconds for long polling.
238+
tb.polling(none_stop=False, interval=0, timeout=20)
239239

240240
# getMe
241241
user = tb.get_me()
@@ -582,5 +582,6 @@ Get help. Discuss. Chat.
582582
* [areajugonesbot](http://t.me/areajugonesbot)([link](http://t.me/areajugonesbot)) - The areajugonesbot sends news published on the videogames blog Areajugones to Telegram.
583583
* [Send2Kindlebot](http://t.me/Send2KindleBot) ([source](https://github.com/GabrielRF/Send2KindleBot)) by *GabrielRF* - Send to Kindle service.
584584
* [RastreioBot](http://t.me/RastreioBot) ([source](https://github.com/GabrielRF/RastreioBot)) by *GabrielRF* - Bot used to track packages on the Brazilian Mail Service.
585+
* [filex_bot](http://t.me/filex_bot)([link](https://github.com/victor141516/FileXbot-telegram))
585586

586587
Want to have your bot listed here? Send a Telegram message to @eternnoir or @pevdh.

‎README.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ TeleBot
421421
# - none_stop: True/False (default False) - Don't stop polling when receiving an error from the Telegram servers
422422
# - interval: True/False (default False) - The interval between polling requests
423423
# Note: Editing this parameter harms the bot's response time
424-
# - block: True/False (default True) - Blocks upon calling this function
425-
tb.polling(none_stop=False, interval=0, block=True)
424+
# - timeout: integer (default 20) - Timeout in seconds for long polling.
425+
tb.polling(none_stop=False, interval=0, timeout=20)
426426
427427
# getMe
428428
user = tb.get_me()

‎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.1.1',
10+
version='3.2.0',
1111
description='Python Telegram bot api. ',
1212
long_description=readme(),
1313
author='eternnoir',

‎telebot/__init__.py‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def polling(self, none_stop=False, interval=0, timeout=20):
255255
Warning: Do not call this function more than once!
256256
257257
Always get updates.
258+
:param interval:
258259
:param none_stop: Do not stop polling when an ApiException occurs.
259260
:param timeout: Timeout in seconds for long polling.
260261
:return:
@@ -462,6 +463,7 @@ def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, rep
462463
disable_notification=None):
463464
"""
464465
Use this method to send photos.
466+
:param disable_notification:
465467
:param chat_id:
466468
:param photo:
467469
:param caption:
@@ -871,6 +873,86 @@ def answer_callback_query(self, callback_query_id, text=None, show_alert=None, u
871873
"""
872874
return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)
873875

876+
# def send_sticker(self, chat_id, sticker, disable_notification=None, reply_to_message_id=None, reply_markup=None):
877+
# """
878+
# Use this method to send .webp stickers. On success, the sent Message is returned.
879+
# :param chat_id:
880+
# :param sticker:
881+
# :param disable_notification:
882+
# :param reply_to_message_id:
883+
# :param reply_markup:
884+
# :return:
885+
# """
886+
# result = apihelper.send_sticker(self.token, chat_id, sticker, disable_notification, reply_markup, reply_markup)
887+
# return types.Message.de_json(result)
888+
889+
def get_sticker_set(self, name):
890+
"""
891+
Use this method to get a sticker set. On success, a StickerSet object is returned.
892+
:param token:
893+
:param name:
894+
:return:
895+
"""
896+
result = apihelper.get_sticker_set(self.token, name)
897+
return types.StickerSet.de_json(result)
898+
899+
def upload_sticker_file(self, user_id, png_sticker):
900+
"""
901+
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
902+
methods (can be used multiple times). Returns the uploaded File on success.
903+
:param user_id:
904+
:param png_sticker:
905+
:return:
906+
"""
907+
result = apihelper.upload_sticker_file(self.token, user_id, png_sticker)
908+
return types.File.de_json(result)
909+
910+
def create_new_sticker_set(self, user_id, name, title, png_sticker, emojis, contains_masks=None,
911+
mask_position=None):
912+
"""
913+
Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.
914+
Returns True on success.
915+
:param user_id:
916+
:param name:
917+
:param title:
918+
:param png_sticker:
919+
:param emojis:
920+
:param contains_masks:
921+
:param mask_position:
922+
:return:
923+
"""
924+
return apihelper.create_new_sticker_set(self.token, user_id, name, title, png_sticker, emojis, contains_masks,
925+
mask_position)
926+
927+
def add_sticker_to_set(self, user_id, name, png_sticker, emojis, mask_position):
928+
"""
929+
Use this method to add a new sticker to a set created by the bot. Returns True on success.
930+
:param user_id:
931+
:param name:
932+
:param png_sticker:
933+
:param emojis:
934+
:param mask_position:
935+
:return:
936+
"""
937+
return apihelper.add_sticker_to_set(self.token, user_id, name, png_sticker, emojis, mask_position)
938+
939+
def set_sticker_position_in_set(self, sticker, position):
940+
"""
941+
Use this method to move a sticker in a set created by the bot to a specific position . Returns True on success.
942+
:param sticker:
943+
:param position:
944+
:return:
945+
"""
946+
return apihelper.set_sticker_position_in_set(self.token, sticker, position)
947+
948+
def delete_sticker_from_set(self, sticker):
949+
"""
950+
Use this method to delete a sticker from a set created by the bot. Returns True on success.
951+
:param sticker:
952+
:return:
953+
"""
954+
return apihelper.delete_sticker_from_set(self.token, sticker)
955+
874956
def register_for_reply(self, message, callback):
875957
"""
876958
Registers a callback function to be notified when a reply to `message` arrives.
@@ -1301,3 +1383,31 @@ def answer_inline_query(self, *args, **kwargs):
13011383
@util.async()
13021384
def answer_callback_query(self, *args, **kwargs):
13031385
return TeleBot.answer_callback_query(self, *args, **kwargs)
1386+
1387+
@util.async()
1388+
def send_sticker(self, *args, **kwargs):
1389+
return TeleBot.send_sticker(self, *args, **kwargs)
1390+
1391+
@util.async()
1392+
def get_sticker_set(self, *args, **kwargs):
1393+
return TeleBot.get_sticker_set(self, *args, **kwargs)
1394+
1395+
@util.async()
1396+
def upload_sticker_file(self, *args, **kwargs):
1397+
return TeleBot.upload_sticker_file(self, *args, **kwargs)
1398+
1399+
@util.async()
1400+
def create_new_sticker_set(self, *args, **kwargs):
1401+
return TeleBot.create_new_sticker_set(self, *args, **kwargs)
1402+
1403+
@util.async()
1404+
def add_sticker_to_set(self, *args, **kwargs):
1405+
return TeleBot.add_sticker_to_set(self, *args, **kwargs)
1406+
1407+
@util.async()
1408+
def set_sticker_position_in_set(self, *args, **kwargs):
1409+
return TeleBot.set_sticker_position_in_set(self, *args, **kwargs)
1410+
1411+
@util.async()
1412+
def delete_sticker_from_set(self, *args, **kwargs):
1413+
return TeleBot.delete_sticker_from_set(self, *args, **kwargs)

‎telebot/apihelper.py‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _make_request(token, method_name, method='get', params=None, files=None, bas
5151
if 'timeout' in params: read_timeout = params['timeout'] + 10
5252
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
5353
result = _get_req_session().request(method, request_url, params=params, files=files,
54-
timeout=(connect_timeout, read_timeout), proxies=proxy)
54+
timeout=(connect_timeout, read_timeout), proxies=proxy)
5555
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
5656
return _check_result(method_name, result)['result']
5757

@@ -791,6 +791,58 @@ def answer_inline_query(token, inline_query_id, results, cache_time=None, is_per
791791
return _make_request(token, method_url, params=payload, method='post')
792792

793793

794+
def get_sticker_set(token, name):
795+
method_url = 'getStickerSet'
796+
return _make_request(token, method_url, params={'name': name})
797+
798+
799+
def upload_sticker_file(token, user_id, png_sticker):
800+
method_url = 'uploadStickerFile'
801+
payload = {'user_id': user_id}
802+
files = {'png_sticker': png_sticker}
803+
return _make_request(token, method_url, params=payload, files=files, method='post')
804+
805+
806+
def create_new_sticker_set(token, user_id, name, title, png_sticker, emojis, contains_masks=None, mask_position=None):
807+
method_url = 'createNewStickerSet'
808+
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
809+
files = None
810+
if not util.is_string(png_sticker):
811+
files = {'png_sticker': png_sticker}
812+
else:
813+
payload['png_sticker'] = png_sticker
814+
if contains_masks:
815+
payload['contains_masks'] = contains_masks
816+
if mask_position:
817+
payload['mask_position'] = mask_position.to_json()
818+
return _make_request(token, method_url, params=payload, files=files, method='post')
819+
820+
821+
def add_sticker_to_set(token, user_id, name, png_sticker, emojis, mask_position):
822+
method_url = 'addStickerToSet'
823+
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
824+
files = None
825+
if not util.is_string(png_sticker):
826+
files = {'png_sticker': png_sticker}
827+
else:
828+
payload['png_sticker'] = png_sticker
829+
if mask_position:
830+
payload['mask_position'] = mask_position.to_json()
831+
return _make_request(token, method_url, params=payload, files=files, method='post')
832+
833+
834+
def set_sticker_position_in_set(token, sticker, position):
835+
method_url = 'setStickerPositionInSet'
836+
payload = {'sticker': sticker, 'position': position}
837+
return _make_request(token, method_url, params=payload, method='post')
838+
839+
840+
def delete_sticker_from_set(token, sticker):
841+
method_url = 'deleteStickerFromSet'
842+
payload = {'sticker': sticker}
843+
return _make_request(token, method_url, params=payload, method='post')
844+
845+
794846
def _convert_list_json_serializable(results):
795847
ret = ''
796848
for r in results:

‎telebot/types.py‎

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,8 @@ def de_json(cls, json_type):
902902
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews)
903903

904904
def __init__(self, user, status, until_date, can_be_edited, can_change_info, can_post_messages, can_edit_messages,
905-
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
906-
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews):
905+
can_delete_messages, can_invite_users, can_restrict_members, can_pin_messages, can_promote_members,
906+
can_send_messages, can_send_media_messages, can_send_other_messages, can_add_web_page_previews):
907907
self.user = user
908908
self.status = status
909909
self.until_date = until_date
@@ -921,6 +921,7 @@ def __init__(self, user, status, until_date, can_be_edited, can_change_info, can
921921
self.can_send_other_messages = can_send_other_messages
922922
self.can_add_web_page_previews = can_add_web_page_previews
923923

924+
924925
# InlineQuery
925926

926927
class InlineQuery(JsonDeserializable):
@@ -1859,3 +1860,77 @@ def __init__(self, id, from_user, currency, total_amount, invoice_payload, shipp
18591860
self.invoice_payload = invoice_payload
18601861
self.shipping_option_id = shipping_option_id
18611862
self.order_info = order_info
1863+
1864+
1865+
# Stickers
1866+
1867+
class StickerSet(JsonDeserializable):
1868+
@classmethod
1869+
def de_json(cls, json_string):
1870+
obj = cls.check_json(json_string)
1871+
name = obj['name']
1872+
title = obj['title']
1873+
contains_masks = obj['contains_masks']
1874+
stickers = []
1875+
for s in obj['stickers']:
1876+
stickers.append(Sticker.de_json(s))
1877+
return cls(name, title, contains_masks, stickers)
1878+
1879+
def __init__(self, name, title, contains_masks, stickers):
1880+
self.stickers = stickers
1881+
self.contains_masks = contains_masks
1882+
self.title = title
1883+
self.name = name
1884+
1885+
1886+
class Sticker(JsonDeserializable):
1887+
@classmethod
1888+
def de_json(cls, json_string):
1889+
obj = cls.check_json(json_string)
1890+
file_id = obj['file_id']
1891+
width = obj['width']
1892+
height = obj['height']
1893+
thumb = None
1894+
if 'thumb' in obj:
1895+
thumb = PhotoSize.de_json(obj['thumb'])
1896+
emoji = obj.get('emoji')
1897+
set_name = obj.get('set_name')
1898+
mask_position = None
1899+
if 'mask_position' in obj:
1900+
mask_position = MaskPosition.de_json(obj['mask_position'])
1901+
file_size = obj.get('file_size')
1902+
return cls(file_id, width, height, thumb, emoji, set_name, mask_position, file_size)
1903+
1904+
def __init__(self, file_id, width, height, thumb, emoji, set_name, mask_position, file_size):
1905+
self.file_id = file_id
1906+
self.width = width
1907+
self.height = height
1908+
self.thumb = thumb
1909+
self.emoji = emoji
1910+
self.set_name = set_name
1911+
self.mask_position = mask_position
1912+
self.file_size = file_size
1913+
1914+
1915+
class MaskPosition(JsonDeserializable, JsonSerializable):
1916+
@classmethod
1917+
def de_json(cls, json_string):
1918+
obj = cls.check_json(json_string)
1919+
point = obj['point']
1920+
x_shift = obj['x_shift']
1921+
y_shift = obj['y_shift']
1922+
scale = obj['scale']
1923+
return cls(point, x_shift, y_shift, scale)
1924+
1925+
def __init__(self, point, x_shift, y_shift, scale):
1926+
self.point = point
1927+
self.x_shift = x_shift
1928+
self.y_shift = y_shift
1929+
self.scale = scale
1930+
1931+
def to_json(self):
1932+
return json.dumps(self.to_dic())
1933+
1934+
def to_dic(self):
1935+
return {'point': self.point, 'x_shift': self.x_shift, 'y_shift': self.y_shift, 'scale': self.scale}
1936+

0 commit comments

Comments
 (0)