From c3b30923c71e8235f118c1daaeb93305a33185fb Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 5 Mar 2024 12:21:12 +0800 Subject: [PATCH 1/5] fix: claude.ai --- apps/button.js | 9 +++++---- apps/chat.js | 17 ++++++++++++----- apps/md.js | 23 +++++++++++++++++++---- guoba.support.js | 6 ++++++ utils/claude.ai/index.js | 3 ++- utils/config.js | 1 + 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/apps/button.js b/apps/button.js index dfbf0ec..4ccc5c1 100644 --- a/apps/button.js +++ b/apps/button.js @@ -1,4 +1,5 @@ import plugin from '../../../lib/plugins/plugin.js' +import {Config} from "../utils/config.js"; const PLUGIN_CHAT = 'ChatGpt 对话' const PLUGIN_MANAGEMENT = 'ChatGPT-Plugin 管理' @@ -52,8 +53,8 @@ export class ChatGPTButtonHandler extends plugin { } async btnHandler (e, options, reject) { - logger.mark('[chatgpt按钮处理器]') - if (e.adapter !== 'shamrock' && (!segment.button || segment.button(1)?.content !== 1)) { + // logger.mark('[chatgpt按钮处理器]') + if (!Config.enableMd || (e.adapter !== 'shamrock' && (!segment.button || segment.button(1)?.content !== 1))) { return null } const fnc = e.logFnc @@ -192,8 +193,8 @@ export class ChatGPTButtonHandler extends plugin { { buttons: [ createButtonBase('恢复本群回复', '#chatgpt本群张嘴', false), - createButtonBase('开启上下文', '#chatgpt打开上下文'), - createButtonBase('关闭上下文 ', '#chatgpt关闭上下文') + createButtonBase('开启上下文', '#打开群聊上下文'), + createButtonBase('关闭上下文 ', '#关闭群聊上下文') ] }, diff --git a/apps/chat.js b/apps/chat.js index 38aa23d..4a35a8b 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -173,7 +173,7 @@ export class chatgpt extends plugin { }, { /** 命令正则匹配 */ - reg: '^#claude2[sS]*', + reg: '^#claude(2|3|.ai)[sS]*', /** 执行方法 */ fnc: 'claude2' }, @@ -907,7 +907,7 @@ export class chatgpt extends plugin { * #chatgpt */ async chatgpt (e) { - let msg = (Version.isTrss || e.adapter === 'shamrock') ? e.msg : e.raw_message + let msg = e.msg let prompt if (this.toggleMode === 'at') { if (!msg || e.msg?.startsWith('#')) { @@ -959,7 +959,7 @@ export class chatgpt extends plugin { } return false } - prompt = _.replace(e.raw_message.trimStart(), '#chat', '').trim() + prompt = _.replace(e.msg.trimStart(), '#chat', '').trim() if (prompt.length === 0) { return false } @@ -1506,7 +1506,7 @@ export class chatgpt extends plugin { } async claude2 (e) { - return await this.otherMode(e, 'claude2') + return await this.otherMode(e, 'claude2', /^#claude(2|3|.ai)/) } async claude (e) { @@ -2798,6 +2798,13 @@ export class chatgpt extends plugin { return await this.chatGPTApi.sendMessage(prompt, sendMessageOption) } + /** + * 其他模式 + * @param e + * @param mode + * @param {string|RegExp} pattern + * @returns {Promise} + */ async otherMode (e, mode, pattern = `#${mode}`) { if (!Config.allowOtherMode) { return false @@ -2809,7 +2816,7 @@ export class chatgpt extends plugin { } return false } - let prompt = _.replace(e.raw_message.trimStart(), pattern, '').trim() + let prompt = _.replace(e.msg.trimStart(), pattern, '').trim() if (prompt.length === 0) { return false } diff --git a/apps/md.js b/apps/md.js index 142da97..fcedcda 100644 --- a/apps/md.js +++ b/apps/md.js @@ -1,5 +1,6 @@ import plugin from '../../../lib/plugins/plugin.js' -import cfg from '../../../lib/config/config.js' +import {Config} from '../utils/config.js' + export class ChatGPTMarkdownHandler extends plugin { constructor () { super({ @@ -15,11 +16,25 @@ export class ChatGPTMarkdownHandler extends plugin { async mdHandler (e, options, reject) { const { content, prompt, use } = options - if (cfg.bot.global_md || e.adapter === 'shamrock') { - let md = `> ${prompt}\n\n---\n${content}\n\n---\n*当前模式:${use}*` - return md + if (Config.enableMd && (e.adapter === 'shamrock')) { + let mode = transUse(use) + return `> ${prompt}\n\n---\n${content}\n\n---\n*当前模式:${mode}*` } else { return content } } } + +function transUse (use) { + let useMap = { + api: Config.model, + bing: '必应(Copilot)', + gemini: Config.geminiModel, + xh: '讯飞星火', + qwen: '同义千问', + claude2: 'Claude 3 Sonnet', + glm4: 'ChatGLM4', + chat3: 'ChatGPT官网' + } + return useMap[use] || use +} diff --git a/guoba.support.js b/guoba.support.js index 9115d88..683c636 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -57,6 +57,12 @@ export function supportGuoba () { bottomHelpMessage: '将输出更多调试信息,如果不希望控制台刷屏的话,可以关闭', component: 'Switch' }, + { + field: 'enableMd', + label: 'QQ开启markdown', + bottomHelpMessage: 'qq的第三方md,非QQBot。需要适配器实现segment.markdown和segment.button方可使用,否则不建议开启,会造成各种错误。默认关闭', + component: 'Switch' + }, { field: 'translateSource', label: '翻译来源', diff --git a/utils/claude.ai/index.js b/utils/claude.ai/index.js index 4eeb663..a397aba 100644 --- a/utils/claude.ai/index.js +++ b/utils/claude.ai/index.js @@ -132,7 +132,8 @@ export class ClaudeAIClient { let body = { attachments, files: [], - model: 'claude-2.1', + // 官方更新后这里没有传值了 + // model: 'claude-2.1', prompt: text, timezone: 'Asia/Hong_Kong' } diff --git a/utils/config.js b/utils/config.js index 2d549fb..fce6809 100644 --- a/utils/config.js +++ b/utils/config.js @@ -179,6 +179,7 @@ const defaultConfig = { sunoSessToken: '', sunoClientToken: '', translateSource: 'openai', + enableMd: false, // 第三方md,非QQBot。需要适配器实现segment.markdown和segment.button方可使用,否则不建议开启,会造成各种错误 version: 'v2.7.10' } const _path = process.cwd() From 5e8dafca7310cd1241db7ce34e367bae89620c49 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 5 Mar 2024 12:26:42 +0800 Subject: [PATCH 2/5] fix: md enhancement --- apps/md.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/md.js b/apps/md.js index fcedcda..2b91204 100644 --- a/apps/md.js +++ b/apps/md.js @@ -16,7 +16,7 @@ export class ChatGPTMarkdownHandler extends plugin { async mdHandler (e, options, reject) { const { content, prompt, use } = options - if (Config.enableMd && (e.adapter === 'shamrock')) { + if (Config.enableMd) { let mode = transUse(use) return `> ${prompt}\n\n---\n${content}\n\n---\n*当前模式:${mode}*` } else { From 83fe85d68b10e4a1a495ea7acb5cffbd80885e7f Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 5 Mar 2024 13:45:56 +0800 Subject: [PATCH 3/5] fix: optional buttons --- apps/button.js | 91 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/apps/button.js b/apps/button.js index 4ccc5c1..290ee6d 100644 --- a/apps/button.js +++ b/apps/button.js @@ -108,33 +108,86 @@ export class ChatGPTButtonHandler extends plugin { /** * - * @param {{data: {suggested: string?, use: string}}} options + * @param {{suggested: string?, use: string}?} options */ - makeButtonChat (options) { + async makeButtonChat (options) { + let endCommand = '#摧毁对话' + switch (options?.use) { + case 'api': { + endCommand = '#api结束对话' + break + } + case 'api3': { + endCommand = '#api3结束对话' + break + } + case 'bing': { + endCommand = '#必应结束对话' + break + } + case 'claude2': { + endCommand = '#克劳德结束对话' + break + } + case 'gemini': { + endCommand = '#双子星结束对话' + break + } + case 'xh': { + endCommand = '#星火结束对话' + break + } + case 'qwen': { + endCommand = '#通义千问结束对话' + break + } + case 'chatglm4': { + endCommand = '#智谱结束对话' + break + } + } let rows = [ { buttons: [ - createButtonBase('结束对话', '#摧毁对话'), - createButtonBase('切换模式', '#chatgpt切换', false), + createButtonBase('结束对话', '#毁灭对话'), + createButtonBase('结束当前对话', endCommand), createButtonBase('at我对话', '', false) ] - }, - { - buttons: [ - createButtonBase('OpenAPI', '#chat1', false), - createButtonBase('ChatGPT', '#chat3', false), - createButtonBase('Copilot', '#bing', false), - createButtonBase('Gemini', '#gemini', false) - ] - }, - { - buttons: [ - createButtonBase('讯飞星火', '#xh', false), - createButtonBase('通义千问', '#qwen', false), - createButtonBase('ChatGLM4', '#glm4', false) - ] } ] + let buttons = [[], []] + if (Config.apiKey) { + buttons[0].push(createButtonBase('OpenAPI', '#chat1', false)) + } + if (await redis.get('CHATGPT:TOKEN')) { + buttons[0].push(createButtonBase('ChatGPT', '#chat3', false)) + } + if (await redis.get('CHATGPT:BING_TOKENS')) { + buttons[0].push(createButtonBase('Copilot', '#bing', false)) + } + if (Config.geminiKey) { + buttons[0].push(createButtonBase('Gemini', '#gemini', false)) + } + if (Config.xhAPIKey) { + buttons[buttons[0].length >= 4 ? 1 : 0].push(createButtonBase('讯飞星火', '#xh', false)) + } + if (Config.qwenApiKey) { + buttons[buttons[0].length >= 4 ? 1 : 0].push(createButtonBase('通义千问', '#qwen', false)) + } + if (Config.chatglmRefreshToken) { + buttons[buttons[0].length >= 4 ? 1 : 0].push(createButtonBase('ChatGLM4', '#glm4', false)) + } + if (Config.claudeAISessionKey) { + buttons[buttons[0].length >= 4 ? 1 : 0].push(createButtonBase('Claude', '#claude.ai', false)) + } + rows.push({ + buttons: buttons[0] + }) + if (buttons[1].length > 0) { + rows.push({ + buttons: buttons[1] + }) + } if (options?.suggested) { rows.unshift({ buttons: options.suggested.split('\n').map(s => { From 2ae751e6e789bf8734b1bc00f5fbd2fa1c1be1a2 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 5 Mar 2024 13:50:35 +0800 Subject: [PATCH 4/5] fix: mode name --- apps/md.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/md.js b/apps/md.js index 2b91204..4409a88 100644 --- a/apps/md.js +++ b/apps/md.js @@ -28,10 +28,10 @@ export class ChatGPTMarkdownHandler extends plugin { function transUse (use) { let useMap = { api: Config.model, - bing: '必应(Copilot)', + bing: '必应(Copilot)' + Config.toneStyle, gemini: Config.geminiModel, - xh: '讯飞星火', - qwen: '同义千问', + xh: '讯飞星火 ' + Config.xhmode, + qwen: '通义千问 ' + Config.qwenModel, claude2: 'Claude 3 Sonnet', glm4: 'ChatGLM4', chat3: 'ChatGPT官网' From 766420e65241a85c6422ea09cf3942d89e696bca Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 5 Mar 2024 13:52:45 +0800 Subject: [PATCH 5/5] fix: ignore md while not enable md --- apps/chat.js | 5 ++++- apps/entertainment.js | 5 ++++- apps/management.js | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index 4a35a8b..75fc56d 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -292,6 +292,9 @@ export class chatgpt extends plugin { }) this.toggleMode = toggleMode this.reply = async (msg, quote, data) => { + if (!Config.enableMd) { + return e.reply(msg, quote, data) + } let handler = e.runtime?.handler || {} const btns = await handler.call('chatgpt.button.post', this.e, data) const btnElement = { @@ -303,7 +306,7 @@ export class chatgpt extends plugin { } else { msg = [msg, btnElement] } - return e.reply(msg, data) + return e.reply(msg, quote, data) } } diff --git a/apps/entertainment.js b/apps/entertainment.js index ce65465..b977a5a 100644 --- a/apps/entertainment.js +++ b/apps/entertainment.js @@ -83,6 +83,9 @@ export class Entertainment extends plugin { } ] this.reply = async (msg, quote, data) => { + if (!Config.enableMd) { + return e.reply(msg, quote, data) + } let handler = e.runtime?.handler || {} const btns = await handler.call('chatgpt.button.post', this.e) const btnElement = { @@ -94,7 +97,7 @@ export class Entertainment extends plugin { } else { msg = [msg, btnElement] } - return e.reply(msg, data) + return e.reply(msg, quote, data) } } diff --git a/apps/management.js b/apps/management.js index 3ad63e0..5b6d7eb 100644 --- a/apps/management.js +++ b/apps/management.js @@ -334,6 +334,9 @@ export class ChatgptManagement extends plugin { ] }) this.reply = async (msg, quote, data) => { + if (!Config.enableMd) { + return e.reply(msg, quote, data) + } let handler = e.runtime?.handler || {} const btns = await handler.call('chatgpt.button.post', this.e) if (btns) { @@ -347,7 +350,7 @@ export class ChatgptManagement extends plugin { msg = [msg, btnElement] } } - return e.reply(msg, data) + return e.reply(msg, quote, data) } }