PagerMaid_Plugins_Pyro/yvlu/main.py

40 lines
1.3 KiB
Python

import contextlib
from asyncio import sleep
from pyrogram.errors import Flood
from pagermaid.listener import listener
from pagermaid.enums import Client, Message
@listener(command="yvlu",
description="将回复的消息或者输入的字符串转换成语录")
async def yv_lu(bot: Client, message: Message):
bot_username = "PagerMaid_QuotLy_bot"
if message.reply_to_message:
reply = message.reply_to_message
elif message.parameter:
reply = await message.edit(message.arguments)
else:
return await message.edit('你需要回复一条消息或者输入一串字符。')
with contextlib.suppress(Exception):
await bot.unblock_user(bot_username)
async with bot.conversation(bot_username) as conv:
await reply.forward(bot_username)
await sleep(.1)
chat_response = await conv.get_response()
await conv.mark_as_read()
try:
await chat_response.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id)
except Flood as e:
await sleep(e.value + 1)
with contextlib.suppress(Exception):
await chat_response.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id)
except Exception:
pass
await message.safe_delete()