diff --git a/apps/chat.js b/apps/chat.js index b897863..d18b8a6 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -206,6 +206,13 @@ export class chatgpt extends plugin { await redis.del(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`) await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true) } else if (use === 'bing' && (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom')) { + let c = await redis.get(`CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`) + if (!c) { + await this.reply('当前没有开启对话', true) + return + } else { + await redis.del(`CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`) + } const conversation = { store: new KeyvFile({ filename: 'cache.json' }), namespace: Config.toneStyle @@ -735,7 +742,11 @@ export class chatgpt extends plugin { previousConversation.invocationId = chatMessage.invocationId previousConversation.parentMessageId = chatMessage.parentMessageId previousConversation.conversationSignature = chatMessage.conversationSignature - previousConversation.bingToken = chatMessage.bingToken + if (Config.toneStyle !== 'Sydney' && Config.toneStyle !== 'Custom') { + previousConversation.bingToken = chatMessage.bingToken + } else { + previousConversation.bingToken = '' + } } else { previousConversation.parentMessageId = chatMessage.id } @@ -996,16 +1007,24 @@ export class chatgpt extends plugin { } case 'bing': { let bingToken = await redis.get('CHATGPT:BING_TOKEN') - // 负载均衡 - if (!conversation.bingToken) { - const bingTokens = bingToken.split('|') - const select = Math.floor(Math.random() * bingTokens.length) - bingToken = bingTokens[select] - } else bingToken = conversation.bingToken - if (!bingToken) { throw new Error('未绑定Bing Cookie,请使用#chatgpt设置必应token命令绑定Bing Cookie') } + const bingTokens = bingToken.split('|') + // 负载均衡 + if (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') { + // sydney下不需要保证同一token + const select = Math.floor(Math.random() * bingTokens.length) + bingToken = bingTokens[select] + } else { + // bing 下,需要保证同一对话使用同一账号的token + if (!conversation.bingToken) { + const select = Math.floor(Math.random() * bingTokens.length) + bingToken = bingTokens[select] + } else if (bingTokens.indexOf(conversation.bingToken) > -1) { + bingToken = conversation.bingToken + } + } let cookies if (bingToken?.indexOf('=') > -1) { cookies = bingToken diff --git a/apps/management.js b/apps/management.js index 145f568..4fad2d2 100644 --- a/apps/management.js +++ b/apps/management.js @@ -3,7 +3,7 @@ import { Config } from '../utils/config.js' import { BingAIClient } from '@waylaidwanderer/chatgpt-api' import { exec } from 'child_process' import { checkPnpm, formatDuration, parseDuration } from '../utils/common.js' -import SydneyAIClient from "../utils/SydneyAIClient.js"; +import SydneyAIClient from '../utils/SydneyAIClient.js' export class ChatgptManagement extends plugin { constructor (e) { @@ -168,7 +168,7 @@ export class ChatgptManagement extends plugin { await this.reply(`${tokens}`, true) return false } - + async delBingAccessToken (e) { this.setContext('deleteBingToken') let tokens = await redis.get('CHATGPT:BING_TOKEN') @@ -211,7 +211,7 @@ export class ChatgptManagement extends plugin { let bingToken = await redis.get('CHATGPT:BING_TOKEN') bingToken = bingToken.split('|') if (!bingToken.includes(token)) bingToken.push(token) - bingToken = bingToken.filter (function (element) { return element !== '' }) + bingToken = bingToken.filter(function (element) { return element !== '' }) token = bingToken.join('|') } await redis.set('CHATGPT:BING_TOKEN', token) @@ -224,14 +224,14 @@ export class ChatgptManagement extends plugin { let bingToken = await redis.get('CHATGPT:BING_TOKEN') bingToken = bingToken.split('|') let tokenId = this.e.msg - if (!bingToken[tokenId]) { + if (bingToken[tokenId] === null || bingToken[tokenId] === undefined) { await this.reply('Token编号错误!', true) this.finish('deleteBingToken') return } const removeToken = bingToken[tokenId] bingToken.splice(tokenId, 1) - bingToken = bingToken.filter (function (element) { return element !== '' }) + bingToken = bingToken.filter(function (element) { return element !== '' }) let token = bingToken.join('|') await redis.set('CHATGPT:BING_TOKEN', token) await this.reply(`Token ${removeToken.substring(0, 5 / 2) + '...' + removeToken.substring(removeToken.length - 5 / 2, removeToken.length)} 移除成功`, true)