From f751ed707ddef70cafc212da85b46a293893a34e Mon Sep 17 00:00:00 2001 From: udf Date: Wed, 28 Nov 2018 16:16:01 +0200 Subject: [PATCH] refactor get_target_message into get_recent_self_message --- stdplugins/kbass_core.py | 8 ++------ stdplugins/ninja.py | 8 +++++++- uniborg/util.py | 4 +--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stdplugins/kbass_core.py b/stdplugins/kbass_core.py index 1d1ebff..450293e 100644 --- a/stdplugins/kbass_core.py +++ b/stdplugins/kbass_core.py @@ -13,12 +13,8 @@ async def get_target_message(event): target = await event.get_reply_message() if event.is_reply and target.from_id == borg.uid: return target - if target: - return None - async for target in borg.iter_messages( - await event.get_input_chat(), limit=20): - if target.out: - return target + if not target: + return await util.get_recent_self_message(borg, event) def self_reply_cmd(borg, pattern): diff --git a/stdplugins/ninja.py b/stdplugins/ninja.py index 8209158..996fd9a 100644 --- a/stdplugins/ninja.py +++ b/stdplugins/ninja.py @@ -11,6 +11,12 @@ 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() + return await util.get_recent_self_message(borg, event) + + async def await_read(chat, message): if isinstance(chat, InputPeerSelf): return @@ -37,7 +43,7 @@ async def delete(event): text = event.pattern_match.group(2) if not text: return - target = await util.get_target_message(borg, event) + target = await get_target_message(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 3e3e7c3..bcbd849 100644 --- a/uniborg/util.py +++ b/uniborg/util.py @@ -30,9 +30,7 @@ async def is_read(borg, entity, message, is_out=None): 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 def get_recent_self_message(borg, event): async for message in borg.iter_messages( await event.get_input_chat(), limit=20): if message.out: