From beacc8c30592d835d5b50a573c855213dd92e00c Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Fri, 2 Nov 2018 19:15:37 +0000 Subject: [PATCH] Add chain plugin --- stdplugins/chain.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 stdplugins/chain.py diff --git a/stdplugins/chain.py b/stdplugins/chain.py new file mode 100644 index 0000000..8c28ffc --- /dev/null +++ b/stdplugins/chain.py @@ -0,0 +1,23 @@ +# 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/. + +from telethon import events +from telethon.tl.functions.messages import SaveDraftRequest + +@borg.on(events.NewMessage(pattern=r"\.chain", outgoing=True)) +async def _(event): + await event.edit("Counting...") + count = -1 + message = event.message + while message: + reply = await message.get_reply_message() + if reply is None: + await borg(SaveDraftRequest( + await event.get_input_chat(), + "", + reply_to_msg_id=message.id + )) + message = reply + count += 1 + await event.edit(f"Chain length: {count}")