From 0a2216a22bf89b8f3482462109270b6e9c048e04 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 29 Nov 2020 14:47:53 +0300 Subject: [PATCH 1/3] Bot API 5.0 pinning-unpinning logic update + add unpin_all_chat_messages() (former unpin_chat_message()) * update unpin_chat_message() (add message_id arg) --- telebot/__init__.py | 22 +++++++++++++++++++--- telebot/apihelper.py | 8 +++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 20fdf45..f151195 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1239,16 +1239,28 @@ class TeleBot: """ return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification) - def unpin_chat_message(self, chat_id): + def unpin_chat_message(self, chat_id, message_id): """ - Use this method to unpin a message in a supergroup chat. + Use this method to unpin specific pinned message in a supergroup chat. + The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. + Returns True on success. + :param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel + (in the format @channelusername) + :param message_id: Int: Identifier of a message to unpin + :return: + """ + return apihelper.unpin_chat_message(self.token, chat_id) + + def unpin_all_chat_messages(self, chat_id): + """ + Use this method to unpin a all pinned messages in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. :param chat_id: Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername) :return: """ - return apihelper.unpin_chat_message(self.token, chat_id) + return apihelper.unpin_all_chat_messages(self.token, chat_id, message_id) def edit_message_text(self, text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, disable_web_page_preview=None, reply_markup=None): @@ -2317,6 +2329,10 @@ class AsyncTeleBot(TeleBot): def unpin_chat_message(self, *args): return TeleBot.unpin_chat_message(self, *args) + @util.async_dec() + def unpin_all_chat_messages(self, *args): + return TeleBot.unpin_all_chat_messages(self, *args) + @util.async_dec() def edit_message_text(self, *args, **kwargs): return TeleBot.edit_message_text(self, *args, **kwargs) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 3bc6d35..b43d341 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -830,8 +830,14 @@ def pin_chat_message(token, chat_id, message_id, disable_notification=None): return _make_request(token, method_url, params=payload, method='post') -def unpin_chat_message(token, chat_id): +def unpin_chat_message(token, chat_id, message_id): method_url = 'unpinChatMessage' + payload = {'chat_id': chat_id, 'message_id': message_id} + return _make_request(token, method_url, params=payload, method='post') + + +def unpin_all_chat_messages(token, chat_id): + method_url = 'unpinAllChatMessages' payload = {'chat_id': chat_id} return _make_request(token, method_url, params=payload, method='post') From 00c9351f83ddff17e0b4c88d380f8cbfcb90d6f0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 29 Nov 2020 15:12:14 +0300 Subject: [PATCH 2/3] Hotfix 0a2216a22bf89b8f3482462109270b6e9c048e04 * message_id made optional as API declares --- telebot/__init__.py | 2 +- telebot/apihelper.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f151195..4f59e04 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1239,7 +1239,7 @@ class TeleBot: """ return apihelper.pin_chat_message(self.token, chat_id, message_id, disable_notification) - def unpin_chat_message(self, chat_id, message_id): + def unpin_chat_message(self, chat_id, message_id=None): """ Use this method to unpin specific pinned message in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. diff --git a/telebot/apihelper.py b/telebot/apihelper.py index b43d341..1cc57ab 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -830,7 +830,7 @@ def pin_chat_message(token, chat_id, message_id, disable_notification=None): return _make_request(token, method_url, params=payload, method='post') -def unpin_chat_message(token, chat_id, message_id): +def unpin_chat_message(token, chat_id, message_id=None): method_url = 'unpinChatMessage' payload = {'chat_id': chat_id, 'message_id': message_id} return _make_request(token, method_url, params=payload, method='post') From b9898bbdda1ca783046acc9c976f63a56059cb82 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 29 Nov 2020 15:21:59 +0300 Subject: [PATCH 3/3] Fix 0a2216a22bf89b8f3482462109270b6e9c048e04 #2 + message_id arg of unpin_chat_message() passing to the helper - removed passing arg to unpin_all_chat_messages() --- telebot/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 4f59e04..03b6c6c 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1249,7 +1249,7 @@ class TeleBot: :param message_id: Int: Identifier of a message to unpin :return: """ - return apihelper.unpin_chat_message(self.token, chat_id) + return apihelper.unpin_chat_message(self.token, chat_id, message_id) def unpin_all_chat_messages(self, chat_id): """ @@ -1260,7 +1260,7 @@ class TeleBot: (in the format @channelusername) :return: """ - return apihelper.unpin_all_chat_messages(self.token, chat_id, message_id) + return apihelper.unpin_all_chat_messages(self.token, chat_id) def edit_message_text(self, text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, disable_web_page_preview=None, reply_markup=None):