From 83c789baf4e5040b7eff18aed7a568ea236d4229 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 14 Mar 2023 20:36:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=87=E9=95=BF?= =?UTF-8?q?=E8=AE=BE=E5=AE=9A=E5=8F=91=E4=B8=8D=E5=87=BA=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=E3=80=82=E5=90=8E=E7=BB=AD=E7=94=A8=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/prompts.js | 7 ++++--- utils/common.js | 8 ++++++++ utils/prompts.js | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/prompts.js b/apps/prompts.js index f38df77..ee13cc1 100644 --- a/apps/prompts.js +++ b/apps/prompts.js @@ -2,7 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js' import fs from 'fs' import _ from 'lodash' import { Config } from '../utils/config.js' -import { makeForwardMsg } from '../utils/common.js' +import {limitString, makeForwardMsg} from '../utils/common.js' import { getPromptByName, readPrompts, saveOnePrompt } from '../utils/prompts.js' export class help extends plugin { constructor (e) { @@ -63,7 +63,8 @@ export class help extends plugin { } prompts.push(...[defaultPrompt, defaultSydneyPrompt]) prompts.push(...readPrompts()) - e.reply(await makeForwardMsg(e, prompts.map(p => `《${p.name}》\n${p.content}`), '设定列表')) + console.log(prompts) + e.reply(await makeForwardMsg(e, prompts.map(p => `《${p.name}》\n${limitString(p.content, 500)}`), '设定列表')) } async detailPrompt (e) { @@ -85,7 +86,7 @@ export class help extends plugin { return } } - await e.reply(`《${prompt.name}》\n${prompt.content}`, true) + await e.reply(`《${prompt.name}》\n${limitString(p.content, 500)}`, true) } async usePrompt (e) { diff --git a/utils/common.js b/utils/common.js index a2d5182..3b6f676 100644 --- a/utils/common.js +++ b/utils/common.js @@ -374,3 +374,11 @@ export async function isCN () { } } } + +export function limitString(str, maxLength) { + if (str.length <= maxLength) { + return str; + } else { + return str.slice(0, maxLength) + '...'; + } +} diff --git a/utils/prompts.js b/utils/prompts.js index 0250bb7..60f78c7 100644 --- a/utils/prompts.js +++ b/utils/prompts.js @@ -1,6 +1,6 @@ import _ from 'lodash' import fs from 'fs' -import {mkdirs} from "./common.js"; +import { mkdirs } from './common.js' export function readPrompts () { const _path = process.cwd() let prompts = []