refactor get_target_message into get_recent_self_message

This commit is contained in:
udf 2018-11-28 16:16:01 +02:00
parent 100f417744
commit f751ed707d
Signed by: kate
GPG Key ID: E40724BAD73AF77B
3 changed files with 10 additions and 10 deletions

View File

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

View File

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

View File

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