diff --git a/apps/bym.js b/apps/bym.js index df3f407..12243a9 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -1,23 +1,6 @@ -import { CustomGoogleGeminiClient } from '../client/CustomGoogleGeminiClient.js' import { Config } from '../utils/config.js' -import { getImg } from '../utils/common.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 { 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 core from '../model/core.js' diff --git a/apps/management.js b/apps/management.js index 072248f..9e26148 100644 --- a/apps/management.js +++ b/apps/management.js @@ -24,6 +24,7 @@ import { supportConfigurations as azureRoleList } from '../utils/tts/microsoft-a import fetch from 'node-fetch' import { newFetch } from '../utils/proxy.js' import { createServer, runServer, stopServer } from '../server/index.js' +import { BingAIClient } from '../client/CopilotAIClient.js' export class ChatgptManagement extends plugin { constructor (e) { @@ -362,6 +363,15 @@ export class ChatgptManagement extends plugin { reg: '^#(chatgpt)?(Copilot|Bing|必应)配置方法', fnc: 'copilotSetting' } + ], + task: [ + { + cron: '0 */2 * * * ?', + // cron: '*/1 * * * *', + name: 'refreshBingAi', + fnc: 'refreshBingAi', + log: false + } ] }) this.reply = async (msg, quote, data) => { @@ -1848,7 +1858,6 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, } } - async switchBYM (e) { if (e.msg.includes('开启')) { if (Config.enableBYM) { @@ -1916,4 +1925,15 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务, 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') + } + } + } } diff --git a/client/CopilotAIClient.js b/client/CopilotAIClient.js index 4db9d60..eb43740 100644 --- a/client/CopilotAIClient.js +++ b/client/CopilotAIClient.js @@ -2,7 +2,7 @@ import WebSocket from 'ws' import common from '../../../lib/common/common.js' import _ from 'lodash' import { pTimeout } from '../utils/common.js' -import {Config} from '../utils/config.js' +import { Config } from '../utils/config.js' export class BingAIClient { 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) { 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' }) if (createConversationRsp.status === 401) { - await this.doRefreshToken(this.clientId, this.scope, this.refreshToken, this.oid) + await this.doRefreshToken() return await this._generateConversationId(times - 1) } const conversation = await createConversationRsp.json() @@ -324,7 +324,7 @@ export class BingAIClient { * 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() 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') diff --git a/utils/text.js b/utils/text.js index ab8ba11..a617e1d 100644 --- a/utils/text.js +++ b/utils/text.js @@ -15,7 +15,7 @@ export function filterResponseChunk (msg) { if (msg.trim() === '') { return false } - msg = trimSpecific(msg, '') return msg }