修复搜索关键词错误时报错,以及一些其他小bug

This commit is contained in:
TNTcraftHIM 2020-08-28 17:36:06 +08:00
parent 1b55fdaa3f
commit 5e117c5348
2 changed files with 18 additions and 8 deletions

View File

@ -282,10 +282,10 @@
},
{
"name": "neteasemusic",
"version": "2.1",
"version": "2.2",
"section": "daily",
"maintainer": "TNTcraftHIM",
"size": "22.4 kb",
"size": "22.9 kb",
"supported": true,
"des-short": "网易云点歌",
"des": "可以在线搜索并且快速点歌歌曲信息齐全支持直接回复点歌。命令nem。"

View File

@ -41,7 +41,11 @@ async def nem(context):
req = requests.request("GET", url, headers=headers)
if req.status_code == 200:
req = json.loads(req.content)
if req['result']:
if req['code'] == 200:
result = req['result']
else:
result = False
if result:
info = defaultdict()
for i in range(len(req['result']['songs'])):
info[i] = {'id': '', 'title': '', 'alias': '',
@ -64,23 +68,24 @@ async def nem(context):
info[i]['album'] + '</a>'
text += f"<strong>专辑</strong> {res} \n"
text += f"<strong>作者</strong> {info[i]['artist']}\n<strong>歌曲ID</strong> <code>{info[i]['id']}</code>\n————————\n"
text += "回复此消息 <code>-nem p <歌曲序号></code> 即可点歌"
text += "<strong>回复此消息</strong> <code>-nem p <歌曲序号></code> <strong>即可点歌</strong>"
await context.edit(text, parse_mode='html', link_preview=True)
status = True
break
else:
await context.edit("**未搜索到结果**")
sleep(3)
await context.delete()
status = True
break
else:
continue
if status is False:
await context.edit("出错了呜呜呜 ~ 试了好多好多次都无法访问到 API 服务器 。")
sleep(2)
sleep(3)
await context.delete()
return
if context.parameter[0] == "p": # 播放功能
elif context.parameter[0] == "p": # 播放功能
try:
reply = await context.get_reply_message()
except ValueError:
@ -395,6 +400,8 @@ async def nem(context):
break
else:
await context.edit("**未搜索到结果**")
sleep(3)
await context.delete()
status = True
break
else:
@ -402,5 +409,8 @@ async def nem(context):
if status is False:
await context.edit("出错了呜呜呜 ~ 试了好多好多次都无法访问到 API 服务器 。")
sleep(2)
sleep(3)
await context.delete()
else: #错误输入
await context.edit("使用方法:`-nem` `<指令>` `<关键词>`\n(指令s为搜索指令p为播放\n关键词可填歌曲ID或直接回复搜索结果 `-nem` `p` `<歌曲数字序号>`)")
return