mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
Merge branch 'btn' of github.com:ikechan8370/chatgpt-plugin into btn
This commit is contained in:
commit
2f79f2e1bc
8 changed files with 128 additions and 35 deletions
100
apps/button.js
100
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
|
||||
|
|
@ -107,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 => {
|
||||
|
|
@ -192,8 +246,8 @@ export class ChatGPTButtonHandler extends plugin {
|
|||
{
|
||||
buttons: [
|
||||
createButtonBase('恢复本群回复', '#chatgpt本群张嘴', false),
|
||||
createButtonBase('开启上下文', '#chatgpt打开上下文'),
|
||||
createButtonBase('关闭上下文 ', '#chatgpt关闭上下文')
|
||||
createButtonBase('开启上下文', '#打开群聊上下文'),
|
||||
createButtonBase('关闭上下文 ', '#关闭群聊上下文')
|
||||
|
||||
]
|
||||
},
|
||||
|
|
|
|||
20
apps/chat.js
20
apps/chat.js
|
|
@ -173,7 +173,7 @@ export class chatgpt extends plugin {
|
|||
},
|
||||
{
|
||||
/** 命令正则匹配 */
|
||||
reg: '^#claude2[sS]*',
|
||||
reg: '^#claude(2|3|.ai)[sS]*',
|
||||
/** 执行方法 */
|
||||
fnc: 'claude2'
|
||||
},
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -907,7 +910,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 +962,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
|
||||
}
|
||||
|
|
@ -1512,7 +1515,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) {
|
||||
|
|
@ -2804,6 +2807,13 @@ export class chatgpt extends plugin {
|
|||
return await this.chatGPTApi.sendMessage(prompt, sendMessageOption)
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他模式
|
||||
* @param e
|
||||
* @param mode
|
||||
* @param {string|RegExp} pattern
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async otherMode (e, mode, pattern = `#${mode}`) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
23
apps/md.js
23
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) {
|
||||
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)' + Config.toneStyle,
|
||||
gemini: Config.geminiModel,
|
||||
xh: '讯飞星火 ' + Config.xhmode,
|
||||
qwen: '通义千问 ' + Config.qwenModel,
|
||||
claude2: 'Claude 3 Sonnet',
|
||||
glm4: 'ChatGLM4',
|
||||
chat3: 'ChatGPT官网'
|
||||
}
|
||||
return useMap[use] || use
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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: '翻译来源',
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue