mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
Merge branch 'v2' into v2
This commit is contained in:
commit
8e50acc146
88 changed files with 18904 additions and 879 deletions
867
apps/chat.js
867
apps/chat.js
File diff suppressed because it is too large
Load diff
|
|
@ -1,16 +1,17 @@
|
|||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { Config } from '../utils/config.js'
|
||||
import { generateHello } from '../utils/randomMessage.js'
|
||||
import { generateAudio } from '../utils/tts.js'
|
||||
import { generateVitsAudio } from '../utils/tts.js'
|
||||
import fs from 'fs'
|
||||
import { emojiRegex, googleRequestUrl } from '../utils/emoj/index.js'
|
||||
import fetch from 'node-fetch'
|
||||
import { getImageOcrText, getImg, makeForwardMsg, mkdirs } from '../utils/common.js'
|
||||
import { getImageOcrText, getImg, makeForwardMsg, mkdirs, renderUrl } from '../utils/common.js'
|
||||
import uploadRecord from '../utils/uploadRecord.js'
|
||||
import { makeWordcloud } from '../utils/wordcloud/wordcloud.js'
|
||||
import { translate, translateLangSupports } from '../utils/translate.js'
|
||||
import AzureTTS from '../utils/tts/microsoft-azure.js'
|
||||
import VoiceVoxTTS from '../utils/tts/voicevox.js'
|
||||
import { URL } from 'node:url'
|
||||
|
||||
let useSilk = false
|
||||
try {
|
||||
|
|
@ -56,6 +57,10 @@ export class Entertainment extends plugin {
|
|||
{
|
||||
reg: '^#ocr',
|
||||
fnc: 'ocr'
|
||||
},
|
||||
{
|
||||
reg: '^#url(:|:)',
|
||||
fnc: 'screenshotUrl'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
@ -198,7 +203,8 @@ ${translateLangLabels}
|
|||
await e.reply('请在群里发送此命令')
|
||||
}
|
||||
}
|
||||
async wordcloud_latest(e) {
|
||||
|
||||
async wordcloud_latest (e) {
|
||||
if (e.isGroup) {
|
||||
let groupId = e.group_id
|
||||
let lock = await redis.get(`CHATGPT:WORDCLOUD:${groupId}`)
|
||||
|
|
@ -210,14 +216,14 @@ ${translateLangLabels}
|
|||
const regExp = /词云(\d{0,2})(|h)/
|
||||
const match = e.msg.trim().match(regExp)
|
||||
const duration = !match[1] ? 12 : parseInt(match[1]) // default 12h
|
||||
|
||||
|
||||
if(duration > 24) {
|
||||
await e.reply('最多只能统计24小时内的记录哦')
|
||||
return false
|
||||
}
|
||||
await e.reply('在统计啦,请稍等...')
|
||||
|
||||
await redis.set(`CHATGPT:WORDCLOUD:${groupId}`, '1', {EX: 600})
|
||||
|
||||
await redis.set(`CHATGPT:WORDCLOUD:${groupId}`, '1', { EX: 600 })
|
||||
try {
|
||||
await makeWordcloud(e, e.group_id, duration)
|
||||
} catch (err) {
|
||||
|
|
@ -298,7 +304,7 @@ ${translateLangLabels}
|
|||
let sendable = message
|
||||
logger.info(`打招呼给群聊${groupId}:` + message)
|
||||
if (Config.defaultUseTTS) {
|
||||
let audio = await generateAudio(message, Config.defaultTTSRole)
|
||||
let audio = await generateVitsAudio(message, Config.defaultTTSRole)
|
||||
sendable = segment.record(audio)
|
||||
}
|
||||
if (!groupId) {
|
||||
|
|
@ -356,7 +362,7 @@ ${translateLangLabels}
|
|||
}
|
||||
}
|
||||
try {
|
||||
audio = await generateAudio(message, defaultVitsTTSRole, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
|
||||
audio = await generateVitsAudio(message, defaultVitsTTSRole, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
}
|
||||
|
|
@ -466,4 +472,31 @@ ${translateLangLabels}
|
|||
await this.reply(replyMsg)
|
||||
return false
|
||||
}
|
||||
|
||||
async screenshotUrl (e) {
|
||||
let url = e.msg.replace(/^#url(:|:)/, '')
|
||||
if (url.length === 0) { return false }
|
||||
try {
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||
url = 'http://' + url
|
||||
}
|
||||
let urlLink = new URL(url)
|
||||
await e.reply(
|
||||
await renderUrl(
|
||||
e, urlLink.href,
|
||||
{
|
||||
retType: 'base64',
|
||||
Viewport: {
|
||||
width: Config.chatViewWidth,
|
||||
height: parseInt(Config.chatViewWidth * 0.56)
|
||||
},
|
||||
deviceScaleFactor: parseFloat(Config.cloudDPR)
|
||||
}
|
||||
),
|
||||
e.isGroup && Config.quoteReply)
|
||||
} catch (err) {
|
||||
this.reply('无效url:' + url)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,6 +210,11 @@ let helpData = [
|
|||
icon: 'token',
|
||||
title: '#chatgpt设置后台刷新token',
|
||||
desc: '用于查看API余额。注意和配置的key保持同一账号。'
|
||||
},
|
||||
{
|
||||
icon: 'token',
|
||||
title: '#chatgpt(开启|关闭)智能模式',
|
||||
desc: 'API模式下打开或关闭智能模式。'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { Config } from '../utils/config.js'
|
||||
import { exec } from 'child_process'
|
||||
import {
|
||||
checkPnpm,
|
||||
formatDuration,
|
||||
getAzureRoleList,
|
||||
getPublicIP,
|
||||
|
|
@ -10,7 +8,7 @@ import {
|
|||
getVitsRoleList,
|
||||
getVoicevoxRoleList,
|
||||
makeForwardMsg,
|
||||
parseDuration, processList,
|
||||
parseDuration,
|
||||
renderUrl
|
||||
} from '../utils/common.js'
|
||||
import SydneyAIClient from '../utils/SydneyAIClient.js'
|
||||
|
|
@ -22,8 +20,6 @@ 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'
|
||||
|
||||
let isWhiteList = true
|
||||
let isSetGroup = true
|
||||
export class ChatgptManagement extends plugin {
|
||||
constructor (e) {
|
||||
super({
|
||||
|
|
@ -33,42 +29,42 @@ export class ChatgptManagement extends plugin {
|
|||
priority: 500,
|
||||
rule: [
|
||||
{
|
||||
reg: '#chatgpt开启(问题)?(回复)?确认',
|
||||
reg: '^#chatgpt开启(问题)?(回复)?确认',
|
||||
fnc: 'turnOnConfirm',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '#chatgpt关闭(问题)?(回复)?确认',
|
||||
reg: '^#chatgpt关闭(问题)?(回复)?确认',
|
||||
fnc: 'turnOffConfirm',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '#chatgpt(设置|绑定)(token|Token)',
|
||||
reg: '^#chatgpt(设置|绑定)(token|Token)',
|
||||
fnc: 'setAccessToken',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '#chatgpt(设置|绑定)(Poe|POE)(token|Token)',
|
||||
reg: '^#chatgpt(设置|绑定)(Poe|POE)(token|Token)',
|
||||
fnc: 'setPoeCookie',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '#chatgpt(设置|绑定|添加)(必应|Bing |bing )(token|Token)',
|
||||
reg: '^#chatgpt(设置|绑定|添加)(必应|Bing |bing )(token|Token)',
|
||||
fnc: 'setBingAccessToken',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '#chatgpt(删除|移除)(必应|Bing |bing )(token|Token)',
|
||||
reg: '^#chatgpt(删除|移除)(必应|Bing |bing )(token|Token)',
|
||||
fnc: 'delBingAccessToken',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '#chatgpt(查看|浏览)(必应|Bing |bing )(token|Token)',
|
||||
reg: '^#chatgpt(查看|浏览)(必应|Bing |bing )(token|Token)',
|
||||
fnc: 'getBingAccessToken',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '#chatgpt(迁移|恢复)(必应|Bing |bing )(token|Token)',
|
||||
reg: '^#chatgpt(迁移|恢复)(必应|Bing |bing )(token|Token)',
|
||||
fnc: 'migrateBingAccessToken',
|
||||
permission: 'master'
|
||||
},
|
||||
|
|
@ -126,10 +122,6 @@ export class ChatgptManagement extends plugin {
|
|||
reg: '^#chatgpt模式(帮助)?$',
|
||||
fnc: 'modeHelp'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt(强制)?更新$',
|
||||
fnc: 'updateChatGPTPlugin'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt版本(信息)',
|
||||
fnc: 'versionChatGPTPlugin'
|
||||
|
|
@ -140,32 +132,32 @@ export class ChatgptManagement extends plugin {
|
|||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt(本群)?(群\\d+)?(开启|启动|激活|张嘴|开口|说话|上班)',
|
||||
reg: '^#chatgpt(本群)?(群\\d+)?(开启|启动|激活|张嘴|开口|说话|上班)$',
|
||||
fnc: 'openMouth',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt查看?(关闭|闭嘴|关机|休眠|下班|休眠)列表',
|
||||
reg: '^#chatgpt查看?(关闭|闭嘴|关机|休眠|下班|休眠)列表$',
|
||||
fnc: 'listShutUp',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt设置(API|key)(Key|key)',
|
||||
reg: '^#chatgpt设置(API|key)(Key|key)$',
|
||||
fnc: 'setAPIKey',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt设置(API|api)设定',
|
||||
reg: '^#chatgpt设置(API|api)设定$',
|
||||
fnc: 'setAPIPromptPrefix',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt设置星火token',
|
||||
reg: '^#chatgpt设置星火token$',
|
||||
fnc: 'setXinghuoToken',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt设置(Bing|必应|Sydney|悉尼|sydney|bing)设定',
|
||||
reg: '^#chatgpt设置(Bing|必应|Sydney|悉尼|sydney|bing)设定$',
|
||||
fnc: 'setBingPromptPrefix',
|
||||
permission: 'master'
|
||||
},
|
||||
|
|
@ -206,21 +198,6 @@ export class ChatgptManagement extends plugin {
|
|||
fnc: 'enablePrivateChat',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt(设置|添加)对话[白黑]名单$',
|
||||
fnc: 'setList',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt(查看)?对话[白黑]名单(帮助)?$',
|
||||
fnc: 'checkList',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt(删除|移除)对话[白黑]名单$',
|
||||
fnc: 'delList',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#(设置|修改)管理密码',
|
||||
fnc: 'setAdminPassword',
|
||||
|
|
@ -240,7 +217,7 @@ export class ChatgptManagement extends plugin {
|
|||
fnc: 'userPage'
|
||||
},
|
||||
{
|
||||
reg: '^#(chatgpt)?(对话|管理|娱乐|绘图|人物设定|聊天记录)?指令表(帮助|搜索(.+))?',
|
||||
reg: '^#?(chatgpt)(对话|管理|娱乐|绘图|人物设定|聊天记录)?指令表(帮助|搜索(.+))?',
|
||||
fnc: 'commandHelp'
|
||||
},
|
||||
{
|
||||
|
|
@ -259,6 +236,21 @@ export class ChatgptManagement extends plugin {
|
|||
{
|
||||
reg: '^#(chatgpt)?查看回复设置$',
|
||||
fnc: 'viewUserSetting'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt导出配置',
|
||||
fnc: 'exportConfig',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt导入配置',
|
||||
fnc: 'importConfig',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt(开启|关闭)智能模式$',
|
||||
fnc: 'switchSmartMode',
|
||||
permission: 'master'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
@ -312,9 +304,7 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
roleList = getVoicevoxRoleList()
|
||||
break
|
||||
case 'azure':
|
||||
if (matchCommand[2] === 'azure') {
|
||||
roleList = getAzureRoleList()
|
||||
}
|
||||
roleList = getAzureRoleList()
|
||||
break
|
||||
default:
|
||||
break
|
||||
|
|
@ -360,8 +350,8 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
async commandHelp (e) {
|
||||
if (/^#(chatgpt)?指令表帮助$/.exec(e.msg.trim())) {
|
||||
await this.reply('#chatgpt指令表: 查看本插件的所有指令\n' +
|
||||
'#chatgpt(对话|管理|娱乐|绘图|人物设定|聊天记录)指令表: 查看对应功能分类的指令表\n' +
|
||||
'#chatgpt指令表搜索xxx: 查看包含对应关键词的指令')
|
||||
'#chatgpt(对话|管理|娱乐|绘图|人物设定|聊天记录)指令表: 查看对应功能分类的指令表\n' +
|
||||
'#chatgpt指令表搜索xxx: 查看包含对应关键词的指令')
|
||||
return false
|
||||
}
|
||||
const categories = {
|
||||
|
|
@ -438,126 +428,6 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
return true
|
||||
}
|
||||
|
||||
async setList (e) {
|
||||
this.setContext('saveList')
|
||||
isWhiteList = e.msg.includes('白')
|
||||
const listType = isWhiteList ? '对话白名单' : '对话黑名单'
|
||||
await this.reply(`请发送需要添加的${listType}号码,默认设置为添加群号,需要添加QQ号时在前面添加^(例如:^123456)。`, e.isGroup)
|
||||
return false
|
||||
}
|
||||
|
||||
async saveList (e) {
|
||||
if (!this.e.msg) return
|
||||
const listType = isWhiteList ? '对话白名单' : '对话黑名单'
|
||||
const regex = /^\^?[1-9]\d{5,9}$/
|
||||
const wrongInput = []
|
||||
const inputSet = new Set()
|
||||
const inputList = this.e.msg.split(/[,,]/).reduce((acc, value) => {
|
||||
if (value.length > 11 || !regex.test(value)) {
|
||||
wrongInput.push(value)
|
||||
} else if (!inputSet.has(value)) {
|
||||
inputSet.add(value)
|
||||
acc.push(value)
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
if (!inputList.length) {
|
||||
let replyMsg = '名单更新失败,请在检查输入是否正确后重新输入。'
|
||||
if (wrongInput.length) replyMsg += `\n${wrongInput.length ? '检测到以下错误输入:"' + wrongInput.join(',') + '",已自动忽略。' : ''}`
|
||||
await this.reply(replyMsg, e.isGroup)
|
||||
return false
|
||||
}
|
||||
let [whitelist, blacklist] = processList(Config.whitelist, Config.blacklist)
|
||||
whitelist = [...inputList, ...whitelist]
|
||||
blacklist = [...inputList, ...blacklist]
|
||||
if (listType === '对话白名单') {
|
||||
Config.whitelist = Array.from(new Set(whitelist))
|
||||
} else {
|
||||
Config.blacklist = Array.from(new Set(blacklist))
|
||||
}
|
||||
let replyMsg = `${listType}已更新,可通过\n"#chatgpt查看${listType}" 查看最新名单\n"#chatgpt移除${listType}" 管理名单${wrongInput.length ? '\n检测到以下错误输入:"' + wrongInput.join(',') + '",已自动忽略。' : ''}`
|
||||
if (e.isPrivate) {
|
||||
replyMsg += `\n当前${listType}为:${listType === '对话白名单' ? Config.whitelist : Config.blacklist}`
|
||||
}
|
||||
await this.reply(replyMsg, e.isGroup)
|
||||
this.finish('saveList')
|
||||
}
|
||||
|
||||
async checkList (e) {
|
||||
if (e.msg.includes('帮助')) {
|
||||
await this.reply('默认设置为添加群号,需要拉黑QQ号时在前面添加^(例如:^123456),可一次性混合输入多个配置号码,错误项会自动忽略。具体使用指令可通过 "#指令表搜索名单" 查看,白名单优先级高于黑名单。')
|
||||
return true
|
||||
}
|
||||
isWhiteList = e.msg.includes('白')
|
||||
const list = isWhiteList ? Config.whitelist : Config.blacklist
|
||||
const listType = isWhiteList ? '白名单' : '黑名单'
|
||||
const replyMsg = list.length ? `当前${listType}为:${list}` : `当前没有设置任何${listType}`
|
||||
await this.reply(replyMsg, e.isGroup)
|
||||
return false
|
||||
}
|
||||
|
||||
async delList (e) {
|
||||
isWhiteList = e.msg.includes('白')
|
||||
const listType = isWhiteList ? '对话白名单' : '对话黑名单'
|
||||
let replyMsg = ''
|
||||
if (Config.whitelist.length === 0 && Config.blacklist.length === 0) {
|
||||
replyMsg = '当前对话(白|黑)名单都是空哒,请先添加吧~'
|
||||
} else if ((listType === '对话白名单' && !Config.whitelist.length) || (listType === '对话黑名单' && !Config.blacklist.length)) {
|
||||
replyMsg = `当前${listType}为空,请先添加吧~`
|
||||
}
|
||||
if (replyMsg) {
|
||||
await this.reply(replyMsg, e.isGroup)
|
||||
return false
|
||||
}
|
||||
this.setContext('confirmDelList')
|
||||
await this.reply(`请发送需要删除的${listType}号码,号码间使用,隔开。输入‘全部删除’清空${listType}。${e.isPrivate ? '\n当前' + listType + '为:' + (listType === '对话白名单' ? Config.whitelist : Config.blacklist) : ''}`, e.isGroup)
|
||||
return false
|
||||
}
|
||||
|
||||
async confirmDelList (e) {
|
||||
if (!this.e.msg) return
|
||||
const isAllDeleted = this.e.msg.trim() === '全部删除'
|
||||
const regex = /^\^?[1-9]\d{5,9}$/
|
||||
const wrongInput = []
|
||||
const inputSet = new Set()
|
||||
const inputList = this.e.msg.split(/[,,]/).reduce((acc, value) => {
|
||||
if (value.length > 11 || !regex.test(value)) {
|
||||
wrongInput.push(value)
|
||||
} else if (!inputSet.has(value)) {
|
||||
inputSet.add(value)
|
||||
acc.push(value)
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
if (!inputList.length && !isAllDeleted) {
|
||||
let replyMsg = '名单更新失败,请在检查输入是否正确后重新输入。'
|
||||
if (wrongInput.length) replyMsg += `${wrongInput.length ? '\n检测到以下错误输入:"' + wrongInput.join(',') + '",已自动忽略。' : ''}`
|
||||
await this.reply(replyMsg, e.isGroup)
|
||||
return false
|
||||
}
|
||||
let [whitelist, blacklist] = processList(Config.whitelist, Config.blacklist)
|
||||
if (isAllDeleted) {
|
||||
Config.whitelist = isWhiteList ? [] : whitelist
|
||||
Config.blacklist = !isWhiteList ? [] : blacklist
|
||||
} else {
|
||||
for (const element of inputList) {
|
||||
if (isWhiteList) {
|
||||
Config.whitelist = whitelist.filter(item => item !== element)
|
||||
} else {
|
||||
Config.blacklist = blacklist.filter(item => item !== element)
|
||||
}
|
||||
}
|
||||
}
|
||||
const listType = isWhiteList ? '对话白名单' : '对话黑名单'
|
||||
let replyMsg = `${listType}已更新,可通过 "#chatgpt查看${listType}" 命令查看最新名单${wrongInput.length ? '\n检测到以下错误输入:"' + wrongInput.join(',') + '",已自动忽略。' : ''}`
|
||||
if (e.isPrivate) {
|
||||
const list = isWhiteList ? Config.whitelist : Config.blacklist
|
||||
replyMsg = list.length ? `\n当前${listType}为:${list}` : `当前没有设置任何${listType}`
|
||||
}
|
||||
await this.reply(replyMsg, e.isGroup)
|
||||
this.finish('confirmDelList')
|
||||
}
|
||||
|
||||
async enablePrivateChat (e) {
|
||||
Config.enablePrivateChat = !!e.msg.match(/(允许|打开|同意)/)
|
||||
await this.reply('设置成功', e.isGroup)
|
||||
|
|
@ -793,7 +663,7 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
else tokens = []
|
||||
tokens = tokens.length > 0
|
||||
? tokens.map((item, index) => (
|
||||
`【${index}】 Token:${item.Token.substring(0, 5 / 2) + '...' + item.Token.substring(item.Token.length - 5 / 2, item.Token.length)}`
|
||||
`【${index}】 Token:${item.Token.substring(0, 5 / 2) + '...' + item.Token.substring(item.Token.length - 5 / 2, item.Token.length)}`
|
||||
)).join('\n')
|
||||
: '无必应Token记录'
|
||||
await this.reply(`${tokens}`, true)
|
||||
|
|
@ -807,7 +677,7 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
else tokens = []
|
||||
tokens = tokens.length > 0
|
||||
? tokens.map((item, index) => (
|
||||
`【${index}】 Token:${item.Token.substring(0, 5 / 2) + '...' + item.Token.substring(item.Token.length - 5 / 2, item.Token.length)}`
|
||||
`【${index}】 Token:${item.Token.substring(0, 5 / 2) + '...' + item.Token.substring(item.Token.length - 5 / 2, item.Token.length)}`
|
||||
)).join('\n')
|
||||
: '无必应Token记录'
|
||||
await this.reply(`请发送要删除的token编号\n${tokens}`, true)
|
||||
|
|
@ -1013,62 +883,6 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
return true
|
||||
}
|
||||
|
||||
// modified from miao-plugin
|
||||
async updateChatGPTPlugin (e) {
|
||||
let timer
|
||||
if (!await this.checkAuth(e)) {
|
||||
return true
|
||||
}
|
||||
let isForce = e.msg.includes('强制')
|
||||
let command = 'git pull'
|
||||
if (isForce) {
|
||||
command = 'git checkout . && git pull'
|
||||
e.reply('正在执行强制更新操作,请稍等')
|
||||
} else {
|
||||
e.reply('正在执行更新操作,请稍等')
|
||||
}
|
||||
const _path = process.cwd()
|
||||
exec(command, { cwd: `${_path}/plugins/chatgpt-plugin/` }, async function (error, stdout, stderr) {
|
||||
if (/(Already up[ -]to[ -]date|已经是最新的)/.test(stdout)) {
|
||||
e.reply('目前已经是最新版ChatGPT了~')
|
||||
return true
|
||||
}
|
||||
if (error) {
|
||||
e.reply('ChatGPT更新失败!\nError code: ' + error.code + '\n' + error.stack + '\n 请稍后重试。')
|
||||
return true
|
||||
}
|
||||
e.reply('ChatGPT更新成功,正在尝试重新启动Yunzai以应用更新...')
|
||||
e.reply('更新日志:\n' + stdout)
|
||||
timer && clearTimeout(timer)
|
||||
|
||||
let data = JSON.stringify({
|
||||
isGroup: !!e.isGroup,
|
||||
id: e.isGroup ? e.group_id : e.user_id,
|
||||
time: new Date().getTime()
|
||||
})
|
||||
await redis.set('Yz:restart', data, { EX: 120 })
|
||||
let npm = await checkPnpm()
|
||||
timer = setTimeout(function () {
|
||||
let command = `${npm} start`
|
||||
if (process.argv[1].includes('pm2')) {
|
||||
command = `${npm} run restart`
|
||||
}
|
||||
exec(command, function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
e.reply('自动重启失败,请手动重启以应用新版ChatGPT。\nError code: ' + error.code + '\n' + error.stack + '\n')
|
||||
Bot.logger.error(`重启失败\n${error.stack}`)
|
||||
return true
|
||||
} else if (stdout) {
|
||||
Bot.logger.mark('重启成功,运行已转为后台,查看日志请用命令:npm run log')
|
||||
Bot.logger.mark('停止后台运行命令:npm stop')
|
||||
process.exit()
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
async versionChatGPTPlugin (e) {
|
||||
await renderUrl(e, `http://127.0.0.1:${Config.serverPort || 3321}/version`, { Viewport: { width: 800, height: 600 } })
|
||||
}
|
||||
|
|
@ -1428,4 +1242,127 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
|
|||
await this.e.reply('设置成功')
|
||||
this.finish('doSetOpenAIPlatformToken')
|
||||
}
|
||||
}
|
||||
|
||||
async exportConfig (e) {
|
||||
if (e.isGroup || !e.isPrivate) {
|
||||
await this.reply('请私聊发送命令', true)
|
||||
return true
|
||||
}
|
||||
let redisConfig = {}
|
||||
if (await redis.exists('CHATGPT:BING_TOKENS') != 0) {
|
||||
let bingTokens = await redis.get('CHATGPT:BING_TOKENS')
|
||||
if (bingTokens) { bingTokens = JSON.parse(bingTokens) } else bingTokens = []
|
||||
redisConfig.bingTokens = bingTokens
|
||||
} else {
|
||||
redisConfig.bingTokens = []
|
||||
}
|
||||
if (await redis.exists('CHATGPT:CONFIRM') != 0) {
|
||||
redisConfig.turnConfirm = await redis.get('CHATGPT:CONFIRM') === 'on'
|
||||
}
|
||||
if (await redis.exists('CHATGPT:USE') != 0) {
|
||||
redisConfig.useMode = await redis.get('CHATGPT:USE')
|
||||
}
|
||||
const filepath = path.join('plugins/chatgpt-plugin/resources', 'view.json')
|
||||
const configView = JSON.parse(fs.readFileSync(filepath, 'utf8'))
|
||||
const configJson = JSON.stringify({
|
||||
chatConfig: Config,
|
||||
redisConfig,
|
||||
view: configView
|
||||
})
|
||||
console.log(configJson)
|
||||
const buf = Buffer.from(configJson)
|
||||
e.friend.sendFile(buf, `ChatGPT-Plugin Config ${new Date()}.json`)
|
||||
return true
|
||||
}
|
||||
|
||||
async importConfig (e) {
|
||||
if (e.isGroup || !e.isPrivate) {
|
||||
await this.reply('请私聊发送命令', true)
|
||||
return true
|
||||
}
|
||||
this.setContext('doImportConfig')
|
||||
await e.reply('请发送配置文件')
|
||||
}
|
||||
|
||||
async doImportConfig (e) {
|
||||
const file = this.e.message.find(item => item.type === 'file')
|
||||
if (file) {
|
||||
const fileUrl = await this.e.friend.getFileUrl(file.fid)
|
||||
if (fileUrl) {
|
||||
try {
|
||||
let changeConfig = []
|
||||
const response = await fetch(fileUrl)
|
||||
const data = await response.json()
|
||||
const chatdata = data.chatConfig || {}
|
||||
for (let [keyPath, value] of Object.entries(chatdata)) {
|
||||
if (keyPath === 'blockWords' || keyPath === 'promptBlockWords' || keyPath === 'initiativeChatGroups') { value = value.toString().split(/[,,;;\|]/) }
|
||||
if (Config[keyPath] != value) {
|
||||
changeConfig.push({
|
||||
item: keyPath,
|
||||
value: typeof (value) === 'object' ? JSON.stringify(value) : value,
|
||||
old: typeof (Config[keyPath]) === 'object' ? JSON.stringify(Config[keyPath]) : Config[keyPath],
|
||||
type: 'config'
|
||||
})
|
||||
Config[keyPath] = value
|
||||
}
|
||||
}
|
||||
const redisConfig = data.redisConfig || {}
|
||||
if (redisConfig.bingTokens != null) {
|
||||
changeConfig.push({
|
||||
item: 'bingTokens',
|
||||
value: JSON.stringify(redisConfig.bingTokens),
|
||||
old: await redis.get('CHATGPT:BING_TOKENS'),
|
||||
type: 'redis'
|
||||
})
|
||||
await redis.set('CHATGPT:BING_TOKENS', JSON.stringify(redisConfig.bingTokens))
|
||||
}
|
||||
if (redisConfig.turnConfirm != null) {
|
||||
changeConfig.push({
|
||||
item: 'turnConfirm',
|
||||
value: redisConfig.turnConfirm ? 'on' : 'off',
|
||||
old: await redis.get('CHATGPT:CONFIRM'),
|
||||
type: 'redis'
|
||||
})
|
||||
await redis.set('CHATGPT:CONFIRM', redisConfig.turnConfirm ? 'on' : 'off')
|
||||
}
|
||||
if (redisConfig.useMode != null) {
|
||||
changeConfig.push({
|
||||
item: 'useMode',
|
||||
value: redisConfig.useMode,
|
||||
old: await redis.get('CHATGPT:USE'),
|
||||
type: 'redis'
|
||||
})
|
||||
await redis.set('CHATGPT:USE', redisConfig.useMode)
|
||||
}
|
||||
await this.reply(await makeForwardMsg(this.e, changeConfig.map(msg => `修改项:${msg.item}\n旧数据\n\n${msg.old}\n\n新数据\n ${msg.value}`)))
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
await e.reply('配置文件错误')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await this.reply('未找到配置文件', false)
|
||||
return false
|
||||
}
|
||||
|
||||
this.finish('doImportConfig')
|
||||
}
|
||||
|
||||
async switchSmartMode (e) {
|
||||
if (e.msg.includes('开启')) {
|
||||
if (Config.smartMode) {
|
||||
await e.reply('已经开启了')
|
||||
return
|
||||
}
|
||||
Config.smartMode = true
|
||||
await e.reply('好的,已经打开智能模式,注意API额度哦。配合开启读取群聊上下文效果更佳!')
|
||||
} else {
|
||||
if (!Config.smartMode) {
|
||||
await e.reply('已经是关闭得了')
|
||||
return
|
||||
}
|
||||
Config.smartMode = false
|
||||
await e.reply('好的,已经关闭智能模式')
|
||||
}
|
||||
}
|
||||
}
|
||||
316
apps/update.js
Normal file
316
apps/update.js
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
// modified from StarRail-plugin | 已经过StarRail-plugin作者本人同意
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { createRequire } from 'module'
|
||||
import _ from 'lodash'
|
||||
import { Restart } from '../../other/restart.js'
|
||||
import fs from 'fs'
|
||||
import {} from "../utils/common.js";
|
||||
|
||||
const _path = process.cwd()
|
||||
const require = createRequire(import.meta.url)
|
||||
const { exec, execSync } = require('child_process')
|
||||
|
||||
const checkAuth = async function (e) {
|
||||
if (!e.isMaster) {
|
||||
e.reply(`只有主人才能命令ChatGPT哦~(*/ω\*)`)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 是否在更新中
|
||||
let uping = false
|
||||
|
||||
/**
|
||||
* 处理插件更新
|
||||
*/
|
||||
export class Update extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
name: 'chatgpt更新插件',
|
||||
event: 'message',
|
||||
priority: 1000,
|
||||
rule: [
|
||||
{
|
||||
reg: '^#?(chatgpt|柴特寄批踢|GPT|ChatGPT|柴特鸡批踢|Chat|CHAT|CHATGPT|柴特|ChatGPT-Plugin|ChatGPT-plugin|chatgpt-plugin)(插件)?(强制)?更新$',
|
||||
fnc: 'update'
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* rule - 更新chatgpt插件
|
||||
* @returns
|
||||
*/
|
||||
async update () {
|
||||
if (!this.e.isMaster) return false
|
||||
|
||||
/** 检查是否正在更新中 */
|
||||
if (uping) {
|
||||
await this.reply('已有命令更新中..请勿重复操作')
|
||||
return
|
||||
}
|
||||
|
||||
/** 检查git安装 */
|
||||
if (!(await this.checkGit())) return
|
||||
|
||||
const isForce = this.e.msg.includes('强制')
|
||||
|
||||
/** 执行更新 */
|
||||
await this.runUpdate(isForce)
|
||||
|
||||
/** 是否需要重启 */
|
||||
if (this.isUp) {
|
||||
// await this.reply("更新完毕,请重启云崽后生效")
|
||||
setTimeout(() => this.restart(), 2000)
|
||||
}
|
||||
}
|
||||
|
||||
restart () {
|
||||
new Restart(this.e).restart()
|
||||
}
|
||||
|
||||
/**
|
||||
* chatgpt插件更新函数
|
||||
* @param {boolean} isForce 是否为强制更新
|
||||
* @returns
|
||||
*/
|
||||
async runUpdate (isForce) {
|
||||
let command = 'git -C ./plugins/chatgpt-plugin/ pull --no-rebase'
|
||||
if (isForce) {
|
||||
command = `git -C ./plugins/chatgpt-plugin/ checkout . && ${command}`
|
||||
this.e.reply('正在执行强制更新操作,请稍等')
|
||||
} else {
|
||||
this.e.reply('正在执行更新操作,请稍等')
|
||||
}
|
||||
/** 获取上次提交的commitId,用于获取日志时判断新增的更新日志 */
|
||||
this.oldCommitId = await this.getcommitId('chatgpt-plugin')
|
||||
uping = true
|
||||
let ret = await this.execSync(command)
|
||||
uping = false
|
||||
|
||||
if (ret.error) {
|
||||
logger.mark(`${this.e.logFnc} 更新失败:chatgpt-plugin`)
|
||||
this.gitErr(ret.error, ret.stdout)
|
||||
return false
|
||||
}
|
||||
|
||||
/** 获取插件提交的最新时间 */
|
||||
let time = await this.getTime('chatgpt-plugin')
|
||||
|
||||
if (/(Already up[ -]to[ -]date|已经是最新的)/.test(ret.stdout)) {
|
||||
await this.reply(`chatgpt-plugin已经是最新版本\n最后更新时间:${time}`)
|
||||
} else {
|
||||
await this.reply(`chatgpt-plugin\n最后更新时间:${time}`)
|
||||
this.isUp = true
|
||||
/** 获取chatgpt组件的更新日志 */
|
||||
let log = await this.getLog('chatgpt-plugin')
|
||||
await this.reply(log)
|
||||
}
|
||||
|
||||
logger.mark(`${this.e.logFnc} 最后更新时间:${time}`)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取chatgpt插件的更新日志
|
||||
* @param {string} plugin 插件名称
|
||||
* @returns
|
||||
*/
|
||||
async getLog (plugin = '') {
|
||||
let cm = `cd ./plugins/${plugin}/ && git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"`
|
||||
|
||||
let logAll
|
||||
try {
|
||||
logAll = await execSync(cm, { encoding: 'utf-8' })
|
||||
} catch (error) {
|
||||
logger.error(error.toString())
|
||||
this.reply(error.toString())
|
||||
}
|
||||
|
||||
if (!logAll) return false
|
||||
|
||||
logAll = logAll.split('\n')
|
||||
|
||||
let log = []
|
||||
for (let str of logAll) {
|
||||
str = str.split('||')
|
||||
if (str[0] == this.oldCommitId) break
|
||||
if (str[1].includes('Merge branch')) continue
|
||||
log.push(str[1])
|
||||
}
|
||||
let line = log.length
|
||||
log = log.join('\n\n')
|
||||
|
||||
if (log.length <= 0) return ''
|
||||
|
||||
let end = ''
|
||||
end =
|
||||
'更多详细信息,请前往github查看\nhttps://github.com/ikechan8370/chatgpt-plugin'
|
||||
|
||||
log = await this.makeForwardMsg(`chatgpt-plugin更新日志,共${line}条`, log, end)
|
||||
|
||||
return log
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上次提交的commitId
|
||||
* @param {string} plugin 插件名称
|
||||
* @returns
|
||||
*/
|
||||
async getcommitId (plugin = '') {
|
||||
let cm = `git -C ./plugins/${plugin}/ rev-parse --short HEAD`
|
||||
|
||||
let commitId = await execSync(cm, { encoding: 'utf-8' })
|
||||
commitId = _.trim(commitId)
|
||||
|
||||
return commitId
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本次更新插件的最后一次提交时间
|
||||
* @param {string} plugin 插件名称
|
||||
* @returns
|
||||
*/
|
||||
async getTime (plugin = '') {
|
||||
let cm = `cd ./plugins/${plugin}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"`
|
||||
|
||||
let time = ''
|
||||
try {
|
||||
time = await execSync(cm, { encoding: 'utf-8' })
|
||||
time = _.trim(time)
|
||||
} catch (error) {
|
||||
logger.error(error.toString())
|
||||
time = '获取时间失败'
|
||||
}
|
||||
return time
|
||||
}
|
||||
|
||||
/**
|
||||
* 制作转发消息
|
||||
* @param {string} title 标题 - 首条消息
|
||||
* @param {string} msg 日志信息
|
||||
* @param {string} end 最后一条信息
|
||||
* @returns
|
||||
*/
|
||||
async makeForwardMsg (title, msg, end) {
|
||||
let nickname = (this.e.bot ?? Bot).nickname
|
||||
if (this.e.isGroup) {
|
||||
let info = await (this.e.bot ?? Bot).getGroupMemberInfo(this.e.group_id, (this.e.bot ?? Bot).uin)
|
||||
nickname = info.card || info.nickname
|
||||
}
|
||||
let userInfo = {
|
||||
user_id: (this.e.bot ?? Bot).uin,
|
||||
nickname
|
||||
}
|
||||
|
||||
let forwardMsg = [
|
||||
{
|
||||
...userInfo,
|
||||
message: title
|
||||
},
|
||||
{
|
||||
...userInfo,
|
||||
message: msg
|
||||
}
|
||||
]
|
||||
|
||||
if (end) {
|
||||
forwardMsg.push({
|
||||
...userInfo,
|
||||
message: end
|
||||
})
|
||||
}
|
||||
|
||||
/** 制作转发内容 */
|
||||
if (this.e.isGroup) {
|
||||
forwardMsg = await this.e.group.makeForwardMsg(forwardMsg)
|
||||
} else {
|
||||
forwardMsg = await this.e.friend.makeForwardMsg(forwardMsg)
|
||||
}
|
||||
|
||||
/** 处理描述 */
|
||||
forwardMsg.data = forwardMsg.data
|
||||
.replace(/\n/g, '')
|
||||
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
|
||||
.replace(/___+/, `<title color="#777777" size="26">${title}</title>`)
|
||||
|
||||
return forwardMsg
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理更新失败的相关函数
|
||||
* @param {string} err
|
||||
* @param {string} stdout
|
||||
* @returns
|
||||
*/
|
||||
async gitErr (err, stdout) {
|
||||
let msg = '更新失败!'
|
||||
let errMsg = err.toString()
|
||||
stdout = stdout.toString()
|
||||
|
||||
if (errMsg.includes('Timed out')) {
|
||||
let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, '')
|
||||
await this.reply(msg + `\n连接超时:${remote}`)
|
||||
return
|
||||
}
|
||||
|
||||
if (/Failed to connect|unable to access/g.test(errMsg)) {
|
||||
let remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, '')
|
||||
await this.reply(msg + `\n连接失败:${remote}`)
|
||||
return
|
||||
}
|
||||
|
||||
if (errMsg.includes('be overwritten by merge')) {
|
||||
await this.reply(
|
||||
msg +
|
||||
`存在冲突:\n${errMsg}\n` +
|
||||
'请解决冲突后再更新,或者执行#强制更新,放弃本地修改'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (stdout.includes('CONFLICT')) {
|
||||
await this.reply([
|
||||
msg + '存在冲突\n',
|
||||
errMsg,
|
||||
stdout,
|
||||
'\n请解决冲突后再更新,或者执行#强制更新,放弃本地修改'
|
||||
])
|
||||
return
|
||||
}
|
||||
|
||||
await this.reply([errMsg, stdout])
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步执行git相关命令
|
||||
* @param {string} cmd git命令
|
||||
* @returns
|
||||
*/
|
||||
async execSync (cmd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
|
||||
resolve({ error, stdout, stderr })
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查git是否安装
|
||||
* @returns
|
||||
*/
|
||||
async checkGit () {
|
||||
let ret = await execSync('git --version', { encoding: 'utf-8' })
|
||||
if (!ret || !ret.includes('git version')) {
|
||||
await this.reply('请先安装git')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue