From 3dceb2a3327e5154073513f307906c3feda1e27c Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Thu, 30 May 2024 16:28:48 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=96=B0=E5=A2=9E=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E6=80=BB=E7=BB=93=E6=A8=A1=E5=9D=97=E7=9A=84=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E6=97=B6=E9=97=B4=E5=92=8C=E5=AD=97=E6=95=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 7 +++++-- utils/common.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) 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