fix: 命令正则;更改为回复消息

This commit is contained in:
ikechan8370 2022-12-07 10:37:20 +08:00 committed by GitHub
parent 09004accc1
commit d4a0cfc836
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,12 +17,14 @@ export class example extends plugin {
rule: [ rule: [
{ {
/** 命令正则匹配 */ /** 命令正则匹配 */
reg: '^#chatgpt.*$', reg: '^#chatgpt([\s\S]*)',
/** 执行方法 */ /** 执行方法 */
fnc: 'chatgpt' fnc: 'chatgpt'
} }
] ]
}) })
const api = new ChatGPTAPI({ sessionToken: SESSION_TOKEN, markdown: false })
this.chatGPTApi = api
} }
/** /**
* 调用chatgpt接口 * 调用chatgpt接口
@ -31,11 +33,17 @@ export class example extends plugin {
async chatgpt (e) { async chatgpt (e) {
logger.info(e.msg) logger.info(e.msg)
let question = _.trimStart(e.msg, "#chatgpt") let question = _.trimStart(e.msg, "#chatgpt")
question = question.trimStart()
logger.info(`chatgpt question: ${question}`) logger.info(`chatgpt question: ${question}`)
const api = new ChatGPTAPI({ sessionToken: SESSION_TOKEN, markdown: false }) await this.chatGPTApi.ensureAuth()
await api.ensureAuth() // @todo conversation
const response = await api.sendMessage(question) // const response = await this.chatGPTApi.sendMessage(question, { conversationId: '0c382256-d267-4dd4-90e3-a01dd22c20a2', onProgress: this.onProgress })
const response = await this.chatGPTApi.sendMessage(question)
/** 最后回复消息 */ /** 最后回复消息 */
await this.reply(`${response}`) await this.reply(`${response}`, true)
}
onProgress(partialResponse) {
console.log(partialResponse)
} }
} }