fix: merge tons of conflict

This commit is contained in:
ikechan8370 2023-07-01 15:55:07 +08:00
commit 7a8b30db14
50 changed files with 1791 additions and 828 deletions

View file

@ -7,10 +7,8 @@ import { ChatGPTAPI } from '../utils/openai/chatgpt-api.js'
import { BingAIClient } from '@waylaidwanderer/chatgpt-api'
import SydneyAIClient from '../utils/SydneyAIClient.js'
import { PoeClient } from '../utils/poe/index.js'
import AzureTTS, { supportConfigurations } from '../utils/tts/microsoft-azure.js'
import AzureTTS from '../utils/tts/microsoft-azure.js'
import VoiceVoxTTS from '../utils/tts/voicevox.js'
import { translate } from '../utils/translate.js'
import fs from 'fs'
import {
render,
renderUrl,
@ -27,24 +25,21 @@ import {
getUserReplySetting,
getImageOcrText,
getImg,
processList,
getMaxModelTokens, formatDate
getMaxModelTokens, formatDate, generateAudio
} from '../utils/common.js'
import { ChatGPTPuppeteer } from '../utils/browser.js'
import { KeyvFile } from 'keyv-file'
import { OfficialChatGPTClient } from '../utils/message.js'
import fetch from 'node-fetch'
import { deleteConversation, getConversations, getLatestMessageIdByConversationId } from '../utils/conversation.js'
import { convertSpeaker, generateAudio, speakers } from '../utils/tts.js'
import { convertSpeaker, speakers } from '../utils/tts.js'
import ChatGLMClient from '../utils/chatglm.js'
import { convertFaces } from '../utils/face.js'
import uploadRecord from '../utils/uploadRecord.js'
import { SlackClaudeClient } from '../utils/slack/slackClient.js'
import { getPromptByName } from '../utils/prompts.js'
import BingDrawClient from '../utils/BingDraw.js'
import XinghuoClient from '../utils/xinghuo/xinghuo.js'
import { JinyanTool } from '../utils/tools/JinyanTool.js'
import { SendMusicTool } from '../utils/tools/SendMusicTool.js'
import { SendVideoTool } from '../utils/tools/SendBilibiliTool.js'
import { KickOutTool } from '../utils/tools/KickOutTool.js'
import { EditCardTool } from '../utils/tools/EditCardTool.js'
@ -58,12 +53,19 @@ import { SerpIkechan8370Tool } from '../utils/tools/SerpIkechan8370Tool.js'
import { SendPictureTool } from '../utils/tools/SendPictureTool.js'
import { SerpImageTool } from '../utils/tools/SearchImageTool.js'
import { ImageCaptionTool } from '../utils/tools/ImageCaptionTool.js'
import { TTSTool } from '../utils/tools/TTSTool.js'
import { SendAudioMessageTool } from '../utils/tools/SendAudioMessageTool.js'
import { ProcessPictureTool } from '../utils/tools/ProcessPictureTool.js'
import { APTool } from '../utils/tools/APTool.js'
import { QueryGenshinTool } from '../utils/tools/QueryGenshinTool.js'
import { HandleMessageMsgTool } from '../utils/tools/HandleMessageMsgTool.js'
import {QueryUserinfoTool} from "../utils/tools/QueryUserinfoTool.js";
import { QueryUserinfoTool } from '../utils/tools/QueryUserinfoTool.js'
import { EliMovieTool } from '../utils/tools/EliMovieTool.js'
import { EliMusicTool } from '../utils/tools/EliMusicTool.js'
import { SendMusicTool } from '../utils/tools/SendMusicTool.js'
import { SendDiceTool } from '../utils/tools/SendDiceTool.js'
import { SendAvatarTool } from '../utils/tools/SendAvatarTool.js'
import { SendMessageToSpecificGroupOrUserTool } from '../utils/tools/SendMessageToSpecificGroupOrUserTool.js'
try {
await import('emoji-strip')
} catch (err) {
@ -283,6 +285,8 @@ export class chatgpt extends plugin {
return
}
let ats = e.message.filter(m => m.type === 'at')
const isAtMode = Config.toggleMode === 'at'
if (isAtMode) ats = ats.filter(item => item.qq !== Bot.uin)
if (ats.length === 0) {
if (use === 'api3') {
await redis.del(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`)
@ -783,16 +787,37 @@ export class chatgpt extends plugin {
return false
}
// 黑白名单过滤对话
let [whitelist, blacklist] = processList(Config.whitelist, Config.blacklist)
let [whitelist, blacklist] = [Config.whitelist, Config.blacklist]
let chatPermission = false // 对话许可
if (whitelist.join('').length > 0) {
if (e.isGroup && !whitelist.includes(e.group_id.toString())) return false
const list = whitelist.filter(elem => elem.startsWith('^')).map(elem => elem.slice(1))
if (!list.includes(e.sender.user_id.toString())) return false
for (const item of whitelist) {
if (item.length > 11) {
const [group, qq] = item.split('^')
if (e.isGroup && group === e.group_id.toString() && qq === e.sender.user_id.toString()) {
chatPermission = true
break
}
} else if (item.startsWith('^') && item.slice(1) === e.sender.user_id.toString()) {
chatPermission = true
break
} else if (e.isGroup && !item.startsWith('^') && item === e.group_id.toString()) {
chatPermission = true
break
}
}
}
if (blacklist.join('').length > 0) {
if (e.isGroup && blacklist.includes(e.group_id.toString())) return false
const list = blacklist.filter(elem => elem.startsWith('^')).map(elem => elem.slice(1))
if (list.includes(e.sender.user_id.toString())) return false
// 当前用户有对话许可则不再判断黑名单
if (!chatPermission) {
if (blacklist.join('').length > 0) {
for (const item of blacklist) {
if (e.isGroup && !item.startsWith('^') && item === e.group_id.toString()) return false
if (item.startsWith('^') && item.slice(1) === e.sender.user_id.toString()) return false
if (item.length > 11) {
const [group, qq] = item.split('^')
if (e.isGroup && group === e.group_id.toString() && qq === e.sender.user_id.toString()) return false
}
}
}
}
let userSetting = await getUserReplySetting(this.e)
@ -1149,82 +1174,12 @@ export class chatgpt extends plugin {
this.reply(`建议的回复:\n${chatMessage.suggestedResponses}`)
}
}
let wav
if (Config.ttsMode === 'vits-uma-genshin-honkai' && Config.ttsSpace) {
if (Config.autoJapanese) {
try {
ttsResponse = await translate(ttsResponse, '日')
} catch (err) {
logger.error(err)
await this.reply(err.message + '\n将使用原始文本合成语音...')
}
}
try {
wav = await generateAudio(ttsResponse, speaker, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
} catch (err) {
logger.error(err)
await this.reply('合成语音发生错误~')
}
} else if (Config.ttsMode === 'azure' && Config.azureTTSKey) {
if (speaker !== '随机') {
let languagePrefix = AzureTTS.supportConfigurations.find(config => config.code === speaker).languageDetail.charAt(0)
languagePrefix = languagePrefix.startsWith('E') ? '英' : languagePrefix
ttsResponse = (await translate(ttsResponse, languagePrefix)).replace('\n', '')
} else {
let role, languagePrefix
role = AzureTTS.supportConfigurations[Math.floor(Math.random() * supportConfigurations.length)]
speaker = role.code
languagePrefix = role.languageDetail.charAt(0).startsWith('E') ? '英' : role.languageDetail.charAt(0)
ttsResponse = (await translate(ttsResponse, languagePrefix)).replace('\n', '')
if (role?.emotion) {
const keys = Object.keys(role.emotion)
emotion = keys[Math.floor(Math.random() * keys.length)]
}
logger.info('using speaker: ' + speaker)
logger.info('using language: ' + languagePrefix)
logger.info('using emotion: ' + emotion)
}
let ssml = AzureTTS.generateSsml(ttsResponse, {
speaker,
emotion,
emotionDegree
})
wav = await AzureTTS.generateAudio(ttsResponse, {
speaker
}, await ssml)
} else if (Config.ttsMode === 'voicevox' && Config.voicevoxSpace) {
ttsResponse = (await translate(ttsResponse, '日')).replace('\n', '')
wav = await VoiceVoxTTS.generateAudio(ttsResponse, {
speaker
})
} else if (!Config.ttsSpace && !Config.azureTTSKey && !Config.voicevoxSpace) {
await this.reply('你没有配置转语音API哦')
}
try {
try {
let sendable = await uploadRecord(wav, Config.ttsMode)
if (sendable) {
await e.reply(sendable)
} else {
// 如果合成失败尝试使用ffmpeg合成
await e.reply(segment.record(wav))
}
} catch (err) {
logger.error(err)
await e.reply(segment.record(wav))
}
} catch (err) {
logger.error(err)
const sendable = await generateAudio(this.e, ttsResponse, emotion, emotionDegree)
if (sendable) {
await this.reply(sendable)
} else {
await this.reply('合成语音发生错误~')
}
if (Config.ttsMode === 'azure' && Config.azureTTSKey) {
// 清理文件
try {
fs.unlinkSync(wav)
} catch (err) {
logger.warn(err)
}
}
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
// todo use next api of chatgpt to complete incomplete respoonse
try {
@ -1849,12 +1804,13 @@ export class chatgpt extends plugin {
chats.push(...chatHistory.reverse())
}
chats = chats.slice(0, Config.groupContextLength)
// 太多可能会干扰AI对自身qq号和用户qq的判断感觉gpt3.5也处理不了那么多信息
chats = chats > 50 ? 50 : chats
let mm = await e.group.getMemberMap()
chats.forEach(chat => {
let sender = mm.get(chat.sender.user_id)
chat.sender = sender
})
// console.log(chats)
opt.chats = chats
const namePlaceholder = '[name]'
const defaultBotName = 'ChatGPT'
@ -1872,8 +1828,7 @@ export class chatgpt extends plugin {
admin: 'group administrator'
}
if (chats) {
system += `There is the conversation history in the group, you must chat according to the conversation history context"
`
system += `There is the conversation history in the group, you must chat according to the conversation history context"`
system += chats
.map(chat => {
let sender = chat.sender || {}
@ -1891,6 +1846,7 @@ export class chatgpt extends plugin {
logger.warn('获取群聊聊天记录失败,本次对话不携带聊天记录', err)
}
}
// logger.info(system)
}
let opts = {
apiBaseUrl: Config.openAiBaseUrl,
@ -1949,45 +1905,58 @@ export class chatgpt extends plugin {
new WeatherTool(),
new SendPictureTool(),
new SendVideoTool(),
new SearchMusicTool(),
new SendMusicTool(),
new ImageCaptionTool(),
new SearchVideoTool(),
new SendAvatarTool(),
new SerpImageTool(),
new SearchMusicTool(),
new SendMusicTool(),
new SerpIkechan8370Tool(),
new SerpTool(),
new TTSTool(),
new SendAudioMessageTool(),
new ProcessPictureTool(),
new APTool(),
new QueryGenshinTool(),
new HandleMessageMsgTool(),
new QueryUserinfoTool()
new QueryUserinfoTool(),
new EliMusicTool(),
new EliMovieTool(),
new SendMessageToSpecificGroupOrUserTool(),
new SendDiceTool(),
new QueryGenshinTool()
]
// todo 3.0再重构tool的插拔和管理
let tools = [
// new SendAvatarTool(),
// new SendDiceTool(),
new SendAvatarTool(),
new SendDiceTool(),
new SendMessageToSpecificGroupOrUserTool(),
// new EditCardTool(),
new QueryStarRailTool(),
new QueryGenshinTool(),
new ProcessPictureTool(),
new WebsiteTool(),
// new JinyanTool(),
// new KickOutTool(),
new WeatherTool(),
new SendPictureTool(),
new TTSTool(),
new SendAudioMessageTool(),
new APTool(),
// new HandleMessageMsgTool(),
serpTool,
new QueryUserinfoTool()
]
try {
await import('../../avocado-plugin/apps/avocado.js')
tools.push(...[new EliMusicTool(), new EliMovieTool()])
} catch (err) {
tools.push(...[new SendMusicTool(), new SearchMusicTool()])
logger.mark(logger.green('【ChatGPT-Plugin】插件avocado-plugin未安装') + ',安装后可查看最近热映电影与体验可玩性更高的点歌工具。\n可前往 https://github.com/Qz-Sean/avocado-plugin 获取')
}
if (e.isGroup) {
let botInfo = await Bot.getGroupMemberInfo(e.group_id, Bot.uin, true)
if (botInfo.role !== 'member') {
// 管理员才给这些工具
tools.push(...[new EditCardTool(), new JinyanTool(), new KickOutTool(), new HandleMessageMsgTool()])
// 用于撤回和加精的id
if (e.source?.seq) {
let source = (await e.group.getChatHistory(e.source?.seq, 1)).pop()
option.systemMessage += `\nthe last message is replying to ${source.message_id}"\n`
@ -2025,8 +1994,7 @@ export class chatgpt extends plugin {
tools.push(new SerpImageTool())
tools.push(...[new SearchVideoTool(),
new SendVideoTool(),
new SearchMusicTool(),
new SendMusicTool()])
new EliMusicTool()])
}
let funcMap = {}
let fullFuncMap = {}
@ -2053,6 +2021,7 @@ export class chatgpt extends plugin {
while (msg.functionCall) {
let { name, arguments: args } = msg.functionCall
args = JSON.parse(args)
// 感觉换成targetGroupIdOrUserQQNumber这种表意比较清楚的变量名效果会好一丢丢
if (!args.groupId) {
args.groupId = e.group_id + '' || e.sender.user_id + ''
}
@ -2061,14 +2030,6 @@ export class chatgpt extends plugin {
} catch (err) {
args.groupId = e.group_id + '' || e.sender.user_id + ''
}
if (!args.qq) {
args.qq = e.sender.user_id + ''
}
try {
parseInt(args.qq)
} catch (err) {
args.qq = e.sender.user_id + ''
}
let functionResult = await fullFuncMap[name].exec(Object.assign({ isAdmin, sender }, args), e)
logger.mark(`function ${name} execution result: ${functionResult}`)
option.parentMessageId = msg.id

View file

@ -1,7 +1,7 @@
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'
@ -304,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) {
@ -362,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)
}

View file

@ -8,7 +8,7 @@ import {
getVitsRoleList,
getVoicevoxRoleList,
makeForwardMsg,
parseDuration, processList,
parseDuration,
renderUrl
} from '../utils/common.js'
import SydneyAIClient from '../utils/SydneyAIClient.js'
@ -20,10 +20,8 @@ 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) {
constructor(e) {
super({
name: 'ChatGPT-Plugin 管理',
dsc: '插件的管理项配置,让你轻松掌控各个功能的开闭和管理。包含各种实用的配置选项,让你的聊天更加便捷和高效!',
@ -195,21 +193,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',
@ -268,7 +251,7 @@ export class ChatgptManagement extends plugin {
})
}
async viewUserSetting (e) {
async viewUserSetting(e) {
const userSetting = await getUserReplySetting(this.e)
const replyMsg = `${this.e.sender.user_id}的回复设置:
图片模式: ${userSetting.usePicture === true ? '开启' : '关闭'}
@ -281,7 +264,7 @@ ${userSetting.useTTS === true ? '当前语音模式为' + Config.ttsMode : ''}`
return true
}
async getTTSRoleList (e) {
async getTTSRoleList(e) {
const matchCommand = e.msg.match(/^#(chatgpt)?(vits|azure|vox)?语音(服务|角色列表)/)
if (matchCommand[3] === '服务') {
await this.reply(`当前支持vox、vits、azure语音服务可使用'#(vox|azure|vits)语音角色列表'查看支持的语音角色。
@ -332,7 +315,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
await this.reply(roleList)
}
async ttsSwitch (e) {
async ttsSwitch(e) {
let userReplySetting = await getUserReplySetting(this.e)
if (!userReplySetting.useTTS) {
let replyMsg
@ -359,11 +342,11 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return false
}
async commandHelp (e) {
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 = {
@ -375,7 +358,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
聊天记录: '聊天记录'
}
function getCategory (e, plugin) {
function getCategory(e, plugin) {
for (const key in categories) {
if (e.msg.includes(key) && plugin.name.includes(categories[key])) {
return '功能名称: '
@ -440,7 +423,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return true
}
async setList (e) {
async setList(e) {
this.setContext('saveList')
isWhiteList = e.msg.includes('白')
const listType = isWhiteList ? '对话白名单' : '对话黑名单'
@ -448,7 +431,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return false
}
async saveList (e) {
async saveList(e) {
if (!this.e.msg) return
const listType = isWhiteList ? '对话白名单' : '对话黑名单'
const regex = /^\^?[1-9]\d{5,9}$/
@ -485,7 +468,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
this.finish('saveList')
}
async checkList (e) {
async checkList(e) {
if (e.msg.includes('帮助')) {
await this.reply('默认设置为添加群号需要拉黑QQ号时在前面添加^(例如:^123456),可一次性混合输入多个配置号码,错误项会自动忽略。具体使用指令可通过 "#指令表搜索名单" 查看,白名单优先级高于黑名单。')
return true
@ -498,7 +481,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return false
}
async delList (e) {
async delList(e) {
isWhiteList = e.msg.includes('白')
const listType = isWhiteList ? '对话白名单' : '对话黑名单'
let replyMsg = ''
@ -516,7 +499,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return false
}
async confirmDelList (e) {
async confirmDelList(e) {
if (!this.e.msg) return
const isAllDeleted = this.e.msg.trim() === '全部删除'
const regex = /^\^?[1-9]\d{5,9}$/
@ -560,13 +543,13 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
this.finish('confirmDelList')
}
async enablePrivateChat (e) {
async enablePrivateChat(e) {
Config.enablePrivateChat = !!e.msg.match(/(允许|打开|同意)/)
await this.reply('设置成功', e.isGroup)
return false
}
async enableGroupContext (e) {
async enableGroupContext(e) {
const reg = /(关闭|打开)/
const match = e.msg.match(reg)
if (match) {
@ -582,7 +565,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return false
}
async setDefaultReplySetting (e) {
async setDefaultReplySetting(e) {
const reg = /^#chatgpt(打开|关闭|设置)?全局((文本模式|图片模式|语音模式|((azure|vits|vox)?语音角色|角色语音|角色)(.*))|回复帮助)/
const matchCommand = e.msg.match(reg)
const settingType = matchCommand[2]
@ -715,31 +698,31 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
await this.reply(replyMsg, true)
}
async turnOnConfirm (e) {
async turnOnConfirm(e) {
await redis.set('CHATGPT:CONFIRM', 'on')
await this.reply('已开启消息确认', true)
return false
}
async turnOffConfirm (e) {
async turnOffConfirm(e) {
await redis.set('CHATGPT:CONFIRM', 'off')
await this.reply('已关闭消息确认', true)
return false
}
async setAccessToken (e) {
async setAccessToken(e) {
this.setContext('saveToken')
await this.reply('请发送ChatGPT AccessToken', true)
return false
}
async setPoeCookie () {
async setPoeCookie() {
this.setContext('savePoeToken')
await this.reply('请发送Poe Cookie', true)
return false
}
async savePoeToken (e) {
async savePoeToken(e) {
if (!this.e.msg) return
let token = this.e.msg
if (!token.startsWith('p-b=')) {
@ -752,13 +735,13 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
this.finish('savePoeToken')
}
async setBingAccessToken (e) {
async setBingAccessToken(e) {
this.setContext('saveBingToken')
await this.reply('请发送Bing Cookie Token.("_U" cookie from bing.com)', true)
return false
}
async migrateBingAccessToken () {
async migrateBingAccessToken() {
let token = await redis.get('CHATGPT:BING_TOKEN')
if (token) {
token = token.split('|')
@ -782,27 +765,27 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
await this.reply('迁移完成', true)
}
async getBingAccessToken (e) {
async getBingAccessToken(e) {
let tokens = await redis.get('CHATGPT:BING_TOKENS')
if (tokens) tokens = JSON.parse(tokens)
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)
return false
}
async delBingAccessToken (e) {
async delBingAccessToken(e) {
this.setContext('deleteBingToken')
let tokens = await redis.get('CHATGPT:BING_TOKENS')
if (tokens) tokens = JSON.parse(tokens)
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)
@ -810,7 +793,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return false
}
async saveBingToken () {
async saveBingToken() {
if (!this.e.msg) return
let token = this.e.msg
if (token.length < 100) {
@ -867,7 +850,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
this.finish('saveBingToken')
}
async deleteBingToken () {
async deleteBingToken() {
if (!this.e.msg) return
let tokenId = this.e.msg
if (await redis.exists('CHATGPT:BING_TOKENS') != 0) {
@ -888,7 +871,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async saveToken () {
async saveToken() {
if (!this.e.msg) return
let token = this.e.msg
if (!token.startsWith('ey') || token.length < 20) {
@ -901,12 +884,12 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
this.finish('saveToken')
}
async useBrowserBasedSolution (e) {
async useBrowserBasedSolution(e) {
await redis.set('CHATGPT:USE', 'browser')
await this.reply('已切换到基于浏览器的解决方案,如果已经对话过建议执行`#结束对话`避免引起404错误')
}
async useOpenAIAPIBasedSolution (e) {
async useOpenAIAPIBasedSolution(e) {
let use = await redis.get('CHATGPT:USE')
if (use !== 'api') {
await redis.set('CHATGPT:USE', 'api')
@ -916,12 +899,12 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async useChatGLMSolution (e) {
async useChatGLMSolution(e) {
await redis.set('CHATGPT:USE', 'chatglm')
await this.reply('已切换到ChatGLM-6B解决方案如果已经对话过建议执行`#结束对话`避免引起404错误')
}
async useReversedAPIBasedSolution2 (e) {
async useReversedAPIBasedSolution2(e) {
let use = await redis.get('CHATGPT:USE')
if (use !== 'api3') {
await redis.set('CHATGPT:USE', 'api3')
@ -931,7 +914,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async useBingSolution (e) {
async useBingSolution(e) {
let use = await redis.get('CHATGPT:USE')
if (use !== 'bing') {
await redis.set('CHATGPT:USE', 'bing')
@ -941,7 +924,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async useClaudeBasedSolution (e) {
async useClaudeBasedSolution(e) {
let use = await redis.get('CHATGPT:USE')
if (use !== 'poe') {
await redis.set('CHATGPT:USE', 'poe')
@ -951,7 +934,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async useSlackClaudeBasedSolution () {
async useSlackClaudeBasedSolution() {
let use = await redis.get('CHATGPT:USE')
if (use !== 'claude') {
await redis.set('CHATGPT:USE', 'claude')
@ -961,7 +944,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async useXinghuoBasedSolution () {
async useXinghuoBasedSolution() {
let use = await redis.get('CHATGPT:USE')
if (use !== 'xh') {
await redis.set('CHATGPT:USE', 'xh')
@ -971,7 +954,7 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async changeBingTone (e) {
async changeBingTone(e) {
let tongStyle = e.msg.replace(/^#chatgpt(必应|Bing)切换/, '')
if (!tongStyle) {
return
@ -994,12 +977,12 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
}
}
async bingOpenSuggestedResponses (e) {
async bingOpenSuggestedResponses(e) {
Config.enableSuggestedResponses = e.msg.indexOf('开启') > -1
await e.reply('操作成功')
}
async checkAuth (e) {
async checkAuth(e) {
if (!e.isMaster) {
e.reply(`只有主人才能命令ChatGPT哦~
(*/ω*)`)
@ -1008,11 +991,11 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
return true
}
async versionChatGPTPlugin (e) {
async versionChatGPTPlugin(e) {
await renderUrl(e, `http://127.0.0.1:${Config.serverPort || 3321}/version`, { Viewport: { width: 800, height: 600 } })
}
async modeHelp () {
async modeHelp() {
let mode = await redis.get('CHATGPT:USE')
const modeMap = {
browser: '浏览器',
@ -1049,7 +1032,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
await this.reply(message)
}
async shutUp (e) {
async shutUp(e) {
let duration = e.msg.replace(/^#chatgpt(本群)?(群\d+)?(关闭|闭嘴|关机|休眠|下班)/, '')
let scope
let time = 3600000
@ -1101,7 +1084,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
}
}
async openMouth (e) {
async openMouth(e) {
const match = e.msg.match(/^#chatgpt群(\d+)/)
if (e.msg.indexOf('本群') > -1) {
if (await redis.get('CHATGPT:SHUT_UP:ALL')) {
@ -1156,7 +1139,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
}
}
async listShutUp () {
async listShutUp() {
let keys = await redis.keys('CHATGPT:SHUT_UP:*')
if (!keys || keys.length === 0) {
await this.reply('已经开启过全群响应啦', true)
@ -1173,13 +1156,13 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
}
}
async setAPIKey (e) {
async setAPIKey(e) {
this.setContext('saveAPIKey')
await this.reply('请发送OpenAI API Key.', true)
return false
}
async saveAPIKey () {
async saveAPIKey() {
if (!this.e.msg) return
let token = this.e.msg
if (!token.startsWith('sk-')) {
@ -1193,13 +1176,13 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('saveAPIKey')
}
async setXinghuoToken () {
async setXinghuoToken() {
this.setContext('saveXinghuoToken')
await this.reply('请发送星火的ssoSessionId', true)
return false
}
async saveXinghuoToken () {
async saveXinghuoToken() {
if (!this.e.msg) return
let token = this.e.msg
// todo
@ -1208,13 +1191,13 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('saveXinghuoToken')
}
async setAPIPromptPrefix (e) {
async setAPIPromptPrefix(e) {
this.setContext('saveAPIPromptPrefix')
await this.reply('请发送用于API模式的设定', true)
return false
}
async saveAPIPromptPrefix (e) {
async saveAPIPromptPrefix(e) {
if (!this.e.msg) return
if (this.e.msg === '取消') {
await this.reply('已取消设置API设定', true)
@ -1227,13 +1210,13 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('saveAPIPromptPrefix')
}
async setBingPromptPrefix (e) {
async setBingPromptPrefix(e) {
this.setContext('saveBingPromptPrefix')
await this.reply('请发送用于Bing Sydney模式的设定', true)
return false
}
async saveBingPromptPrefix (e) {
async saveBingPromptPrefix(e) {
if (!this.e.msg) return
if (this.e.msg === '取消') {
await this.reply('已取消设置Sydney设定', true)
@ -1245,7 +1228,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('saveBingPromptPrefix')
}
async switchDraw (e) {
async switchDraw(e) {
if (e.msg.indexOf('开启') > -1) {
if (Config.enableDraw) {
await this.reply('当前已经开启chatgpt画图功能', true)
@ -1263,15 +1246,15 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
}
}
async queryAPIPromptPrefix (e) {
async queryAPIPromptPrefix(e) {
await this.reply(Config.promptPrefixOverride, true)
}
async queryBingPromptPrefix (e) {
async queryBingPromptPrefix(e) {
await this.reply(Config.sydney, true)
}
async setAdminPassword (e) {
async setAdminPassword(e) {
if (e.isGroup || !e.isPrivate) {
await this.reply('请私聊发送命令', true)
return true
@ -1281,7 +1264,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
return false
}
async setUserPassword (e) {
async setUserPassword(e) {
if (e.isGroup || !e.isPrivate) {
await this.reply('请私聊发送命令', true)
return true
@ -1291,7 +1274,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
return false
}
async saveAdminPassword (e) {
async saveAdminPassword(e) {
if (!this.e.msg) return
const passwd = this.e.msg
await redis.set('CHATGPT:ADMIN_PASSWD', md5(passwd))
@ -1299,7 +1282,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('saveAdminPassword')
}
async saveUserPassword (e) {
async saveUserPassword(e) {
if (!this.e.msg) return
const passwd = this.e.msg
const dir = 'resources/ChatGPTCache/user'
@ -1335,7 +1318,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('saveUserPassword')
}
async adminPage (e) {
async adminPage(e) {
if (!Config.groupAdminPage && (e.isGroup || !e.isPrivate)) {
await this.reply('请私聊发送命令', true)
return true
@ -1344,7 +1327,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
await this.reply(`请登录${viewHost + 'admin/settings'}进行系统配置`, true)
}
async userPage (e) {
async userPage(e) {
if (!Config.groupAdminPage && (e.isGroup || !e.isPrivate)) {
await this.reply('请私聊发送命令', true)
return true
@ -1353,12 +1336,12 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
await this.reply(`请登录${viewHost + 'admin/dashboard'}进行系统配置`, true)
}
async setOpenAIPlatformToken (e) {
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如果仍不能查看余额请退出登录重新获取刷新令牌')
}
async doSetOpenAIPlatformToken () {
async doSetOpenAIPlatformToken() {
let token = this.e.msg
if (!token) {
return false
@ -1368,7 +1351,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('doSetOpenAIPlatformToken')
}
async exportConfig (e) {
async exportConfig(e) {
if (e.isGroup || !e.isPrivate) {
await this.reply('请私聊发送命令', true)
return true
@ -1387,9 +1370,12 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
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
redisConfig,
view: configView
})
console.log(configJson)
const buf = Buffer.from(configJson)
@ -1397,7 +1383,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
return true
}
async importConfig (e) {
async importConfig(e) {
if (e.isGroup || !e.isPrivate) {
await this.reply('请私聊发送命令', true)
return true
@ -1406,7 +1392,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
await e.reply('请发送配置文件')
}
async doImportConfig (e) {
async doImportConfig(e) {
const file = this.e.message.find(item => item.type === 'file')
if (file) {
const fileUrl = await this.e.friend.getFileUrl(file.fid)
@ -1470,7 +1456,7 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
this.finish('doImportConfig')
}
async switchSmartMode (e) {
async switchSmartMode(e) {
if (e.msg.includes('开启')) {
if (Config.smartMode) {
await e.reply('已经开启了')