PagerMaid_Plugins_Pyro/netease/main.py

94 lines
3.2 KiB
Python
Raw Normal View History

2022-06-30 06:54:54 +00:00
""" PagerMaid Netease Plugin , Thanks to @Music163bot """
from pyrogram.errors import YouBlockedUser
from pyrogram import filters
from pagermaid.listener import listener
2022-09-01 08:28:48 +00:00
from pagermaid.enums import Message
2024-09-28 14:35:08 +00:00
from pagermaid.services import bot
2022-06-30 06:54:54 +00:00
from pagermaid.utils import alias_command
Netease_Help_Msg = f"""
网易云搜/点歌
i.e.
`,{alias_command('netease')} 失眠飞行 兔籽鲸 / 雨客Yoker` # 通过歌曲名称+歌手(可选)点歌
`,{alias_command('netease')} https://music.163.com/#/song?id=1430702717` # 通过歌曲链接点歌
`,{alias_command('netease')} 1430702717` # 通过歌曲 ID 点歌
"""
async def netease_start() -> None:
try:
await bot.send_message("Music163bot", "/start")
except YouBlockedUser:
await bot.unblock_user("Music163bot")
async def netease_search(keyword: str, message: Message):
2022-09-01 08:28:48 +00:00
async with bot.conversation("Music163bot") as conv:
2022-06-30 06:54:54 +00:00
await conv.send_message(f"/search {keyword}")
await conv.mark_as_read()
answer: Message = await conv.get_response(filters=~filters.regex("搜索中..."))
await conv.mark_as_read()
if not answer.reply_markup:
return await message.edit(answer.text.html)
await bot.request_callback_answer(
2023-07-01 12:18:58 +00:00
answer.chat.id,
answer.id,
callback_data=answer.reply_markup.inline_keyboard[0][0].callback_data,
)
2022-06-30 06:54:54 +00:00
await conv.mark_as_read()
answer: Message = await conv.get_response(filters=filters.audio)
await conv.mark_as_read()
2022-11-18 08:41:46 +00:00
await answer.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,
2022-11-18 08:41:46 +00:00
)
2022-06-30 06:54:54 +00:00
await message.safe_delete()
async def netease_url(url: str, message: Message):
2022-09-01 08:28:48 +00:00
async with bot.conversation("Music163bot") as conv:
2022-06-30 06:54:54 +00:00
await conv.send_message(url)
await conv.mark_as_read()
answer: Message = await conv.get_response(filters=filters.audio)
await conv.mark_as_read()
2022-11-18 08:41:46 +00:00
await answer.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,
2022-11-18 08:41:46 +00:00
)
2022-06-30 06:54:54 +00:00
await message.safe_delete()
async def netease_id(music_id: str, message: Message):
2022-09-01 08:28:48 +00:00
async with bot.conversation("Music163bot") as conv:
2022-06-30 06:54:54 +00:00
await conv.send_message(f"/music {music_id}")
await conv.mark_as_read()
answer: Message = await conv.get_response(filters=filters.audio)
await conv.mark_as_read()
2022-11-18 08:41:46 +00:00
await answer.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,
2022-11-18 08:41:46 +00:00
)
2022-06-30 06:54:54 +00:00
await message.safe_delete()
2023-07-01 12:18:58 +00:00
@listener(
command="netease",
description="Netease Music",
parameters="[query]",
)
2022-06-30 06:54:54 +00:00
async def netease_music(message: Message):
if not message.arguments:
return await message.edit(Netease_Help_Msg)
await netease_start()
if message.arguments.startswith("http"):
return await netease_url(message.arguments, message)
if message.arguments.isdigit():
return await netease_id(message.arguments, message)
return await netease_search(message.arguments, message)