From 7e461be1bdb3492e88b37c46b16e72360247151e Mon Sep 17 00:00:00 2001 From: Davte Date: Tue, 16 Jul 2019 16:39:23 +0200 Subject: [PATCH] Defined methods `forward_message` and `delete_message` --- davtelepot/bot.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/davtelepot/bot.py b/davtelepot/bot.py index 4cb8e8b..5bf6027 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -1007,6 +1007,43 @@ class Bot(TelegramBot, ObjectWithDatabase): ) return edited_message + async def forward_message(self, chat_id, update=None, from_chat_id=None, + message_id=None, disable_notification=False): + """Forward message from `from_chat_id` to `chat_id`. + + Set `disable_notification` to True to avoid disturbing recipient. + Pass the `update` to be forwarded or its identifier (`from_chat_id` and + `message_id`). + """ + if from_chat_id is None or message_id is None: + message_identifier = self.get_message_identifier(update) + from_chat_id = message_identifier['chat_id'] + message_id = message_identifier['message_id'] + return await self.forwardMessage( + chat_id=chat_id, + from_chat_id=from_chat_id, + message_id=message_id, + disable_notification=disable_notification, + ) + + async def delete_message(self, update=dict(), chat_id=None, + message_id=None): + """Delete given update with given *args and **kwargs. + + Please note, that a bot can delete only messages sent by itself + or sent in a group which it is administrator of. + """ + if chat_id is None or message_id is None: + message_identifier = self.get_message_identifier(update) + else: + message_identifier = dict( + chat_id=chat_id, + message_id=message_id + ) + return await self.deleteMessage( + **message_identifier + ) + async def send_photo(self, chat_id=None, photo=None, caption=None, parse_mode=None,