From 89d1c3e287e3b57c36aa6ffb766ff8ec28550d29 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 1 Mar 2024 11:54:38 +0800 Subject: [PATCH] fix: add default md handler --- apps/chat.js | 13 ++++++++++--- apps/md.js | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 apps/md.js diff --git a/apps/chat.js b/apps/chat.js index 0c2aa41..80f9a70 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -1201,7 +1201,7 @@ export class chatgpt extends plugin { bingToken: previousConversation.bingToken } } - + let handler = this.e.runtime?.handler || {} try { if (Config.debug) { logger.mark({ conversation }) @@ -1396,7 +1396,15 @@ export class chatgpt extends plugin { if (Config.ttsMode === 'vits-uma-genshin-honkai' && ttsResponse.length > parseInt(Config.ttsAutoFallbackThreshold)) { await this.reply('回复的内容过长,已转为文本模式') } - await this.reply(await convertFaces(response, Config.enableRobotAt, e), e.isGroup) + let responseText = await convertFaces(response, Config.enableRobotAt, e) + if (handler.has('chatgpt.markdown.convert')) { + responseText = await handler.call('chatgpt.markdown.convert', this.e, { + content: responseText, + use, + prompt + }) + } + await this.reply(finalResponse, e.isGroup) if (quotemessage.length > 0) { this.reply(await makeForwardMsg(this.e, quotemessage.map(msg => `${msg.text} - ${msg.url}`))) } @@ -1436,7 +1444,6 @@ export class chatgpt extends plugin { this.reply('今日对话已达上限') return false } - let handler = this.e.runtime?.handler || {} let responseText = await convertFaces(response, Config.enableRobotAt, e) if (handler.has('chatgpt.markdown.convert')) { responseText = await handler.call('chatgpt.markdown.convert', this.e, { diff --git a/apps/md.js b/apps/md.js new file mode 100644 index 0000000..14be0b1 --- /dev/null +++ b/apps/md.js @@ -0,0 +1,23 @@ +import plugin from '../../../lib/plugins/plugin.js' +import cfg from '../../../lib/config/config.js' +export class ChatGPTMarkdownHandler extends plugin { + constructor () { + super({ + name: 'chatgptmd处理器', + priority: -100, + namespace: 'chatgpt-plugin', + handler: [{ + key: 'chatgpt.markdown.convert', + fn: 'mdHandler' + }] + }) + } + + async mdHandler (e, options, reject) { + if (cfg.bot.global_md) { + const { content, prompt, use } = options + let md = `> ${prompt}\n\n---\n${content}\n\n---\n*当前模式:${use}*` + return md + } + } +}