fix: bing自动刷新;<EMPTY>匹配错误

This commit is contained in:
ikechan8370 2025-02-06 21:46:02 +08:00
parent f9a6fafb9e
commit e67a145635
4 changed files with 26 additions and 23 deletions

View file

@ -1,23 +1,6 @@
import { CustomGoogleGeminiClient } from '../client/CustomGoogleGeminiClient.js'
import { Config } from '../utils/config.js' import { Config } from '../utils/config.js'
import { getImg } from '../utils/common.js'
import { getChatHistoryGroup } from '../utils/chat.js' import { getChatHistoryGroup } from '../utils/chat.js'
import { SearchVideoTool } from '../utils/tools/SearchBilibiliTool.js'
import { SerpImageTool } from '../utils/tools/SearchImageTool.js'
import { SearchMusicTool } from '../utils/tools/SearchMusicTool.js'
import { SendAvatarTool } from '../utils/tools/SendAvatarTool.js'
import { SendVideoTool } from '../utils/tools/SendBilibiliTool.js'
import { SendMusicTool } from '../utils/tools/SendMusicTool.js'
import { SendPictureTool } from '../utils/tools/SendPictureTool.js'
import { WebsiteTool } from '../utils/tools/WebsiteTool.js'
import { convertFaces } from '../utils/face.js' import { convertFaces } from '../utils/face.js'
import { WeatherTool } from '../utils/tools/WeatherTool.js'
import { EditCardTool } from '../utils/tools/EditCardTool.js'
import { JinyanTool } from '../utils/tools/JinyanTool.js'
import { KickOutTool } from '../utils/tools/KickOutTool.js'
import { SetTitleTool } from '../utils/tools/SetTitleTool.js'
import { SerpTool } from '../utils/tools/SerpTool.js'
import { SendMessageToSpecificGroupOrUserTool } from '../utils/tools/SendMessageToSpecificGroupOrUserTool.js'
import { customSplitRegex, filterResponseChunk } from '../utils/text.js' import { customSplitRegex, filterResponseChunk } from '../utils/text.js'
import core from '../model/core.js' import core from '../model/core.js'

View file

@ -24,6 +24,7 @@ import { supportConfigurations as azureRoleList } from '../utils/tts/microsoft-a
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { newFetch } from '../utils/proxy.js' import { newFetch } from '../utils/proxy.js'
import { createServer, runServer, stopServer } from '../server/index.js' import { createServer, runServer, stopServer } from '../server/index.js'
import { BingAIClient } from '../client/CopilotAIClient.js'
export class ChatgptManagement extends plugin { export class ChatgptManagement extends plugin {
constructor (e) { constructor (e) {
@ -362,6 +363,15 @@ export class ChatgptManagement extends plugin {
reg: '^#(chatgpt)?(Copilot|Bing|必应)配置方法', reg: '^#(chatgpt)?(Copilot|Bing|必应)配置方法',
fnc: 'copilotSetting' fnc: 'copilotSetting'
} }
],
task: [
{
cron: '0 */2 * * * ?',
// cron: '*/1 * * * *',
name: 'refreshBingAi',
fnc: 'refreshBingAi',
log: false
}
] ]
}) })
this.reply = async (msg, quote, data) => { this.reply = async (msg, quote, data) => {
@ -1848,7 +1858,6 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
} }
} }
async switchBYM (e) { async switchBYM (e) {
if (e.msg.includes('开启')) { if (e.msg.includes('开启')) {
if (Config.enableBYM) { if (Config.enableBYM) {
@ -1916,4 +1925,15 @@ azure语音Azure 语音是微软 Azure 平台提供的一项语音服务,
await e.reply('操作成功') await e.reply('操作成功')
} }
async refreshBingAi () {
if (Config.bingAiRefreshToken) {
let client = new BingAIClient(Config.bingAiToken, Config.sydneyReverseProxy, Config.debug, Config._2captchaKey, Config.bingAiClientId, Config.bingAiScope, Config.bingAiRefreshToken, Config.bingAiOid, Config.bingReasoning)
let json = await client.doRefreshToken()
if (json.refresh_token) {
logger.mark('Bing AI Token Refreshed')
} else {
logger.mark('Failed to refresh Bing AI Token')
}
}
}
} }

View file

@ -2,7 +2,7 @@ import WebSocket from 'ws'
import common from '../../../lib/common/common.js' import common from '../../../lib/common/common.js'
import _ from 'lodash' import _ from 'lodash'
import { pTimeout } from '../utils/common.js' import { pTimeout } from '../utils/common.js'
import {Config} from '../utils/config.js' import { Config } from '../utils/config.js'
export class BingAIClient { export class BingAIClient {
constructor (accessToken, baseUrl = 'wss://copilot.microsoft.com', debug, _2captchaKey, clientId, scope, refreshToken, oid, reasoning = false) { constructor (accessToken, baseUrl = 'wss://copilot.microsoft.com', debug, _2captchaKey, clientId, scope, refreshToken, oid, reasoning = false) {
@ -81,7 +81,7 @@ export class BingAIClient {
if (code === 401) { if (code === 401) {
logger.error('token expired. try to refresh with refresh token') logger.error('token expired. try to refresh with refresh token')
await this.doRefreshToken(this.clientId, this.scope, this.refreshToken, this.oid) await this.doRefreshToken()
} }
}) })
@ -282,7 +282,7 @@ export class BingAIClient {
method: 'POST' method: 'POST'
}) })
if (createConversationRsp.status === 401) { if (createConversationRsp.status === 401) {
await this.doRefreshToken(this.clientId, this.scope, this.refreshToken, this.oid) await this.doRefreshToken()
return await this._generateConversationId(times - 1) return await this._generateConversationId(times - 1)
} }
const conversation = await createConversationRsp.json() const conversation = await createConversationRsp.json()
@ -324,7 +324,7 @@ export class BingAIClient {
* refresh_token: string * refresh_token: string
* }>} * }>}
*/ */
async doRefreshToken (clientId, scope, refreshToken, oid) { async doRefreshToken (clientId = this.clientId, scope = this.scope, refreshToken = this.refreshToken, oid = this.oid) {
const myHeaders = new Headers() const myHeaders = new Headers()
myHeaders.append('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0') myHeaders.append('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0')
myHeaders.append('priority', 'u=1, i') myHeaders.append('priority', 'u=1, i')

View file

@ -15,7 +15,7 @@ export function filterResponseChunk (msg) {
if (msg.trim() === '<EMPTY>') { if (msg.trim() === '<EMPTY>') {
return false return false
} }
msg = trimSpecific(msg, '<EMPTY') msg = trimSpecific(msg, '<EMPTY>')
return msg return msg
} }