From 599f794525d3ebf80dd1578fd924da73a3939f8e Mon Sep 17 00:00:00 2001 From: udf Date: Sat, 24 Nov 2018 17:19:23 +0200 Subject: [PATCH] move get_target_message to utils --- stdplugins/ninja.py | 11 +---------- uniborg/util.py | 9 +++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stdplugins/ninja.py b/stdplugins/ninja.py index 42688e9..8209158 100644 --- a/stdplugins/ninja.py +++ b/stdplugins/ninja.py @@ -11,15 +11,6 @@ import telethon.utils from uniborg import util -async def get_target_message(event): - if event.is_reply and (await event.get_reply_message()).from_id == borg.uid: - return await event.get_reply_message() - async for message in borg.iter_messages( - await event.get_input_chat(), limit=20): - if message.out: - return message - - async def await_read(chat, message): if isinstance(chat, InputPeerSelf): return @@ -46,7 +37,7 @@ async def delete(event): text = event.pattern_match.group(2) if not text: return - target = await get_target_message(event) + target = await util.get_target_message(borg, event) if target: chat = await event.get_input_chat() await await_read(chat, target) diff --git a/uniborg/util.py b/uniborg/util.py index 39cfc8c..3e3e7c3 100644 --- a/uniborg/util.py +++ b/uniborg/util.py @@ -28,3 +28,12 @@ async def is_read(borg, entity, message, is_out=None): dialog = (await borg(GetPeerDialogsRequest([entity]))).dialogs[0] max_id = dialog.read_outbox_max_id if is_out else dialog.read_inbox_max_id return message_id <= max_id + + +async def get_target_message(borg, event): + if event.is_reply and (await event.get_reply_message()).from_id == borg.uid: + return await event.get_reply_message() + async for message in borg.iter_messages( + await event.get_input_chat(), limit=20): + if message.out: + return message