mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-06 12:20:00 +08:00
update 0.0.6.2
This commit is contained in:
Regular → Executable
+57
-57
@@ -1,57 +1,57 @@
|
||||
from .music_163 import get_song_id, get_song_info
|
||||
from nonebot.adapters.cqhttp import Bot, Event, GroupMessageEvent
|
||||
from nonebot.typing import T_State
|
||||
from services.log import logger
|
||||
from nonebot import on_command
|
||||
|
||||
|
||||
__zx_plugin_name__ = "点歌"
|
||||
__plugin_usage__ = """
|
||||
usage:
|
||||
在线点歌
|
||||
指令:
|
||||
点歌 [歌名]
|
||||
""".strip()
|
||||
__plugin_des__ = "为你点播了一首曾经的歌"
|
||||
__plugin_cmd__ = ["点歌 [歌名]"]
|
||||
__plugin_type__ = ("一些工具",)
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"level": 5,
|
||||
"default_status": True,
|
||||
"limit_superuser": False,
|
||||
"cmd": ["点歌"],
|
||||
}
|
||||
|
||||
|
||||
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["song_name"] = args
|
||||
|
||||
|
||||
@songpicker.got("song_name", prompt="歌名是?")
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
song = state["song_name"]
|
||||
song_id = await get_song_id(song)
|
||||
if not song_id:
|
||||
await songpicker.finish("没有找到这首歌!", at_sender=True)
|
||||
for _ in range(3):
|
||||
song_content = [{"type": "music", "data": {"type": 163, "id": song_id}}]
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 点歌 :{song}"
|
||||
)
|
||||
await songpicker.finish(song_content)
|
||||
else:
|
||||
await songpicker.finish("网易云繁忙...")
|
||||
|
||||
|
||||
|
||||
|
||||
from .music_163 import get_song_id, get_song_info
|
||||
from nonebot.adapters.cqhttp import Bot, Event, GroupMessageEvent
|
||||
from nonebot.typing import T_State
|
||||
from services.log import logger
|
||||
from nonebot import on_command
|
||||
|
||||
|
||||
__zx_plugin_name__ = "点歌"
|
||||
__plugin_usage__ = """
|
||||
usage:
|
||||
在线点歌
|
||||
指令:
|
||||
点歌 [歌名]
|
||||
""".strip()
|
||||
__plugin_des__ = "为你点播了一首曾经的歌"
|
||||
__plugin_cmd__ = ["点歌 [歌名]"]
|
||||
__plugin_type__ = ("一些工具",)
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"level": 5,
|
||||
"default_status": True,
|
||||
"limit_superuser": False,
|
||||
"cmd": ["点歌"],
|
||||
}
|
||||
|
||||
|
||||
music = on_command("点歌", priority=5, block=True)
|
||||
|
||||
|
||||
@music.handle()
|
||||
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
|
||||
args = str(event.get_message()).strip()
|
||||
if args:
|
||||
state["song_name"] = args
|
||||
|
||||
|
||||
@music.got("song_name", prompt="歌名是?")
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
song = state["song_name"]
|
||||
song_id = await get_song_id(song)
|
||||
if not song_id:
|
||||
await music.finish("没有找到这首歌!", at_sender=True)
|
||||
for _ in range(3):
|
||||
song_content = [{"type": "music", "data": {"type": 163, "id": song_id}}]
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 点歌 :{song}"
|
||||
)
|
||||
await music.finish(song_content)
|
||||
else:
|
||||
await music.finish("网易云繁忙...")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Regular → Executable
+38
-47
@@ -1,47 +1,38 @@
|
||||
import aiohttp
|
||||
import json
|
||||
|
||||
|
||||
headers = {"referer": "http://music.163.com"}
|
||||
cookies = {"appver": "2.0.2"}
|
||||
|
||||
|
||||
async def search_song(song_name: str):
|
||||
async with aiohttp.ClientSession(
|
||||
headers=headers, cookies=cookies
|
||||
) as session:
|
||||
async with session.post(
|
||||
f"http://music.163.com/api/search/get/",
|
||||
data={"s": song_name, "limit": 1, "type": 1, "offset": 0},
|
||||
) as r:
|
||||
if r.status != 200:
|
||||
return None
|
||||
r = await r.text()
|
||||
return json.loads(r)
|
||||
|
||||
|
||||
async def get_song_id(songName: str) -> int:
|
||||
"""
|
||||
根据用户输入的songName 获取候选songId列表 [默认songId数量:5]
|
||||
"""
|
||||
r = await search_song(songName)
|
||||
return r["result"]["songs"][0]["id"]
|
||||
|
||||
|
||||
async def get_song_info(songId: int):
|
||||
"""
|
||||
获取歌曲信息
|
||||
"""
|
||||
async with aiohttp.ClientSession(
|
||||
headers=headers, cookies=cookies
|
||||
) as session:
|
||||
async with session.post(
|
||||
f"http://music.163.com/api/song/detail/?id={songId}&ids=%5B{songId}%5D",
|
||||
) as r:
|
||||
if r.status != 200:
|
||||
return None
|
||||
r = await r.text()
|
||||
return json.loads(r)
|
||||
|
||||
|
||||
|
||||
from utils.http_utils import AsyncHttpx
|
||||
import json
|
||||
|
||||
|
||||
headers = {"referer": "http://music.163.com"}
|
||||
cookies = {"appver": "2.0.2"}
|
||||
|
||||
|
||||
async def search_song(song_name: str):
|
||||
"""
|
||||
搜索歌曲
|
||||
:param song_name: 歌名
|
||||
"""
|
||||
r = await AsyncHttpx.post(
|
||||
f"http://music.163.com/api/search/get/",
|
||||
data={"s": song_name, "limit": 1, "type": 1, "offset": 0},
|
||||
)
|
||||
if r.status_code != 200:
|
||||
return None
|
||||
return json.loads(r.text)
|
||||
|
||||
|
||||
async def get_song_id(song_name: str) -> int:
|
||||
""" """
|
||||
r = await search_song(song_name)
|
||||
return r["result"]["songs"][0]["id"]
|
||||
|
||||
|
||||
async def get_song_info(songId: int):
|
||||
"""
|
||||
获取歌曲信息
|
||||
"""
|
||||
r = await AsyncHttpx.post(
|
||||
f"http://music.163.com/api/song/detail/?id={songId}&ids=%5B{songId}%5D",
|
||||
)
|
||||
if r.status_code != 200:
|
||||
return None
|
||||
return json.loads(r.text)
|
||||
|
||||
Reference in New Issue
Block a user