From 261184086daed6552edeb6c8e13f21193c8c9f3c Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Fri, 24 Mar 2023 09:01:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=93=94=E5=93=A9=E5=93=94=E5=93=A9=E6=80=BB=E7=BB=93=E7=9A=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 8 +++++++- utils/biliSummary.js | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index b77812a..3272ed5 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -353,7 +353,13 @@ export class tools extends plugin { // 如果有ck 并且 有openai的key if (this.biliSessData && this.openaiApiKey) { - const prompt = await getBiliGptInputText(title, aid, cid); + let prompt; + try { + prompt = await getBiliGptInputText(title, aid, cid); + } catch (err) { + logger.error("总结失败,可能是没有弹幕或者网络问题!"); + return true; + } const response = await this.chatGptClient.sendMessage(prompt); // 暂时不设计上下文 e.reply(response.response); diff --git a/utils/biliSummary.js b/utils/biliSummary.js index 63effa7..5710a1b 100644 --- a/utils/biliSummary.js +++ b/utils/biliSummary.js @@ -28,7 +28,10 @@ export async function getBiliGptInputText(title, aid, cid, shouldShowTimestamp = commonConfig, ); const subtitles = (await resp.json()).data.subtitle.subtitles; - const res = await fetch(`http:${subtitles[0].subtitle_url}`); + const res = await fetch(`http:${subtitles[0]?.subtitle_url}`); + if (_.isUndefined(res)) { + throw new Error(""); + } const subtitlesData = (await res.json()).body; const subtitleTimestamp = reduceBilibiliSubtitleTimestamp(subtitlesData, shouldShowTimestamp); const inputText = getSmallSizeTranscripts(subtitleTimestamp, subtitleTimestamp);