zhenxun_bot/plugins/songpicker2/__init__.py

43 lines
1.4 KiB
Python
Raw Normal View History

2021-06-24 15:32:06 +08:00
from .music_163 import dataGet, dataProcess, get_music_id
2021-05-20 19:25:51 +08:00
from nonebot.adapters import Bot, Event
from nonebot.typing import T_State
from nonebot import on_command
2021-07-30 21:21:51 +08:00
__plugin_name__ = "点歌"
2021-06-15 10:57:08 +08:00
2021-07-30 21:21:51 +08:00
__plugin_usage__ = "用法:点歌 [歌名]"
2021-05-20 19:25:51 +08:00
dataget = dataGet()
songpicker = on_command("点歌", priority=5, block=True)
@songpicker.handle()
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
args = str(event.get_message()).strip()
if args:
state["songName"] = args
@songpicker.got("songName", prompt="歌名是?")
async def handle_songName(bot: Bot, event: Event, state: T_State):
songName = state["songName"]
songIdList = await dataget.songIds(songName=songName)
if not songIdList:
2021-06-24 15:32:06 +08:00
await songpicker.finish("没有找到这首歌!", at_sender=True)
for _ in range(3):
songInfoDict = await dataget.songInfo(songIdList[0])
2021-07-30 21:21:51 +08:00
if songInfoDict != "网易云网络繁忙!":
2021-06-24 15:32:06 +08:00
break
else:
await songpicker.finish("网易云繁忙...")
2021-05-20 19:25:51 +08:00
state["songIdList"] = songIdList
@songpicker.got("songName")
async def handle_songNum(bot: Bot, event: Event, state: T_State):
songIdList = state["songIdList"]
2021-06-24 15:32:06 +08:00
selectedSongId = songIdList[0]
2021-07-30 21:21:51 +08:00
songContent = [{"type": "music", "data": {"type": 163, "id": selectedSongId}}]
2021-05-20 19:25:51 +08:00
await songpicker.send(songContent)