add .edit command to ninja

it's now a full port from kateborg
pull/2/head
udf 2018-04-08 16:53:21 +02:00
parent 4c7923dd44
commit 923f04e688
1 changed files with 12 additions and 2 deletions

View File

@ -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)