mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #402 from MasterGroosha/master
Bot API 3.4: new methods for live locations, new objects.
This commit is contained in:
commit
35d7293ebd
@ -407,6 +407,32 @@ class TeleBot:
|
||||
result = apihelper.get_chat_members_count(self.token, chat_id)
|
||||
return result
|
||||
|
||||
def set_chat_sticker_set(self, chat_id, sticker_set_name):
|
||||
"""
|
||||
Use this method to set a new group sticker set for a supergroup. The bot must be an administrator
|
||||
in the chat for this to work and must have the appropriate admin rights.
|
||||
Use the field can_set_sticker_set optionally returned in getChat requests to check
|
||||
if the bot can use this method. Returns True on success.
|
||||
:param chat_id: Unique identifier for the target chat or username of the target supergroup
|
||||
(in the format @supergroupusername)
|
||||
:param sticker_set_name: Name of the sticker set to be set as the group sticker set
|
||||
:return:
|
||||
"""
|
||||
result = apihelper.set_chat_sticker_set(self.token, chat_id, sticker_set_name)
|
||||
return result
|
||||
|
||||
def delete_chat_sticker_set(self, chat_id):
|
||||
"""
|
||||
Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat
|
||||
for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set
|
||||
optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
|
||||
:param chat_id: Unique identifier for the target chat or username of the target supergroup
|
||||
(in the format @supergroupusername)
|
||||
:return:
|
||||
"""
|
||||
result = apihelper.delete_chat_sticker_set(self.token, chat_id)
|
||||
return result
|
||||
|
||||
def get_chat_member(self, chat_id, user_id):
|
||||
"""
|
||||
Use this method to get information about a member of a chat. Returns a ChatMember object on success.
|
||||
@ -568,21 +594,51 @@ class TeleBot:
|
||||
apihelper.send_video_note(self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
|
||||
disable_notification, timeout))
|
||||
|
||||
def send_location(self, chat_id, latitude, longitude, reply_to_message_id=None, reply_markup=None,
|
||||
def send_location(self, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None,
|
||||
disable_notification=None):
|
||||
"""
|
||||
Use this method to send point on the map.
|
||||
:param chat_id:
|
||||
:param latitude:
|
||||
:param longitude:
|
||||
:param live_period
|
||||
:param reply_to_message_id:
|
||||
:param reply_markup:
|
||||
:return: API reply.
|
||||
"""
|
||||
return types.Message.de_json(
|
||||
apihelper.send_location(self.token, chat_id, latitude, longitude, reply_to_message_id, reply_markup,
|
||||
apihelper.send_location(self.token, chat_id, latitude, longitude, live_period, reply_to_message_id, reply_markup,
|
||||
disable_notification))
|
||||
|
||||
def edit_message_live_location(self, latitude, longitude, chat_id=None, message_id=None,
|
||||
inline_message_id=None, reply_markup=None):
|
||||
"""
|
||||
Use this method to edit live location
|
||||
:param latitude:
|
||||
:param longitude:
|
||||
:param chat_id:
|
||||
:param message_id:
|
||||
:param inline_message_id:
|
||||
:param reply_markup:
|
||||
:return:
|
||||
"""
|
||||
return types.Message.de_json(
|
||||
apihelper.edit_message_live_location(self, latitude, longitude, chat_id, message_id,
|
||||
inline_message_id, reply_markup))
|
||||
|
||||
def stop_message_live_location(self, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None):
|
||||
"""
|
||||
Use this method to stop updating a live location message sent by the bot
|
||||
or via the bot (for inline bots) before live_period expires
|
||||
:param chat_id:
|
||||
:param message_id:
|
||||
:param inline_message_id:
|
||||
:param reply_markup:
|
||||
:return:
|
||||
"""
|
||||
return types.Message.de_json(
|
||||
apihelper.stop_message_live_location(self, chat_id, message_id, inline_message_id, reply_markup))
|
||||
|
||||
def send_venue(self, chat_id, latitude, longitude, title, address, foursquare_id=None, disable_notification=None,
|
||||
reply_to_message_id=None, reply_markup=None):
|
||||
"""
|
||||
@ -1245,6 +1301,14 @@ class AsyncTeleBot(TeleBot):
|
||||
def get_chat_members_count(self, *args):
|
||||
return TeleBot.get_chat_members_count(self, *args)
|
||||
|
||||
@util.async()
|
||||
def set_chat_sticker_set(self, *args):
|
||||
return TeleBot.set_chat_sticker_set(self, *args)
|
||||
|
||||
@util.async()
|
||||
def delete_chat_sticker_set(self, *args):
|
||||
return TeleBot.delete_chat_sticker_set(self, *args)
|
||||
|
||||
@util.async()
|
||||
def get_chat_member(self, *args):
|
||||
return TeleBot.get_chat_member(self, *args)
|
||||
@ -1293,6 +1357,14 @@ class AsyncTeleBot(TeleBot):
|
||||
def send_location(self, *args, **kwargs):
|
||||
return TeleBot.send_location(self, *args, **kwargs)
|
||||
|
||||
@util.async()
|
||||
def edit_message_live_location(self, *args, **kwargs):
|
||||
return TeleBot.edit_message_live_location(self, *args, **kwargs)
|
||||
|
||||
@util.async()
|
||||
def stop_message_live_location(self, *args, **kwargs):
|
||||
return TeleBot.stop_message_live_location(self, *args, **kwargs)
|
||||
|
||||
@util.async()
|
||||
def send_venue(self, *args, **kwargs):
|
||||
return TeleBot.send_venue(self, *args, **kwargs)
|
||||
|
@ -209,6 +209,18 @@ def get_chat_members_count(token, chat_id):
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
def set_chat_sticker_set(token, chat_id, sticker_set_name):
|
||||
method_url = r'setChatStickerSet'
|
||||
payload = {'chat_id': chat_id, 'sticker_set_name': sticker_set_name}
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
def delete_chat_sticker_set(token, chat_id):
|
||||
method_url = r'deleteChatStickerSet'
|
||||
payload = {'chat_id': chat_id}
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
def get_chat_member(token, chat_id, user_id):
|
||||
method_url = r'getChatMember'
|
||||
payload = {'chat_id': chat_id, 'user_id': user_id}
|
||||
@ -243,10 +255,12 @@ def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, re
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None, reply_markup=None,
|
||||
def send_location(token, chat_id, latitude, longitude, live_period=None, reply_to_message_id=None, reply_markup=None,
|
||||
disable_notification=None):
|
||||
method_url = r'sendLocation'
|
||||
payload = {'chat_id': chat_id, 'latitude': latitude, 'longitude': longitude}
|
||||
if live_period:
|
||||
payload['live_perion'] = live_period
|
||||
if reply_to_message_id:
|
||||
payload['reply_to_message_id'] = reply_to_message_id
|
||||
if reply_markup:
|
||||
@ -256,6 +270,36 @@ def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None,
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
def edit_message_live_location(token, latitude, longitude, chat_id=None, message_id=None,
|
||||
inline_message_id=None, reply_markup=None):
|
||||
method_url = r'editMessageLiveLocation'
|
||||
payload = {'latitude': latitude, 'longitude': longitude}
|
||||
if chat_id:
|
||||
payload['chat_id'] = chat_id
|
||||
if message_id:
|
||||
payload['message_id'] = message_id
|
||||
if inline_message_id:
|
||||
payload['inline_message_id'] = inline_message_id
|
||||
if reply_markup:
|
||||
payload['reply_markup'] = _convert_markup(reply_markup)
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
def stop_message_live_location(token, chat_id=None, message_id=None,
|
||||
inline_message_id=None, reply_markup=None):
|
||||
method_url = r'stopMessageLiveLocation'
|
||||
payload = {}
|
||||
if chat_id:
|
||||
payload['chat_id'] = chat_id
|
||||
if message_id:
|
||||
payload['message_id'] = message_id
|
||||
if inline_message_id:
|
||||
payload['inline_message_id'] = inline_message_id
|
||||
if reply_markup:
|
||||
payload['reply_markup'] = _convert_markup(reply_markup)
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
def send_venue(token, chat_id, latitude, longitude, title, address, foursquare_id=None, disable_notification=None,
|
||||
reply_to_message_id=None, reply_markup=None):
|
||||
method_url = r'sendVenue'
|
||||
|
@ -225,12 +225,14 @@ class Chat(JsonDeserializable):
|
||||
pinned_message = None
|
||||
if 'pinned_message' in obj:
|
||||
pinned_message = Message.de_json(obj['pinned_message'])
|
||||
sticker_set_name = obj.get('sticker_set_name')
|
||||
can_set_sticker_set = obj.get('can_set_sticker_set')
|
||||
return cls(id, type, title, username, first_name, last_name, all_members_are_administrators,
|
||||
photo, description, invite_link, pinned_message)
|
||||
photo, description, invite_link, pinned_message, sticker_set_name, can_set_sticker_set)
|
||||
|
||||
def __init__(self, id, type, title=None, username=None, first_name=None, last_name=None,
|
||||
all_members_are_administrators=None, photo=None, description=None, invite_link=None,
|
||||
pinned_message=None):
|
||||
pinned_message=None, sticker_set_name=None, can_set_sticker_set=None):
|
||||
self.type = type
|
||||
self.last_name = last_name
|
||||
self.first_name = first_name
|
||||
@ -242,6 +244,8 @@ class Chat(JsonDeserializable):
|
||||
self.description = description
|
||||
self.invite_link = invite_link
|
||||
self.pinned_message = pinned_message
|
||||
self.sticker_set_name = sticker_set_name
|
||||
self.can_set_sticker_set = can_set_sticker_set
|
||||
|
||||
|
||||
class Message(JsonDeserializable):
|
||||
@ -277,6 +281,8 @@ class Message(JsonDeserializable):
|
||||
content_type = 'text'
|
||||
if 'entities' in obj:
|
||||
opts['entities'] = Message.parse_entities(obj['entities'])
|
||||
if 'caption_entities' in obj:
|
||||
opts['caption_entities'] = Message.parse_entities(obj['caption_entities'])
|
||||
if 'audio' in obj:
|
||||
opts['audio'] = Audio.de_json(obj['audio'])
|
||||
content_type = 'audio'
|
||||
@ -984,12 +990,15 @@ class InputTextMessageContent(Dictionaryable):
|
||||
|
||||
|
||||
class InputLocationMessageContent(Dictionaryable):
|
||||
def __init__(self, latitude, longitude):
|
||||
def __init__(self, latitude, longitude, live_period=None):
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.live_period = live_period
|
||||
|
||||
def to_dic(self):
|
||||
json_dic = {'latitude': self.latitude, 'longitude': self.longitude}
|
||||
if self.live_period:
|
||||
json_dic['live_period'] = self.live_period
|
||||
return json_dic
|
||||
|
||||
|
||||
@ -1386,13 +1395,14 @@ class InlineQueryResultDocument(JsonSerializable):
|
||||
|
||||
|
||||
class InlineQueryResultLocation(JsonSerializable):
|
||||
def __init__(self, id, title, latitude, longitude, reply_markup=None,
|
||||
def __init__(self, id, title, latitude, longitude, live_period=None, reply_markup=None,
|
||||
input_message_content=None, thumb_url=None, thumb_width=None, thumb_height=None):
|
||||
self.type = 'location'
|
||||
self.id = id
|
||||
self.title = title
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.live_period = live_period
|
||||
self.reply_markup = reply_markup
|
||||
self.input_message_content = input_message_content
|
||||
self.thumb_url = thumb_url
|
||||
@ -1402,6 +1412,8 @@ class InlineQueryResultLocation(JsonSerializable):
|
||||
def to_json(self):
|
||||
json_dict = {'type': self.type, 'id': self.id, 'latitude': self.latitude, 'longitude': self.longitude,
|
||||
'title': self.title}
|
||||
if self.live_period:
|
||||
json_dict['live_period'] = self.live_period
|
||||
if self.thumb_url:
|
||||
json_dict['thumb_url'] = self.thumb_url
|
||||
if self.thumb_width:
|
||||
|
Loading…
Reference in New Issue
Block a user