Skip to content

Commit

Permalink
feat: 自定义后处理器
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Oct 11, 2024
1 parent f0a17dc commit d08e9e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
9 changes: 9 additions & 0 deletions apps/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions apps/button.js → apps/post/button.js
Original file line number Diff line number Diff line change
@@ -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 管理'
Expand Down
26 changes: 26 additions & 0 deletions apps/post/example_handler.js
Original file line number Diff line number Diff line change
@@ -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))
// 返回值会被忽略
}
}

0 comments on commit d08e9e4

Please sign in to comment.