forked from uniborg/uniborg
refactor get_target_message into get_recent_self_message
This commit is contained in:
parent
100f417744
commit
f751ed707d
|
@ -13,12 +13,8 @@ async def get_target_message(event):
|
||||||
target = await event.get_reply_message()
|
target = await event.get_reply_message()
|
||||||
if event.is_reply and target.from_id == borg.uid:
|
if event.is_reply and target.from_id == borg.uid:
|
||||||
return target
|
return target
|
||||||
if target:
|
if not target:
|
||||||
return None
|
return await util.get_recent_self_message(borg, event)
|
||||||
async for target in borg.iter_messages(
|
|
||||||
await event.get_input_chat(), limit=20):
|
|
||||||
if target.out:
|
|
||||||
return target
|
|
||||||
|
|
||||||
|
|
||||||
def self_reply_cmd(borg, pattern):
|
def self_reply_cmd(borg, pattern):
|
||||||
|
|
|
@ -11,6 +11,12 @@ import telethon.utils
|
||||||
from uniborg import util
|
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):
|
async def await_read(chat, message):
|
||||||
if isinstance(chat, InputPeerSelf):
|
if isinstance(chat, InputPeerSelf):
|
||||||
return
|
return
|
||||||
|
@ -37,7 +43,7 @@ async def delete(event):
|
||||||
text = event.pattern_match.group(2)
|
text = event.pattern_match.group(2)
|
||||||
if not text:
|
if not text:
|
||||||
return
|
return
|
||||||
target = await util.get_target_message(borg, event)
|
target = await get_target_message(event)
|
||||||
if target:
|
if target:
|
||||||
chat = await event.get_input_chat()
|
chat = await event.get_input_chat()
|
||||||
await await_read(chat, target)
|
await await_read(chat, target)
|
||||||
|
|
|
@ -30,9 +30,7 @@ async def is_read(borg, entity, message, is_out=None):
|
||||||
return message_id <= max_id
|
return message_id <= max_id
|
||||||
|
|
||||||
|
|
||||||
async def get_target_message(borg, event):
|
async def get_recent_self_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(
|
async for message in borg.iter_messages(
|
||||||
await event.get_input_chat(), limit=20):
|
await event.get_input_chat(), limit=20):
|
||||||
if message.out:
|
if message.out:
|
||||||
|
|
Loading…
Reference in New Issue