fix: no quotes in picture mode

This commit is contained in:
ikechan8370 2023-02-24 16:17:51 +08:00
parent 1247aef5bb
commit b5887e6962

View file

@ -270,20 +270,20 @@ export class chatgpt extends plugin {
if (Config.imgOcr) { if (Config.imgOcr) {
// 取消息中的图片、at的头像、回复的图片放入e.img // 取消息中的图片、at的头像、回复的图片放入e.img
if (e.at && !e.source) { if (e.at && !e.source) {
e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`]; e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`]
} }
if (e.source) { if (e.source) {
let reply; let reply
if (e.isGroup) { if (e.isGroup) {
reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message; reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message
} else { } else {
reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message; reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message
} }
if (reply) { if (reply) {
for (let val of reply) { for (let val of reply) {
if (val.type == "image") { if (val.type == 'image') {
e.img = [val.url]; e.img = [val.url]
break; break
} }
} }
} }
@ -323,7 +323,7 @@ export class chatgpt extends plugin {
let confirmOn = (!confirm || confirm === 'on') && Config.thinkingTips let confirmOn = (!confirm || confirm === 'on') && Config.thinkingTips
if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) { if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) {
// 添加超时设置 // 添加超时设置
await redis.pSetEx("CHATGPT:CHAT_QUEUE_TIMEOUT", Config.defaultTimeoutMs, randomId); await redis.pSetEx('CHATGPT:CHAT_QUEUE_TIMEOUT', Config.defaultTimeoutMs, randomId)
if (confirmOn) { if (confirmOn) {
await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 8 }) await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 8 })
} }
@ -336,13 +336,13 @@ export class chatgpt extends plugin {
// 开始排队 // 开始排队
while (true) { while (true) {
if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) { if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) {
await redis.pSetEx("CHATGPT:CHAT_QUEUE_TIMEOUT", Config.defaultTimeoutMs, randomId); await redis.pSetEx('CHATGPT:CHAT_QUEUE_TIMEOUT', Config.defaultTimeoutMs, randomId)
break break
} else { } else {
// 超时检查 // 超时检查
if (await redis.exists("CHATGPT:CHAT_QUEUE_TIMEOUT") === 0) { if (await redis.exists('CHATGPT:CHAT_QUEUE_TIMEOUT') === 0) {
await redis.lPop('CHATGPT:CHAT_QUEUE', 0) await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
await redis.pSetEx("CHATGPT:CHAT_QUEUE_TIMEOUT", Config.defaultTimeoutMs, await redis.lIndex('CHATGPT:CHAT_QUEUE', 0)); await redis.pSetEx('CHATGPT:CHAT_QUEUE_TIMEOUT', Config.defaultTimeoutMs, await redis.lIndex('CHATGPT:CHAT_QUEUE', 0))
if (confirmOn) { if (confirmOn) {
let length = await redis.lLen('CHATGPT:CHAT_QUEUE') - 1 let length = await redis.lLen('CHATGPT:CHAT_QUEUE') - 1
await this.reply(`问题想不明白放弃了,开始思考下一个问题,当前队列前方还有${length}个问题`, true, { recallMsg: 8 }) await this.reply(`问题想不明白放弃了,开始思考下一个问题,当前队列前方还有${length}个问题`, true, { recallMsg: 8 })
@ -448,16 +448,6 @@ export class chatgpt extends plugin {
usePicture: Config.defaultUsePicture usePicture: Config.defaultUsePicture
} }
} }
if (userSetting.usePicture) {
// todo use next api of chatgpt to complete incomplete respoonse
try {
await this.renderImage(e, use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', response, prompt, [], Config.showQRCode)
} catch (err) {
logger.warn('error happened while uploading content to the cache server. QR Code will not be showed in this picture.')
logger.error(err)
await this.renderImage(e, use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', response, prompt)
}
} else {
let quotemessage = [] let quotemessage = []
if (chatMessage?.quote) { if (chatMessage?.quote) {
chatMessage.quote.forEach(function (item, index) { chatMessage.quote.forEach(function (item, index) {
@ -466,8 +456,8 @@ export class chatgpt extends plugin {
} }
}) })
} }
if (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold) { if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
// 文字过多时自动切换到图片模式输出 // todo use next api of chatgpt to complete incomplete respoonse
try { try {
await this.renderImage(e, use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', response, prompt, quotemessage, Config.showQRCode) await this.renderImage(e, use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', response, prompt, quotemessage, Config.showQRCode)
} catch (err) { } catch (err) {
@ -481,7 +471,6 @@ export class chatgpt extends plugin {
this.reply(await makeForwardMsg(this.e, quotemessage)) this.reply(await makeForwardMsg(this.e, quotemessage))
} }
} }
}
if (use !== 'bing') { if (use !== 'bing') {
// 移除队列首位,释放锁 // 移除队列首位,释放锁
await redis.lPop('CHATGPT:CHAT_QUEUE', 0) await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
@ -521,7 +510,7 @@ export class chatgpt extends plugin {
content: new Buffer.from(content).toString('base64'), content: new Buffer.from(content).toString('base64'),
prompt, prompt,
senderName: e.sender.nickname, senderName: e.sender.nickname,
quote: quote quote
}, },
bing: use === 'bing', bing: use === 'bing',
entry: Config.cacheEntry ? cacheData.file : '' entry: Config.cacheEntry ? cacheData.file : ''
@ -537,7 +526,7 @@ export class chatgpt extends plugin {
} }
} }
await e.runtime.render('chatgpt-plugin', template, { await e.runtime.render('chatgpt-plugin', template, {
content: new Buffer.from(content).toString("base64"), content: new Buffer.from(content).toString('base64'),
prompt: escapeHtml(prompt), prompt: escapeHtml(prompt),
senderName: e.sender.nickname, senderName: e.sender.nickname,
quote: quote.length > 0, quote: quote.length > 0,