move get_target_message to utils

kate
udf 2018-11-24 17:19:23 +02:00
parent 4d531be35b
commit 599f794525
Signed by: kate
GPG Key ID: E40724BAD73AF77B
2 changed files with 10 additions and 10 deletions

View File

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

View File

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