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
|
|
|
|
|
|
|
|
2023-07-01 12:18:58 +00:00
|
|
|
@listener(command="yvlu", description="将回复的消息或者输入的字符串转换成语录")
|
2022-08-08 07:40:19 +00:00
|
|
|
async def yv_lu(bot: Client, message: Message):
|
2023-08-02 15:16:52 +00:00
|
|
|
bot_username = "PagerMaid_QuotLyBot"
|
2022-06-26 13:16:45 +00:00
|
|
|
if message.reply_to_message:
|
|
|
|
reply = message.reply_to_message
|
|
|
|
elif message.parameter:
|
|
|
|
reply = await message.edit(message.arguments)
|
|
|
|
else:
|
2023-07-01 12:18:58 +00:00
|
|
|
return await message.edit("你需要回复一条消息或者输入一串字符。")
|
2022-06-26 13:16:45 +00:00
|
|
|
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:
|
2023-07-01 12:18:58 +00:00
|
|
|
return await message.edit("群组消息不允许被转发。")
|
|
|
|
await sleep(0.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,
|
2024-02-04 07:56:06 +00:00
|
|
|
reply_to_message_id=message.reply_to_message_id,
|
|
|
|
message_thread_id=message.message_thread_id,
|
2023-07-01 12:18:58 +00:00
|
|
|
)
|
2022-08-08 07:40:19 +00:00
|
|
|
except Flood as e:
|
|
|
|
await sleep(e.value + 1)
|
|
|
|
with contextlib.suppress(Exception):
|
|
|
|
await chat_response.copy(
|
|
|
|
message.chat.id,
|
2024-02-04 07:56:06 +00:00
|
|
|
reply_to_message_id=message.reply_to_message_id,
|
|
|
|
message_thread_id=message.message_thread_id,
|
2023-07-01 12:18:58 +00:00
|
|
|
)
|
2022-08-08 07:40:19 +00:00
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
await message.safe_delete()
|