From 923f04e688edfea6180747ff75c3332e5bfbeed4 Mon Sep 17 00:00:00 2001 From: udf Date: Sun, 8 Apr 2018 16:53:21 +0200 Subject: [PATCH] add .edit command to ninja it's now a full port from kateborg --- stdplugins/ninja.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/stdplugins/ninja.py b/stdplugins/ninja.py index 68db5a7..33d9c05 100644 --- a/stdplugins/ninja.py +++ b/stdplugins/ninja.py @@ -9,6 +9,7 @@ import telethon.utils from uniborg import util + async def get_target_message(event): if event.is_reply and (await event.reply_message).from_id == borg.uid: return event.reply_message @@ -29,12 +30,21 @@ async def await_read(chat, message): await fut -@borg.on(util.admin_cmd(r"^\.del(ete)?$")) +@borg.on(util.admin_cmd(r"^\.(del)(?:ete)?$")) +@borg.on(util.admin_cmd(r"^\.(edit)(.*)$")) async def delete(event): await event.delete() + command = event.pattern_match.group(1) + if command == 'edit': + text = event.pattern_match.group(2).strip() + if not text: + return target = await get_target_message(event) if target: chat = await event.input_chat await await_read(chat, target) await asyncio.sleep(.5) - await borg.delete_messages(chat, target) + if command == 'edit': + await borg.edit_message(chat, target, text) + else: + await borg.delete_messages(chat, target)