From d17aa2a7ac23b20a213c254d1e246c338a41abed Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 9 Dec 2022 17:08:50 +0800 Subject: [PATCH] fix: add auth failed response --- index_no#.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index_no#.js b/index_no#.js index a6d955a..295404b 100644 --- a/index_no#.js +++ b/index_no#.js @@ -123,6 +123,12 @@ export class chatgpt extends plugin { } // let question = _.trimStart(e.msg, '#chatgpt') let question = e.msg.trimStart() + try { + await this.chatGPTApi.ensureAuth() + } catch (e) { + logger.error(e) + await this.reply(`OpenAI认证失败,请检查Token:${e}`, true) + } let c logger.info(`chatgpt question: ${question}`) let previousConversation = await redis.get(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`) @@ -146,7 +152,6 @@ export class chatgpt extends plugin { } try { // console.log({ c }) - await this.chatGPTApi.ensureAuth() const response = await c.sendMessage(question) logger.info(response) // 更新redis中的conversation对象,因为send后c已经被自动更新了