mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: 删除上传的设定;一些设定共享的优化改进
This commit is contained in:
parent
b11a653c51
commit
b4f37b5339
6 changed files with 74 additions and 29 deletions
|
|
@ -1011,6 +1011,7 @@ export class chatgpt extends plugin {
|
||||||
opt.toneStyle = Config.toneStyle
|
opt.toneStyle = Config.toneStyle
|
||||||
opt.context = Config.sydneyContext
|
opt.context = Config.sydneyContext
|
||||||
if (Config.enableGroupContext && e.isGroup) {
|
if (Config.enableGroupContext && e.isGroup) {
|
||||||
|
try {
|
||||||
opt.groupId = e.group_id
|
opt.groupId = e.group_id
|
||||||
opt.qq = e.sender.user_id
|
opt.qq = e.sender.user_id
|
||||||
opt.nickname = e.sender.card
|
opt.nickname = e.sender.card
|
||||||
|
|
@ -1028,8 +1029,11 @@ export class chatgpt extends plugin {
|
||||||
let sender = mm.get(chat.sender.user_id)
|
let sender = mm.get(chat.sender.user_id)
|
||||||
chat.sender = sender
|
chat.sender = sender
|
||||||
})
|
})
|
||||||
console.log(chats)
|
// console.log(chats)
|
||||||
opt.chats = chats
|
opt.chats = chats
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn('获取群聊聊天记录失败,本次对话不携带聊天记录', err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
response = await bingAIClient.sendMessage(prompt, opt, (token) => {
|
response = await bingAIClient.sendMessage(prompt, opt, (token) => {
|
||||||
reply += token
|
reply += token
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,11 @@ let helpData = [
|
||||||
title: '#chatgpt(上传|分享|共享)设定',
|
title: '#chatgpt(上传|分享|共享)设定',
|
||||||
desc: '上传设定'
|
desc: '上传设定'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
icon: 'confirm',
|
||||||
|
title: '#chatgpt(删除|取消|撤销)共享设定+设定名',
|
||||||
|
desc: '从远端删除,只能删除自己上传的设定,根据机器人主人qq号判断。'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: 'confirm',
|
icon: 'confirm',
|
||||||
title: '#chatgpt浏览设定(+关键词)(页码X)',
|
title: '#chatgpt浏览设定(+关键词)(页码X)',
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { Config } from '../utils/config.js'
|
import { Config } from '../utils/config.js'
|
||||||
import { getMasterQQ, limitString, makeForwardMsg } from '../utils/common.js'
|
import {getMasterQQ, limitString, makeForwardMsg, maskQQ} from '../utils/common.js'
|
||||||
import { deleteOnePrompt, getPromptByName, readPrompts, saveOnePrompt } from '../utils/prompts.js'
|
import { deleteOnePrompt, getPromptByName, readPrompts, saveOnePrompt } from '../utils/prompts.js'
|
||||||
export class help extends plugin {
|
export class help extends plugin {
|
||||||
constructor (e) {
|
constructor (e) {
|
||||||
|
|
@ -42,6 +42,11 @@ export class help extends plugin {
|
||||||
fnc: 'uploadPrompt',
|
fnc: 'uploadPrompt',
|
||||||
permission: 'master'
|
permission: 'master'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
reg: '^#(chatgpt|ChatGPT)(删除|取消|撤销)共享设定',
|
||||||
|
fnc: 'removeSharePrompt',
|
||||||
|
permission: 'master'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
reg: '^#(chatgpt|ChatGPT)导入设定',
|
reg: '^#(chatgpt|ChatGPT)导入设定',
|
||||||
fnc: 'importPrompt',
|
fnc: 'importPrompt',
|
||||||
|
|
@ -225,10 +230,32 @@ export class help extends plugin {
|
||||||
this.finish('addPromptContext')
|
this.finish('addPromptContext')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeSharePrompt (e) {
|
||||||
|
let master = (await getMasterQQ())[0]
|
||||||
|
let name = e.msg.replace(/^#(chatgpt|ChatGPT)(删除|取消|撤销)共享设定/, '')
|
||||||
|
let response = await fetch(`https://chatgpt.roki.best/prompt?name=${name}&qq=${master}?`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'FROM-CHATGPT': 'ikechan8370'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (response.status === 200) {
|
||||||
|
let json = await response.json()
|
||||||
|
if (json.code === 200 && json.data) {
|
||||||
|
await e.reply('已从云端删除该设定')
|
||||||
|
} else {
|
||||||
|
await e.reply('操作失败:' + json.msg)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await e.reply('操作失败:' + await response.text())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async uploadPrompt (e) {
|
async uploadPrompt (e) {
|
||||||
if (await redis.get('CHATGPT:UPLOAD_PROMPT')) {
|
if (await redis.get('CHATGPT:UPLOAD_PROMPT')) {
|
||||||
await this.reply('本机器人存在其他人正在上传设定,请稍后')
|
await redis.del('CHATGPT:UPLOAD_PROMPT')
|
||||||
return
|
// await this.reply('本机器人存在其他人正在上传设定,请稍后')
|
||||||
|
// return
|
||||||
}
|
}
|
||||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||||
if (use.toLowerCase() === 'bing') {
|
if (use.toLowerCase() === 'bing') {
|
||||||
|
|
@ -240,7 +267,7 @@ export class help extends plugin {
|
||||||
if (!currentUse) {
|
if (!currentUse) {
|
||||||
currentUse = await redis.get(`CHATGPT:PROMPT_USE_${use}`)
|
currentUse = await redis.get(`CHATGPT:PROMPT_USE_${use}`)
|
||||||
}
|
}
|
||||||
await this.reply(`即将上传设定${currentUse},确定请回复确定,取消请回复取消,或者回复其他本地存在设定的名字`, true)
|
await this.reply(`即将向云端上传设定${currentUse},确定请回复确定,取消请回复取消,或者回复其他本地存在设定的名字`, true)
|
||||||
let extraData = {
|
let extraData = {
|
||||||
currentUse,
|
currentUse,
|
||||||
use
|
use
|
||||||
|
|
@ -268,7 +295,7 @@ export class help extends plugin {
|
||||||
this.finish('uploadPromptConfirm')
|
this.finish('uploadPromptConfirm')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await redis.set('CHATGPT:UPLOAD_PROMPT', JSON.stringify(extraData), 300)
|
// await redis.set('CHATGPT:UPLOAD_PROMPT', JSON.stringify(extraData), 300)
|
||||||
await this.reply('请输入对该设定的描述或备注,便于其他人快速了解该设定', true)
|
await this.reply('请输入对该设定的描述或备注,便于其他人快速了解该设定', true)
|
||||||
this.finish('uploadPromptConfirm')
|
this.finish('uploadPromptConfirm')
|
||||||
this.setContext('uploadPromptDescription')
|
this.setContext('uploadPromptDescription')
|
||||||
|
|
@ -278,7 +305,7 @@ export class help extends plugin {
|
||||||
if (!this.e.msg) return
|
if (!this.e.msg) return
|
||||||
let description = this.e.msg.trim()
|
let description = this.e.msg.trim()
|
||||||
if (description === '取消') {
|
if (description === '取消') {
|
||||||
await redis.del('CHATGPT:UPLOAD_PROMPT')
|
// await redis.del('CHATGPT:UPLOAD_PROMPT')
|
||||||
await this.reply('已取消上传', true)
|
await this.reply('已取消上传', true)
|
||||||
this.finish('uploadPromptDescription')
|
this.finish('uploadPromptDescription')
|
||||||
return
|
return
|
||||||
|
|
@ -356,7 +383,7 @@ export class help extends plugin {
|
||||||
let output = '| 【设定名称】 | 上传者QQ | 上传时间 | 是否R18 | 使用场景 |\n'
|
let output = '| 【设定名称】 | 上传者QQ | 上传时间 | 是否R18 | 使用场景 |\n'
|
||||||
output += '----------------------------------------------------------------------------------------\n'
|
output += '----------------------------------------------------------------------------------------\n'
|
||||||
content.forEach(c => {
|
content.forEach(c => {
|
||||||
output += `| 【${c.title}】 | ${c.qq} | ${c.createTime} | ${c.r18} | ${c.use}|\n`
|
output += `| 【${c.title}】 | ${maskQQ(c.qq)} | ${c.createTime} | ${c.r18} | ${c.use}|\n`
|
||||||
})
|
})
|
||||||
output += '**************************************************************************\n'
|
output += '**************************************************************************\n'
|
||||||
output += ` 当前为第${pageable.pageNumber + 1}页,共${totalElements}个设定`
|
output += ` 当前为第${pageable.pageNumber + 1}页,共${totalElements}个设定`
|
||||||
|
|
|
||||||
4
index.js
4
index.js
|
|
@ -1,8 +1,8 @@
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import {Config} from "./utils/config.js";
|
import { Config } from './utils/config.js'
|
||||||
|
|
||||||
if (!global.segment) {
|
if (!global.segment) {
|
||||||
global.segment = (await import("oicq")).segment
|
global.segment = (await import('oicq')).segment
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = fs.readdirSync('./plugins/chatgpt-plugin/apps').filter(file => file.endsWith('.js'))
|
const files = fs.readdirSync('./plugins/chatgpt-plugin/apps').filter(file => file.endsWith('.js'))
|
||||||
|
|
|
||||||
|
|
@ -477,3 +477,12 @@ export function wrapTextByLanguage (text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(wrapTextByLanguage('你好,这里是哈哈,こんにちは,Hello!'))
|
// console.log(wrapTextByLanguage('你好,这里是哈哈,こんにちは,Hello!'))
|
||||||
|
|
||||||
|
export function maskQQ (qq) {
|
||||||
|
if (!qq) {
|
||||||
|
return '未知'
|
||||||
|
}
|
||||||
|
let len = qq.length // QQ号长度
|
||||||
|
let newqq = qq.slice(0, 3) + '*'.repeat(len - 7) + qq.slice(len - 3) // 替换中间3位为*
|
||||||
|
return newqq
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ const defaultConfig = {
|
||||||
emojiBaseURL: 'https://www.gstatic.com/android/keyboard/emojikitchen',
|
emojiBaseURL: 'https://www.gstatic.com/android/keyboard/emojikitchen',
|
||||||
enableGroupContext: false,
|
enableGroupContext: false,
|
||||||
groupContextLength: 50,
|
groupContextLength: 50,
|
||||||
version: 'v2.4.2'
|
version: 'v2.4.3'
|
||||||
}
|
}
|
||||||
const _path = process.cwd()
|
const _path = process.cwd()
|
||||||
let config = {}
|
let config = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue