From 4dc7af71a030b98f96892d3c3d5798ef1a4bc3cb Mon Sep 17 00:00:00 2001 From: eternnoir Date: Thu, 14 Apr 2016 14:48:26 +0800 Subject: [PATCH] Add bot2.0 new methods. --- telebot/__init__.py | 28 ++++++++++++++++++++++++++++ telebot/apihelper.py | 22 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/telebot/__init__.py b/telebot/__init__.py index cda256e..4487532 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -415,6 +415,19 @@ class TeleBot: def send_venue(self, chat_id, latitude, longitude, title, address, foursquare_id=None, disable_notification=None, reply_to_message_id=None, reply_markup=None): + """ + Use this method to send information about a venue. + :param chat_id: Integer or String : Unique identifier for the target chat or username of the target channel + :param latitude: Float : Latitude of the venue + :param longitude: Float : Longitude of the venue + :param title: String : Name of the venue + :param address: String : Address of the venue + :param foursquare_id: String : Foursquare identifier of the venue + :param disable_notification: + :param reply_to_message_id: + :param reply_markup: + :return: + """ return types.Message.de_json( apihelper.send_venue(self.token, chat_id, latitude, longitude, title, address, foursquare_id, disable_notification, reply_to_message_id, reply_markup) @@ -432,6 +445,21 @@ class TeleBot: """ return apihelper.send_chat_action(self.token, chat_id, action) + def kick_chat_member(self, chat_id, user_id): + """ + Use this method to kick a user from a group or a supergroup. + :param chat_id: Int or string : Unique identifier for the target group or username of the target supergroup + :param user_id: Int : Unique identifier of the target user + :return: types.Message + """ + return apihelper.kick_chat_member(self.token, chat_id, user_id) + + def unban_chat_member(self, chat_id, user_id): + return apihelper.unban_chat_member(self.token, chat_id, user_id) + + def answer_callback_query(self, callback_query_id, text=None, show_alert=None): + return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert) + def reply_to(self, message, text, **kwargs): """ Convenience function for `send_message(message.chat.id, text, reply_to_message_id=message.message_id, **kwargs)` diff --git a/telebot/apihelper.py b/telebot/apihelper.py index a47ab18..d087933 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -299,6 +299,28 @@ def get_method_by_type(data_type): return r'sendSticker' +def kick_chat_member(token, chat_id, user_id): + method_url = 'kickChatMember' + payload = {'chat_id': chat_id, 'user_id': user_id} + return _make_request(token, method_url, params=payload, method='post') + + +def unban_chat_member(token, chat_id, user_id): + method_url = 'unbanChatMember' + payload = {'chat_id': chat_id, 'user_id': user_id} + return _make_request(token, method_url, params=payload, method='post') + + +def answer_callback_query(token, callback_query_id, text=None, show_alert=None): + method_url = 'answerCallbackQuery' + payload = {'callback_query_id': callback_query_id} + if text: + payload['text'] = text + if show_alert: + payload['show_alert'] = show_alert + return _make_request(token, method_url, params=payload, method='post') + + def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None): method_url = 'answerInlineQuery' payload = {'inline_query_id': inline_query_id, 'results': _convert_inline_results(results)}