2022-06-26 13:16:45 +00:00
|
|
|
import contextlib
|
2022-06-26 11:59:09 +00:00
|
|
|
from asyncio import sleep
|
|
|
|
|
2022-08-08 07:40:19 +00:00
|
|
|
from pyrogram.errors import Flood
|
2022-08-09 13:50:03 +00:00
|
|
|
from pyrogram.errors.exceptions.bad_request_400 import ChatForwardsRestricted
|
2022-06-26 11:59:09 +00:00
|
|
|
|
2022-08-08 07:40:19 +00:00
|
|
|
from pagermaid.listener import listener
|
|
|
|
from pagermaid.enums import Client, Message
|
2022-06-26 11:59:09 +00:00
|
|
|
|
|
|
|
|
2022-08-08 07:40:19 +00:00
|
|
|
@listener(command="yvlu",
|
2022-06-26 11:59:09 +00:00
|
|
|
description="将回复的消息或者输入的字符串转换成语录")
|
2022-08-08 07:40:19 +00:00
|
|
|
async def yv_lu(bot: Client, message: Message):
|
2022-06-26 13:16:45 +00:00
|
|
|
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):
|
2022-08-08 07:40:19 +00:00
|
|
|
await bot.unblock_user(bot_username)
|
|
|
|
async with bot.conversation(bot_username) as conv:
|
2022-08-09 13:50:03 +00:00
|
|
|
try:
|
|
|
|
await reply.forward(bot_username)
|
|
|
|
except ChatForwardsRestricted:
|
|
|
|
return await message.edit('群组消息不允许被转发。')
|
2022-08-08 07:40:19 +00:00
|
|
|
await sleep(.1)
|
2022-06-26 13:16:45 +00:00
|
|
|
chat_response = await conv.get_response()
|
|
|
|
await conv.mark_as_read()
|
2022-08-08 07:40:19 +00:00
|
|
|
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()
|