From 20ec59ce5fea7561e554e3aae85cb7a44c4975e4 Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Mon, 20 Mar 2023 01:35:48 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=B3=A2=E7=82=B9=E9=9F=B3=E4=B9=90=E4=B8=BB=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E9=98=BB=E5=A1=9E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 2c76e69..ca12d3c 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -66,9 +66,9 @@ export class tools extends plugin { permission: "master", }, { - reg: '^#波点音乐(.*)', - fnc: 'bodianMusic' - } + reg: "^#波点音乐(.*)", + fnc: "bodianMusic", + }, ], }); // http://api.tuwei.space/girl @@ -643,8 +643,8 @@ export class tools extends plugin { } async bodianMusic(e) { - const msg = e.msg.replace("#波点音乐").trim() - const API = `https://xiaobai.klizi.cn/API/music/bodian.php?msg=${msg}&n=&max=` + const msg = e.msg.replace("#波点音乐").trim(); + const API = `https://xiaobai.klizi.cn/API/music/bodian.php?msg=${msg}&n=&max=`; // 获取列表 const thisMethod = this; await axios.get(API).then(resp => { @@ -658,7 +658,7 @@ export class tools extends plugin { */ e.reply("请选择一个要播放的视频:\n" + resp.data); thisMethod.setContext("bodianMusicContext"); - }) + }); return true; } @@ -672,15 +672,23 @@ export class tools extends plugin { // 上一个消息 const preMsg = await this.getContext().bodianMusicContext; const msg = preMsg.msg.replace("#波点音乐", "").trim(); - const API = `https://xiaobai.klizi.cn/API/music/bodian.php?msg=${msg}&n=${Number(curMsg.msg)}&max=` + const API = `https://xiaobai.klizi.cn/API/music/bodian.php?msg=${msg}&n=${Number( + curMsg.msg, + )}&max=`; const thisMethod = this; - await axios.get(API).then(async res => { - const {songName, artist, coverUrl, highUrl, lowUrl, shortLowUrl} = res.data; - curMsg.reply([`${songName}-${artist}\n`, segment.image(coverUrl)]); - await thisMethod.downloadVideo(lowUrl).then(path => { - curMsg.reply(segment.video(path + "/temp.mp4")); - }) - }) + axios.get(API).then(async res => { + try { + const { songName, artist, coverUrl, highUrl, lowUrl, shortLowUrl } = res.data; + curMsg.reply([`${songName}-${artist}\n`, segment.image(coverUrl)]); + await thisMethod.downloadVideo(lowUrl).then(path => { + curMsg.reply(segment.video(path + "/temp.mp4")); + }); + } catch (err) { + curMsg.reply("发生网络错误,请重新发送!"); + } finally { + thisMethod.finish("bodianMusicContext"); + } + }); this.finish("bodianMusicContext"); }