From 86bab73216ce334ac94918a2e3eb2d7189725cb4 Mon Sep 17 00:00:00 2001 From: Davte Date: Sun, 25 Nov 2018 00:36:41 +0100 Subject: [PATCH] forward_message defined --- davtelepot/custombot.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/davtelepot/custombot.py b/davtelepot/custombot.py index 7dadf0c..e6dab06 100644 --- a/davtelepot/custombot.py +++ b/davtelepot/custombot.py @@ -1628,6 +1628,40 @@ class Bot(telepot.aio.Bot, Gettable): ) return sent + 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. + """ + try: + if from_chat_id is None or message_id is None: + if ( + type(update) is not dict + or 'chat' not in update + or 'id' not in update['chat'] + or message_id not in update + ): + raise Exception("Wrong parameters, cannot forward.") + from_chat_id = update['chat']['id'] + message_id = update['message_id'] + await self.avoid_flooding(chat_id) + sent = await self.forwardMessage( + chat_id=chat_id, + from_chat_id=from_chat_id, + disable_notification=disable_notification, + message_id=message_id, + ) + if isinstance(sent, Exception): + raise Exception("Forwarding failed.") + except Exception as e: + logging.error( + "Error sending photo\n{}".format( + e + ), + exc_info=False # Set exc_info=True for more information + ) + async def send_and_destroy(self, chat_id, answer, timer=60, mode='text', **kwargs): """Send a message or photo and delete it after `timer` seconds."""