PagerMaid_Plugins_Pyro/audio_to_voice/main.py

36 lines
1.1 KiB
Python
Raw Normal View History

from pagermaid.listener import listener
from pagermaid.enums import Client, Message
2024-09-28 14:35:08 +00:00
from pagermaid.utils import safe_remove
async def get_audio(message: Message):
if reply := message.reply_to_message:
if reply.audio:
return reply
return message if message.audio else None
2023-07-01 12:18:58 +00:00
@listener(command="audio_to_voice", description="将音乐文件转换为语音")
async def audio_to_voice(bot: Client, message: Message):
audio = await get_audio(message)
if not audio:
return await message.edit("请回复一个音乐文件")
message: Message = await message.edit("转换中。。。")
try:
audio = await audio.download()
await bot.send_voice(
message.chat.id,
audio,
2023-07-01 12:18:58 +00:00
reply_to_message_id=message.id
if message.audio
2024-02-04 07:56:06 +00:00
else message.reply_to_message_id,
message_thread_id=message.message_thread_id,
2023-07-01 12:18:58 +00:00
)
except Exception as e:
await message.edit(f"转换为语音消息失败:{e}")
safe_remove(audio)
if not message.audio:
await message.safe_delete()
else:
await message.edit("")