From 91abd8a95947bd8af9e249b2bd687edf182aecf5 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Thu, 7 Dec 2023 22:41:44 +0800 Subject: [PATCH 01/13] =?UTF-8?q?feat:=20refresh=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=8E=B7=E5=8F=96sessKey=E4=BD=9C=E4=B8=BAAPI=20Key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/help.js | 7 ++++- apps/management.js | 78 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/apps/help.js b/apps/help.js index 8de904c..1c2a7c6 100644 --- a/apps/help.js +++ b/apps/help.js @@ -209,7 +209,12 @@ let helpData = [ { icon: 'token', title: '#chatgpt设置后台刷新token', - desc: '用于查看API余额。注意和配置的key保持同一账号。' + desc: '用于获取刷新令牌,以便获取sessKey。' + }, + { + icon: 'key', + title: '#chatgpt设置sessKey', + desc: '使用sessKey作为APIKey,适用于未手机号验证的用户' }, { icon: 'token', diff --git a/apps/management.js b/apps/management.js index 2a8d364..c482c4b 100644 --- a/apps/management.js +++ b/apps/management.js @@ -20,6 +20,23 @@ import fs from 'fs' import loader from '../../../lib/plugins/loader.js' import VoiceVoxTTS, { supportConfigurations as voxRoleList } from '../utils/tts/voicevox.js' import { supportConfigurations as azureRoleList } from '../utils/tts/microsoft-azure.js' +import fetch from 'node-fetch' +import { getProxy } from '../utils/proxy.js' + +let proxy = getProxy() +const newFetch = (url, options = {}) => { + const defaultOptions = Config.proxy + ? { + agent: proxy(Config.proxy) + } + : {} + const mergedOptions = { + ...defaultOptions, + ...options + } + + return fetch(url, mergedOptions) +} export class ChatgptManagement extends plugin { constructor (e) { @@ -254,6 +271,10 @@ export class ChatgptManagement extends plugin { reg: '^#chatgpt设置后台(刷新|refresh)(t|T)oken$', fnc: 'setOpenAIPlatformToken' }, + { + reg: '^#chatgpt设置sessKey$', + fnc: 'getSessKey' + }, { reg: '^#(chatgpt)?查看回复设置$', fnc: 'viewUserSetting' @@ -1114,8 +1135,8 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, async saveAPIKey () { if (!this.e.msg) return let token = this.e.msg - if (!token.startsWith('sk-')) { - await this.reply('OpenAI API Key格式错误', true) + if (!token.startsWith('sk-') && !token.startsWith('sess-')) { + await this.reply('OpenAI API Key格式错误。如果是格式特殊的非官方Key请前往锅巴或工具箱手动设置', true) this.finish('saveAPIKey') return } @@ -1302,7 +1323,58 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, async setOpenAIPlatformToken (e) { this.setContext('doSetOpenAIPlatformToken') - await e.reply('请发送refreshToken\n你可以在已登录的platform.openai.com后台界面打开调试窗口,在终端中执行\nJSON.parse(localStorage.getItem(Object.keys(localStorage).filter(k => k.includes(\'auth0\'))[0])).body.refresh_token\n如果仍不能查看余额,请退出登录重新获取刷新令牌') + await e.reply('请发送refreshToken\n你可以在已登录的platform.openai.com后台界面打开调试窗口,在终端中执行\nJSON.parse(localStorage.getItem(Object.keys(localStorage).filter(k => k.includes(\'auth0\'))[0])).body.refresh_token\n如果仍不能查看余额,请退出登录重新获取刷新令牌.设置后可以发送#chatgpt设置sessKey来将sessKey作为API Key使用') + } + + async getSessKey (e) { + if (!Config.OpenAiPlatformRefreshToken) { + this.reply('当前未配置platform.openai.com的刷新token,请发送【#chatgpt设置后台刷新token】进行配置。') + return false + } + let authHost = 'https://auth0.openai.com' + if (Config.openAiBaseUrl && !Config.openAiBaseUrl.startsWith('https://api.openai.com')) { + authHost = Config.openAiBaseUrl.replace('/v1', '').replace('/v1/', '') + } + let refreshRes = await newFetch(`${authHost}/oauth/token`, { + method: 'POST', + body: JSON.stringify({ + refresh_token: Config.OpenAiPlatformRefreshToken, + client_id: 'DRivsnm2Mu42T3KOpqdtwB3NYviHYzwD', + grant_type: 'refresh_token' + }) + }) + if (refreshRes.status !== 200) { + let errMsg = await refreshRes.json() + if (errMsg.error === 'access_denied') { + await e.reply('刷新令牌失效,请重新发送【#chatgpt设置后台刷新token】进行配置。建议退出platform.openai.com重新登录后再获取和配置') + } else { + await e.reply('获取失败') + } + return false + } + let newToken = await refreshRes.json() + // eslint-disable-next-line camelcase + const { access_token, refresh_token } = newToken + // eslint-disable-next-line camelcase + Config.OpenAiPlatformRefreshToken = refresh_token + let host = Config.openAiBaseUrl.replace('/v1', '').replace('/v1/', '') + let res = await newFetch(`${host}/dashboard/onboarding/login`, { + headers: { + // eslint-disable-next-line camelcase + Authorization: `Bearer ${access_token}` + }, + method: 'POST' + }) + if (res.status === 200) { + let authRes = await res.json() + let sess = authRes.user.session.sensitive_id + if (sess) { + Config.apiKey = sess + await e.reply('已成功将sessKey设置为apiKey,您可以发送#open余额来查看该账号余额') + } else { + await e.reply('设置失败!') + } + } } async doSetOpenAIPlatformToken () { From 2183822bf067da1872f019f06a4c31ae9ede6440 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Thu, 7 Dec 2023 22:46:35 +0800 Subject: [PATCH 02/13] =?UTF-8?q?fix:=20=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/management.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/management.js b/apps/management.js index c482c4b..d69ba34 100644 --- a/apps/management.js +++ b/apps/management.js @@ -269,11 +269,13 @@ export class ChatgptManagement extends plugin { }, { reg: '^#chatgpt设置后台(刷新|refresh)(t|T)oken$', - fnc: 'setOpenAIPlatformToken' + fnc: 'setOpenAIPlatformToken', + permission: 'master' }, { reg: '^#chatgpt设置sessKey$', - fnc: 'getSessKey' + fnc: 'getSessKey', + permission: 'master' }, { reg: '^#(chatgpt)?查看回复设置$', @@ -1345,6 +1347,7 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, }) if (refreshRes.status !== 200) { let errMsg = await refreshRes.json() + logger.error(JSON.stringify(errMsg)) if (errMsg.error === 'access_denied') { await e.reply('刷新令牌失效,请重新发送【#chatgpt设置后台刷新token】进行配置。建议退出platform.openai.com重新登录后再获取和配置') } else { From 46328a9716573fa6565ee68b34c871ad052675e2 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Thu, 7 Dec 2023 22:58:11 +0800 Subject: [PATCH 03/13] fix: headers --- apps/management.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/management.js b/apps/management.js index d69ba34..689dd28 100644 --- a/apps/management.js +++ b/apps/management.js @@ -1343,7 +1343,11 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, refresh_token: Config.OpenAiPlatformRefreshToken, client_id: 'DRivsnm2Mu42T3KOpqdtwB3NYviHYzwD', grant_type: 'refresh_token' - }) + }), + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', + 'Content-Type': 'application/json' + } }) if (refreshRes.status !== 200) { let errMsg = await refreshRes.json() @@ -1364,7 +1368,8 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, let res = await newFetch(`${host}/dashboard/onboarding/login`, { headers: { // eslint-disable-next-line camelcase - Authorization: `Bearer ${access_token}` + Authorization: `Bearer ${access_token}`, + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36' }, method: 'POST' }) @@ -1373,7 +1378,7 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, let sess = authRes.user.session.sensitive_id if (sess) { Config.apiKey = sess - await e.reply('已成功将sessKey设置为apiKey,您可以发送#open余额来查看该账号余额') + await e.reply('已成功将sessKey设置为apiKey,您可以发送#openai余额来查看该账号余额') } else { await e.reply('设置失败!') } From ae23e6d7f53126e188b9d8fc37bb1bf4e326240e Mon Sep 17 00:00:00 2001 From: HalcyonAlcedo <41666148+HalcyonAlcedo@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:53:19 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtrss=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E7=99=BB=E9=99=86=E5=90=8E=E5=8F=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#620)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复星火api上下文 * 将无星火ck的情况降低为warn * feat: 添加星火设定自定义代码功能 * 修复星火api模式的一些问题 * 修复导出配置问题 * feat:添加工具箱快捷登录接口 * 添加工具箱快捷登录指令 * 阻止群聊使用快捷登录 * 添加Azure配置支持,修复重复的配置项冲突 * 移除旧版本渲染和新版本帮助 * 添加工具箱 * 更新工具箱替换原有后台 * 更新工具箱适配代码 * 后台适配Trss * 修复trss不支持sendPrivateMsg的问题 * 优化路由 * 修复路由 * 适配其他uin * 添加bing第三方绘图 * 修复bing绘图第三方调用错误 * 添加bing第三方绘图采样配置 * 修复错误 * 添加bing第三方绘图图片大小配置 * 修复视图错误 * 使用ap替换第三方绘图 * 适配trss * server 适配trss * 修复错误的后台版本更新 * 添加锅巴用户数据 * 修复server初始化消息错误 * 添加锅巴插件适配 * 更新后台页面 * 添加锅巴代理接口 * 优化锅巴接口代理 * 修复锅巴代理参数 * 删除调试信息 * 修复headers * 更新后台锅巴插件支持 * 适配星火v3 * 适配星火v3 * 修复星火domain错误 * 修复更新后trss无法快捷登陆面板问题 * 奇怪的错误,忽略提示不影响使用 --- server/modules/user.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/modules/user.js b/server/modules/user.js index 38b9830..0bb7157 100644 --- a/server/modules/user.js +++ b/server/modules/user.js @@ -57,6 +57,7 @@ async function User (fastify, options) { // 快速登录 fastify.post('/quick', async (request, reply) => { const otp = randomString(6) + const isTrss = Array.isArray(Bot.uin) await redis.set( 'CHATGPT:SERVER_QUICK', otp, @@ -65,7 +66,15 @@ async function User (fastify, options) { const master = (await getMasterQQ())[0] let bots = getBots() for (let bot of bots) { - bot.pickUser(master).sendMsg(`收到工具箱快捷登录请求,1分钟内有效:${otp}`) + if(isTrss) { + try { + bot.pickFriend(master).sendMsg(`收到工具箱快捷登录请求,1分钟内有效:${otp}`) + } catch (error) { + logger.error(error) + } + } else { + bot.pickUser(master).sendMsg(`收到工具箱快捷登录请求,1分钟内有效:${otp}`) + } } reply.send({ state: true }) return reply From 247f3e15d0d6e93ba1037347e438cf15a44ca9af Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 10 Dec 2023 23:08:10 +0800 Subject: [PATCH 05/13] =?UTF-8?q?fix:=20=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E3=80=81=E6=96=87=E4=BB=B6=E3=80=81ocr=E7=AD=89=E8=BF=9B?= =?UTF-8?q?=E4=B8=80=E6=AD=A5=E9=80=82=E9=85=8Dshamrock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 31 ++++++++----------------------- utils/chat.js | 31 ++++++++++++++++++++++++++----- utils/common.js | 39 +++++++++++++++++++++++++++++++++++---- utils/config.js | 2 +- 4 files changed, 70 insertions(+), 33 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index 631d2f2..8b1bac4 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -797,7 +797,7 @@ export class chatgpt extends plugin { * #chatgpt */ async chatgpt (e) { - let msg = Version.isTrss ? e.msg : e.raw_message + let msg = (Version.isTrss || e.adapter === 'shamrock') ? e.msg : e.raw_message let prompt if (this.toggleMode === 'at') { if (!msg || e.msg?.startsWith('#')) { @@ -1669,7 +1669,11 @@ export class chatgpt extends plugin { let toSummaryFileContent try { if (e.source) { - let msgs = e.isGroup ? await e.group.getChatHistory(e.source.seq, 1) : await e.friend.getChatHistory(e.source.time, 1) + let seq = e.isGroup ? e.source.seq : e.source.time + if (e.adapter === 'shamrock') { + seq = e.source.message_id + } + let msgs = e.isGroup ? await e.group.getChatHistory(seq, 1) : await e.friend.getChatHistory(seq, 1) let sourceMsg = msgs[0] let fileMsgElem = sourceMsg.message.find(msg => msg.type === 'file') if (fileMsgElem) { @@ -2127,6 +2131,7 @@ export class chatgpt extends plugin { } } default: { + // openai api let completionParams = {} if (Config.model) { completionParams.model = Config.model @@ -2317,27 +2322,7 @@ export class chatgpt extends plugin { } } } - let img = [] - 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') { - console.log(val) - img.push(val.url) - } - } - } - } - if (e.img) { - img.push(...e.img) - } + let img = await getImg(e) if (img.length > 0 && Config.extraUrl) { tools.push(new ImageCaptionTool()) tools.push(new ProcessPictureTool()) diff --git a/utils/chat.js b/utils/chat.js index e249d0f..f37d5d9 100644 --- a/utils/chat.js +++ b/utils/chat.js @@ -1,3 +1,5 @@ +import common from '../../../lib/common/common.js' + export async function getChatHistoryGroup (e, num) { // if (e.adapter === 'shamrock') { // return await e.group.getChatHistory(0, num, false) @@ -16,12 +18,23 @@ export async function getChatHistoryGroup (e, num) { chats = chats.slice(0, num) try { let mm = await e.group.getMemberMap() - chats.forEach(chat => { - let sender = mm.get(chat.sender.user_id) - if (sender) { - chat.sender = sender + for (const chat of chats) { + if (e.adapter === 'shamrock') { + if (chat.sender?.user_id === 0) { + // 奇怪格式的历史消息,过滤掉 + continue + } + let sender = await pickMemberAsync(e, chat.sender.user_id) + if (sender) { + chat.sender = sender + } + } else { + let sender = mm.get(chat.sender.user_id) + if (sender) { + chat.sender = sender + } } - }) + } } catch (err) { logger.warn(err) } @@ -32,3 +45,11 @@ export async function getChatHistoryGroup (e, num) { // } return [] } + +function pickMemberAsync (e, userId) { + return new Promise((resolve, reject) => { + e.group.pickMember(userId, true, (sender) => { + resolve(sender) + }) + }) +} diff --git a/utils/common.js b/utils/common.js index f9b2de9..3c05aaf 100644 --- a/utils/common.js +++ b/utils/common.js @@ -13,7 +13,7 @@ import AzureTTS, { supportConfigurations as azureRoleList } from './tts/microsof import { translate } from './translate.js' import uploadRecord from './uploadRecord.js' import Version from './version.js' -import fetch from 'node-fetch' +import fetch, { FormData, fileFromSync } from 'node-fetch' let pdfjsLib try { pdfjsLib = (await import('pdfjs-dist')).default @@ -785,10 +785,14 @@ export async function getImg (e) { } if (e.source) { let reply + let seq = e.isGroup ? e.source.seq : e.source.time + if (e.adapter === 'shamrock') { + seq = e.source.message_id + } if (e.isGroup) { - reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message + reply = (await e.group.getChatHistory(seq, 1)).pop()?.message } else { - reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message + reply = (await e.friend.getChatHistory(seq, 1)).pop()?.message } if (reply) { let i = [] @@ -809,8 +813,34 @@ export async function getImageOcrText (e) { try { let resultArr = [] let eachImgRes = '' + if (!e.bot.imageOcr || typeof e.bot.imageOcr !== 'function') { + e.bot.imageOcr = async (image) => { + if (Config.extraUrl) { + let md5 = image.split(/[/-]/).find(s => s.length === 32)?.toUpperCase() + let filePath = await downloadFile(image, `ocr/${md5}.png`) + let formData = new FormData() + formData.append('file', fileFromSync(filePath)) + let res = await fetch(`${Config.extraUrl}/ocr?lang=chi_sim%2Beng`, { + body: formData, + method: 'POST', + headers: { + from: 'ikechan8370' + } + }) + if (res.status === 200) { + return { + wordslist: [{ words: await res.text() }] + } + } + } + return { + wordslist: [] + } + } + } for (let i in img) { const imgOCR = await e.bot.imageOcr(img[i]) + for (let text of imgOCR.wordslist) { eachImgRes += (`${text?.words} \n`) } @@ -820,6 +850,7 @@ export async function getImageOcrText (e) { // logger.warn('resultArr', resultArr) return resultArr } catch (err) { + logger.warn(err) logger.warn('OCR失败,可能使用的适配器不支持OCR') return false // logger.error(err) @@ -1061,7 +1092,7 @@ export async function extractContentFromFile (fileMsgElem, e) { let fileType = isPureText(fileMsgElem.name) if (fileType) { // 可读的文件类型 - let fileUrl = e.isGroup ? await e.group.getFileUrl(fileMsgElem.fid) : await e.friend.getFileUrl(fileMsgElem.fid) + let fileUrl = fileMsgElem.url || (e.isGroup ? await e.group.getFileUrl(fileMsgElem.fid) : await e.friend.getFileUrl(fileMsgElem.fid)) let filePath = await downloadFile(fileUrl, path.join('received', fileMsgElem.name)) switch (fileType) { case 'pdf': { diff --git a/utils/config.js b/utils/config.js index fe95971..7e94acc 100644 --- a/utils/config.js +++ b/utils/config.js @@ -162,7 +162,7 @@ const defaultConfig = { qwenSeed: 0, qwenTemperature: 1, qwenEnableSearch: true, - version: 'v2.7.7' + version: 'v2.7.8' } const _path = process.cwd() let config = {} From d254163fa72e10724170f74bcc795535ecb15500 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 10 Dec 2023 23:16:40 +0800 Subject: [PATCH 06/13] fix: bug fix --- apps/chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/chat.js b/apps/chat.js index 8b1bac4..9218175 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -2323,7 +2323,7 @@ export class chatgpt extends plugin { } } let img = await getImg(e) - if (img.length > 0 && Config.extraUrl) { + if (img?.length > 0 && Config.extraUrl) { tools.push(new ImageCaptionTool()) tools.push(new ProcessPictureTool()) prompt += `\nthe url of the picture(s) above: ${img.join(', ')}` From e61d4ff3fa406591b0487e436691e15f7ea008a8 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Mon, 11 Dec 2023 00:46:38 +0800 Subject: [PATCH 07/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BE=A4=E8=81=8A=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 4 ++-- utils/chat.js | 9 +++++++-- utils/common.js | 10 ++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index 9218175..9a06418 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -1674,8 +1674,8 @@ export class chatgpt extends plugin { seq = e.source.message_id } let msgs = e.isGroup ? await e.group.getChatHistory(seq, 1) : await e.friend.getChatHistory(seq, 1) - let sourceMsg = msgs[0] - let fileMsgElem = sourceMsg.message.find(msg => msg.type === 'file') + let sourceMsg = msgs[msgs.length - 1] + let fileMsgElem = sourceMsg.file || sourceMsg.message.find(msg => msg.type === 'file') if (fileMsgElem) { toSummaryFileContent = await extractContentFromFile(fileMsgElem, e) } diff --git a/utils/chat.js b/utils/chat.js index f37d5d9..097cee4 100644 --- a/utils/chat.js +++ b/utils/chat.js @@ -1,4 +1,3 @@ -import common from '../../../lib/common/common.js' export async function getChatHistoryGroup (e, num) { // if (e.adapter === 'shamrock') { @@ -46,9 +45,15 @@ export async function getChatHistoryGroup (e, num) { return [] } -function pickMemberAsync (e, userId) { +async function pickMemberAsync (e, userId) { + let key = `CHATGPT:GroupMemberInfo:${e.group_id}:${userId}` + let cache = await redis.get(key) + if (cache) { + return JSON.parse(cache) + } return new Promise((resolve, reject) => { e.group.pickMember(userId, true, (sender) => { + redis.set(key, JSON.stringify(sender), { EX: 86400 }) resolve(sender) }) }) diff --git a/utils/common.js b/utils/common.js index 3c05aaf..ab27aa5 100644 --- a/utils/common.js +++ b/utils/common.js @@ -14,6 +14,7 @@ import { translate } from './translate.js' import uploadRecord from './uploadRecord.js' import Version from './version.js' import fetch, { FormData, fileFromSync } from 'node-fetch' +import https from "https"; let pdfjsLib try { pdfjsLib = (await import('pdfjs-dist')).default @@ -1034,10 +1035,15 @@ export function getUserSpeaker (userSetting) { * @param url 要下载的文件链接 * @param destPath 目标路径,如received/abc.pdf. 目前如果文件名重复会覆盖。 * @param absolute 是否是绝对路径,默认为false,此时拼接在data/chatgpt下 + * @param ignoreCertificateError 忽略证书错误 * @returns {Promise} 最终下载文件的存储位置 */ -export async function downloadFile (url, destPath, absolute = false) { - let response = await fetch(url) +export async function downloadFile (url, destPath, absolute = false, ignoreCertificateError = true) { + let response = await fetch(url, { + agent: new https.Agent({ + rejectUnauthorized: !ignoreCertificateError + }) + }) if (!response.ok) { throw new Error(`download file http error: status: ${response.status}`) } From b8eaffe930d9b4b8c50fd3df3b80cb3d89fe2e96 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Mon, 11 Dec 2023 01:02:31 +0800 Subject: [PATCH 08/13] fix: query user info tools --- utils/tools/QueryUserinfoTool.js | 43 +++++++++++++++++++------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/utils/tools/QueryUserinfoTool.js b/utils/tools/QueryUserinfoTool.js index 493e7f5..974c08b 100644 --- a/utils/tools/QueryUserinfoTool.js +++ b/utils/tools/QueryUserinfoTool.js @@ -15,21 +15,13 @@ export class QueryUserinfoTool extends AbstractTool { } func = async function (opts, e) { - let { qq } = opts - qq = isNaN(qq) || !qq ? e.sender.user_id : parseInt(qq.trim()) - if (e.isGroup && typeof e.group.getMemberMap === 'function') { - let mm = await e.group.getMemberMap() - let user = mm.get(qq) || e.sender.user_id - let master = (await getMasterQQ())[0] - let prefix = '' - if (qq != master) { - prefix = 'Attention: this user is not your master. \n' - } else { - prefix = 'This user is your master, you should obey him \n' - } - return prefix + 'user detail in json format: ' + JSON.stringify(user) - } else { - if (e.sender.user_id == qq) { + try { + let { qq } = opts + qq = isNaN(qq) || !qq ? e.sender.user_id : parseInt(qq.trim()) + if (e.isGroup && typeof e.bot.getGroupMemberInfo === 'function') { + let user = await e.bot.getGroupMemberInfo(e.group_id, qq || e.sender.user_id, true) + // let mm = await e.group.getMemberMap() + // let user = mm.get(qq) || e.sender.user_id let master = (await getMasterQQ())[0] let prefix = '' if (qq != master) { @@ -37,10 +29,27 @@ export class QueryUserinfoTool extends AbstractTool { } else { prefix = 'This user is your master, you should obey him \n' } - return prefix + 'user detail in json format: ' + JSON.stringify(e.sender) + if (!user) { + return prefix + } + return prefix + 'user detail in json format: ' + JSON.stringify(user) } else { - return 'query failed' + if (e.sender.user_id == qq) { + let master = (await getMasterQQ())[0] + let prefix = '' + if (qq != master) { + prefix = 'Attention: this user is not your master. \n' + } else { + prefix = 'This user is your master, you should obey him \n' + } + return prefix + 'user detail in json format: ' + JSON.stringify(e.sender) + } else { + return 'query failed' + } } + } catch (err) { + logger.warn(err) + return err.message } } From 2f1c3317f401f37d1615584e1e7a8bbc5c60e567 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Mon, 11 Dec 2023 17:02:11 +0800 Subject: [PATCH 09/13] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 6d0e971..ec523ae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -![chatgpt-plugin](https://user-images.githubusercontent.com/21212372/232115814-de9a0633-371f-4733-8da0-dd6e912c8a1e.png) -

云崽系机器人的智能聊天插件

+![chatgpt-plugin](https://socialify.git.ci/ikechan8370/chatgpt-plugin/image?description=1&font=Jost&forks=1&issues=1&language=1&name=1&owner=1&pulls=1&stargazers=1&theme=Light)
From 5f23d97bb38b619934e2864e9e4970044c487019 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 12 Dec 2023 13:10:31 +0800 Subject: [PATCH 10/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BF=85?= =?UTF-8?q?=E5=BA=94=E7=94=BB=E5=9B=BE=E5=A4=9A=E4=BD=99=E7=9A=84svg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/BingDraw.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/BingDraw.js b/utils/BingDraw.js index 80e69b1..7066eea 100644 --- a/utils/BingDraw.js +++ b/utils/BingDraw.js @@ -113,7 +113,10 @@ export default class BingDrawClient { // 很可能是微软内部error,重试即可 return } - imageLinks = imageLinks.map(link => link.split('?w=')[0]).map(link => link.replace('src="', '')) + imageLinks = imageLinks + .map(link => link.split('?w=')[0]) + .map(link => link.replace('src="', '')) + .filter(link => !link.endsWith('.svg')) imageLinks = [...new Set(imageLinks)] const badImages = [ 'https://r.bing.com/rp/in-2zU3AJUdkgFe7ZKv19yPBHVs.png', From fd0d0ff5dbc9db2c4cd7ba78ade18f53838bc1a0 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 12 Dec 2023 13:15:05 +0800 Subject: [PATCH 11/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BF=85?= =?UTF-8?q?=E5=BA=94=E7=94=BB=E5=9B=BE=E5=A4=9A=E4=BD=99=E7=9A=84svg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/BingDraw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/BingDraw.js b/utils/BingDraw.js index 7066eea..268c34e 100644 --- a/utils/BingDraw.js +++ b/utils/BingDraw.js @@ -116,7 +116,7 @@ export default class BingDrawClient { imageLinks = imageLinks .map(link => link.split('?w=')[0]) .map(link => link.replace('src="', '')) - .filter(link => !link.endsWith('.svg')) + .filter(link => !link.includes('.svg')) imageLinks = [...new Set(imageLinks)] const badImages = [ 'https://r.bing.com/rp/in-2zU3AJUdkgFe7ZKv19yPBHVs.png', From e5d6a415e869d120759ccc658d5cb41790bafb2d Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 12 Dec 2023 13:25:45 +0800 Subject: [PATCH 12/13] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=BF=85?= =?UTF-8?q?=E5=BA=94=E7=BB=98=E5=9B=BE=E5=A4=B1=E8=B4=A5=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D=E9=81=BF=E5=85=8Dap=E7=94=BB=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 2 +- apps/draw.js | 2 +- utils/BingDraw.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index 9a06418..72a879d 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -1752,7 +1752,7 @@ export class chatgpt extends plugin { await client.getImages(response.details.imageTag, e) } catch (err) { await redis.del(`CHATGPT:DRAW:${e.sender.user_id}`) - await e.reply('绘图失败:' + err) + await e.reply('❌绘图失败:' + err) } } } diff --git a/apps/draw.js b/apps/draw.js index 10eed61..f45722b 100644 --- a/apps/draw.js +++ b/apps/draw.js @@ -277,7 +277,7 @@ export class dalle extends plugin { await client.getImages(prompt, e) } catch (err) { await redis.del(`CHATGPT:DRAW:${e.sender.user_id}`) - await e.reply('绘图失败:' + err) + await e.reply('❌绘图失败:' + err) } } } diff --git a/utils/BingDraw.js b/utils/BingDraw.js index 268c34e..eb5a5a7 100644 --- a/utils/BingDraw.js +++ b/utils/BingDraw.js @@ -95,7 +95,7 @@ export default class BingDrawClient { let pollingUrl = `${this.opts.baseUrl}/images/create/async/results/${requestId}?q=${urlEncodedPrompt}` logger.info({ pollingUrl }) logger.info('waiting for bing draw results...') - let timeoutTimes = 30 + let timeoutTimes = 50 let found = false let timer = setInterval(async () => { if (found) { @@ -124,7 +124,7 @@ export default class BingDrawClient { ] for (let imageLink of imageLinks) { if (badImages.indexOf(imageLink) > -1) { - await e.reply('绘图失败:Bad images', true) + await e.reply('❌绘图失败:Bad images', true) logger.error(rText) } } @@ -135,7 +135,7 @@ export default class BingDrawClient { clearInterval(timer) } else { if (timeoutTimes === 0) { - await e.reply('绘图超时', true) + await e.reply('❌绘图超时', true) clearInterval(timer) timer = null } else { @@ -143,6 +143,6 @@ export default class BingDrawClient { timeoutTimes-- } } - }, 2000) + }, 3000) } } From 16d9462e7cdbfa29e6370b08258f9bd4195f4dab Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 12 Dec 2023 13:58:16 +0800 Subject: [PATCH 13/13] =?UTF-8?q?fix:=20=E5=BF=85=E5=BA=94=E7=94=BB?= =?UTF-8?q?=E5=9B=BE=E8=A2=AB=E5=B1=8F=E8=94=BD=E7=9A=84=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/BingDraw.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/BingDraw.js b/utils/BingDraw.js index eb5a5a7..53ac92c 100644 --- a/utils/BingDraw.js +++ b/utils/BingDraw.js @@ -119,6 +119,8 @@ export default class BingDrawClient { .filter(link => !link.includes('.svg')) imageLinks = [...new Set(imageLinks)] const badImages = [ + 'https://r.bing.com/rp/in-2zU3AJUdkgFe7ZKv19yPBHVs.png"', + 'https://r.bing.com/rp/TX9QuO3WzcCJz1uaaSwQAz39Kb0.jpg"', 'https://r.bing.com/rp/in-2zU3AJUdkgFe7ZKv19yPBHVs.png', 'https://r.bing.com/rp/TX9QuO3WzcCJz1uaaSwQAz39Kb0.jpg' ]