From bf75c002c02c6443b9858427e02207b8de265031 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 24 Feb 2024 16:52:01 +0800 Subject: [PATCH] fix: remove long translation result forward --- apps/entertainment.js | 8 ++++---- utils/translate.js | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/entertainment.js b/apps/entertainment.js index b32fa08..1de8d70 100644 --- a/apps/entertainment.js +++ b/apps/entertainment.js @@ -170,10 +170,10 @@ ${translateLangLabels} await this.reply(err.message, e.isGroup) return false } - const totalLength = Array.isArray(result) - ? result.reduce((acc, cur) => acc + cur.length, 0) - : result.length - if (totalLength > 300 || multiText) { + // const totalLength = Array.isArray(result) + // ? result.reduce((acc, cur) => acc + cur.length, 0) + // : result.length + if (multiText) { // 多条翻译结果 if (Array.isArray(result)) { result = await makeForwardMsg(e, result, '翻译结果') diff --git a/utils/translate.js b/utils/translate.js index c061195..d290a19 100644 --- a/utils/translate.js +++ b/utils/translate.js @@ -122,6 +122,15 @@ export async function translate (msg, to = 'auto', from = 'auto', ai = Config.tr // if ai is not in the list, throw error if (!['openai', 'gemini', 'xh', 'qwen'].includes(ai)) throw new Error('ai来源错误') let system = `You will be provided with a sentence in the language with language code [${from}], and your task is to translate it into [${lang}]. Just print the result without any other words.` + if (Array.isArray(msg)) { + let result = [] + for (let i = 0; i < msg.length; i++) { + let item = msg[i] + let res = await translate(item, to, from, ai) + result.push(res) + } + return result + } switch (ai) { case 'openai': { let api = new ChatGPTAPI({