From 59a0ebe9dc27319521e9712b633cc5d70f425def Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 27 Feb 2019 13:20:24 +0100 Subject: [PATCH] Add fixreply plugin --- stdplugins/fixreply.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 stdplugins/fixreply.py diff --git a/stdplugins/fixreply.py b/stdplugins/fixreply.py new file mode 100644 index 0000000..fded163 --- /dev/null +++ b/stdplugins/fixreply.py @@ -0,0 +1,27 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +import asyncio + +from telethon import events + + +_last_message = None + + +@borg.on(events.NewMessage(outgoing=True)) +async def _(event): + global _last_message + _last_message = event.message + + +@borg.on(events.NewMessage(pattern=r"\.(fix)?reply", outgoing=True)) +async def _(event): + if not event.is_reply or not _last_message: + return + + chat = await event.get_input_chat() + await asyncio.wait([ + borg.delete_messages(chat, [event.id, _last_message.id]), + borg.send_message(chat, _last_message, reply_to=event.reply_to_msg_id) + ])