PagerMaid_Plugins/nthmsg.py

27 lines
826 B
Python
Raw Normal View History

2020-08-12 03:58:53 +00:00
from pagermaid.listener import listener
from telethon import functions, types
2021-06-16 07:09:40 +00:00
from pagermaid.utils import alias_command
2020-08-12 03:58:53 +00:00
2021-06-16 07:09:40 +00:00
@listener(outgoing=True, command=alias_command("nthmsg"),
2020-08-12 03:58:53 +00:00
description="获取你发送的第 n 条消息,默认为第一条",
parameters="<n>")
async def nthmsg(context):
await context.edit("获取中 . . .")
try:
n = int(context.parameter[0])
except:
n = 1
m = object()
2021-06-16 07:09:40 +00:00
async for m in context.client.iter_messages(context.chat_id, from_user="me", reverse=True, limit=n):
2020-08-12 03:58:53 +00:00
pass
2021-07-02 12:04:08 +00:00
try:
r = await context.client(
functions.channels.ExportMessageLinkRequest(channel=m.to_id, id=m.id, grouped=True))
except AttributeError:
await context.edit('获取失败。')
return
2020-08-12 03:58:53 +00:00
await context.edit(r.link)