diff --git a/apps/chat.js b/apps/chat.js index 4b55344..cdb7a61 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -267,6 +267,40 @@ export class chatgpt extends plugin { return false } } + if (Config.imgOcr) { + // 取消息中的图片、at的头像、回复的图片,放入e.img + if (e.at && !e.source) { + e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`]; + } + if (e.source) { + let reply; + if (e.isGroup) { + reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message; + } else { + reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message; + } + if (reply) { + for (let val of reply) { + if (val.type == "image") { + e.img = [val.url]; + break; + } + } + } + } + if (e.img) { + try { + const imgorc = await Bot.imageOcr(e.img[0]) + if (imgorc.language === 'zh' || imgorc.language === 'en') { + let imgtext = '' + for (let text of imgorc.wordslist) { + imgtext += `${text.words}\n` + } + prompt = imgtext + prompt + } + } catch (err) {} + } + } // 检索是否有屏蔽词 const promtBlockWord = promptBlockWords.find(word => prompt.toLowerCase().includes(word.toLowerCase())) if (promtBlockWord) { diff --git a/config/config.example.js b/config/config.example.js index ef485de..a24d6ae 100644 --- a/config/config.example.js +++ b/config/config.example.js @@ -11,6 +11,7 @@ export default { // blockWords: ['屏蔽词1', '屏蔽词b'], // 问题中如果触发屏蔽词,也会拒绝回答 // promptBlockWords: ['屏蔽词1', '屏蔽词b'], + // imgOcr: true, // 改为true后,全局默认以图片形式回复,并自动发出Continue命令补全回答。长回复可能会有bug。 // defaultUsePicture: false, // 如果true,字数大于阈值(autoUsePictureThreshold)会自动用图片发送,即使是文本模式。 diff --git a/guoba.support.js b/guoba.support.js index b7932a1..74cbde9 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -25,6 +25,24 @@ export function supportGuoba() { configInfo: { // 配置项 schemas schemas: [ + { + field: 'blockWords', + label: '输出黑名单', + bottomHelpMessage: '检查输出结果中是否有违禁词,如果存在黑名单中的违禁词则不输出', + component: 'Input', + }, + { + field: 'promptBlockWords', + label: '输入黑名单', + bottomHelpMessage: '检查输入结果中是否有违禁词,如果存在黑名单中的违禁词则不输出', + component: 'Input', + }, + { + field: 'imgOcr', + label: '图片识别', + bottomHelpMessage: '是否识别消息中图片的文字内容,需要同时包含图片和消息才生效', + component: 'Switch', + }, { field: 'defaultUsePicture', label: '全局图片模式', @@ -241,6 +259,9 @@ export function supportGuoba() { // 设置配置的方法(前端点确定后调用的方法) setConfigData(data, {Result}) { for (let [keyPath, value] of Object.entries(data)) { + // 处理黑名单 + if (keyPath === 'blockWords' || keyPath === 'promptBlockWords') + value = value.toString().split(/[,,;;\|]/) if (Config[keyPath] != value) Config[keyPath] = value } diff --git a/utils/config.js b/utils/config.js index 6dcf189..554a3ad 100644 --- a/utils/config.js +++ b/utils/config.js @@ -3,6 +3,7 @@ import lodash from 'lodash' const defaultConfig = { blockWords: ['屏蔽词1', '屏蔽词b'], promptBlockWords: ['屏蔽词1', '屏蔽词b'], + imgOcr: true, defaultUsePicture: false, autoUsePicture: true, autoUsePictureThreshold: 1200, @@ -47,7 +48,7 @@ export const Config = new Proxy(config, { target[property] = value; const change = lodash.transform(target, function(result, value, key) { if (!lodash.isEqual(value, defaultConfig[key])) { - result[key] = (lodash.isObject(value) && lodash.isObject(defaultConfig[key])) ? changes(value, defaultConfig[key]) : value; + result[key] = value; } }); try {