forked from uniborg/uniborg
Only get self message from history if not a reply
This commit is contained in:
parent
7426cea6d2
commit
100f417744
|
@ -4,12 +4,29 @@ Contains code used by other kbass_* plugins
|
||||||
from uniborg import util
|
from uniborg import util
|
||||||
|
|
||||||
|
|
||||||
|
async def get_target_message(event):
|
||||||
|
"""
|
||||||
|
If the event is a reply, returns the reply message if it's from us
|
||||||
|
If event is not a reply, then it tries to return the most recent message
|
||||||
|
from us
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def self_reply_cmd(borg, pattern):
|
def self_reply_cmd(borg, pattern):
|
||||||
def wrapper(function):
|
def wrapper(function):
|
||||||
@borg.on(util.admin_cmd(pattern))
|
@borg.on(util.admin_cmd(pattern))
|
||||||
async def wrapped(event, *args, **kwargs):
|
async def wrapped(event, *args, **kwargs):
|
||||||
await event.delete()
|
await event.delete()
|
||||||
target = await util.get_target_message(borg, event)
|
target = await get_target_message(event)
|
||||||
if not target:
|
if not target:
|
||||||
return
|
return
|
||||||
return await function(event, target, *args, **kwargs)
|
return await function(event, target, *args, **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue