diff --git a/apps/tools.js b/apps/tools.js index c9fbe02..f73d500 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -34,7 +34,7 @@ import { } from "../constants/constant.js"; import { downloadImg, - downloadMp3, + downloadMp3, estimateReadingTime, formatBiliInfo, getIdVideo, retryAxiosReq, secondsToTime, @@ -1569,8 +1569,11 @@ export class tools extends plugin { .setModel(this.aiModel) .setPrompt(SUMMARY_PROMPT) .build(); - e.reply(`识别:${name},正在为您总结,请稍等...`); + e.reply(`识别:${name},正在为您总结,请稍等...`, true, { recallMsg: 60 }); const { ans: kimiAns, model } = await builder.kimi(summaryLink); + // 计算阅读时间 + const stats = estimateReadingTime(kimiAns); + e.reply(`当前 ${name} 预计阅读时间: ${stats.minutes} 分钟,总字数: ${stats.words}`) const Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您总结内容:`,kimiAns]); await e.reply(Msg); return true; diff --git a/utils/common.js b/utils/common.js index 63a6722..e37008f 100644 --- a/utils/common.js +++ b/utils/common.js @@ -377,4 +377,30 @@ export async function retryAxiosReq(requestFunction, retries = 3, delay = 1000) throw error; } } +} + +/** + * 统计给定文本中的字数 + * + * @param {string} text - The text to count words in + * @return {number} The number of words in the text + */ +export function countWords(text) { + return text.split(/\s+/).filter(word => word.length > 0).length; +} + +/** + * 根据每分钟平均单词数估计给定文本的阅读时间 + * + * @param {string} text - The text for which the reading time is estimated. + * @param {number} wpm - The average words per minute for calculating reading time. Default is 200. + * @return {Object} An object containing the estimated reading time in minutes and the word count. + */ +export function estimateReadingTime(text, wpm = 200) { + const wordCount = countWords(text); + const readingTimeMinutes = wordCount / wpm; + return { + minutes: Math.ceil(readingTimeMinutes), + words: wordCount + }; } \ No newline at end of file