From d08e9e410253c6c6753a9148c01cac73f74f9510 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 11 Oct 2024 22:28:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=90=8E?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 9 +++++++++ apps/{ => post}/button.js | 4 ++-- apps/post/example_handler.js | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) rename apps/{ => post}/button.js (99%) create mode 100644 apps/post/example_handler.js diff --git a/apps/chat.js b/apps/chat.js index 2f934be..e8a1e58 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -823,6 +823,15 @@ export class chatgpt extends plugin { } } let response = chatMessage?.text?.replace('\n\n\n', '\n') + if (handler.has('chatgpt.response.post')) { + handler.call('chatgpt.response.post', this.e, { + content: response, + use, + prompt + }, true).catch(err => { + logger.error('后处理器出错', err) + }) + } let mood = 'blandness' if (!response) { await this.reply('没有任何回复', true) diff --git a/apps/button.js b/apps/post/button.js similarity index 99% rename from apps/button.js rename to apps/post/button.js index d443ba4..8e4f477 100644 --- a/apps/button.js +++ b/apps/post/button.js @@ -1,5 +1,5 @@ -import plugin from '../../../lib/plugins/plugin.js' -import { Config } from '../utils/config.js' +import plugin from '../../../../lib/plugins/plugin.js' +import { Config } from '../../utils/config.js' const PLUGIN_CHAT = 'ChatGpt 对话' const PLUGIN_MANAGEMENT = 'ChatGPT-Plugin 管理' diff --git a/apps/post/example_handler.js b/apps/post/example_handler.js new file mode 100644 index 0000000..b000473 --- /dev/null +++ b/apps/post/example_handler.js @@ -0,0 +1,26 @@ +import plugin from '../../../../lib/plugins/plugin.js' + +/** + * 示例后处理器。你可以在example下面写一个新的。默认会调用所有此key的处理器 + */ +export class ChatGPTResponsePostHandler extends plugin { + constructor () { + super({ + name: 'chatgpt文本回复后处理器', + priority: 999999, + namespace: 'chatgpt-plugin', + handler: [{ + key: 'chatgpt.response.post', // key必须是chatgpt.response.post + fn: 'postHandler' + }] + }) + } + + async postHandler (e, options, reject) { + const { content, use, prompt } = options + // 你可以在这里处理返回的文本,比如使用自定义的语音api来合成语音 + // const audio = customTTS(content) + // e.reply(segment.audio(audio)) + // 返回值会被忽略 + } +}