diff --git a/client/CopilotAIClient.js b/client/CopilotAIClient.js index eb43740..8295353 100644 --- a/client/CopilotAIClient.js +++ b/client/CopilotAIClient.js @@ -1,4 +1,5 @@ import WebSocket from 'ws' +import crypto from 'crypto' import common from '../../../lib/common/common.js' import _ from 'lodash' import { pTimeout } from '../utils/common.js' @@ -271,19 +272,27 @@ export class BingAIClient { throw new Error('max retry exceed, maybe refresh token error') } const url = `${this.baseUrl}/c/api/conversations` + const headers = { + // authorization: `Bearer ${this.accessToken}`, + 'content-type': 'application/json', + origin: 'https://copilot.microsoft.com', + referer: 'https://copilot.microsoft.com/', + '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' + } + if (this.accessToken) { + headers.authorization = `Bearer ${this.accessToken}` + } const createConversationRsp = await fetch(url, { - headers: { - authorization: `Bearer ${this.accessToken}`, - 'content-type': 'application/json', - origin: 'https://copilot.microsoft.com', - referer: 'https://copilot.microsoft.com/', - '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' - }, + headers, method: 'POST' }) if (createConversationRsp.status === 401) { - await this.doRefreshToken() - return await this._generateConversationId(times - 1) + if (this.refreshToken) { + await this.doRefreshToken() + return await this._generateConversationId(times - 1) + } else { + this.accessToken = null + } } const conversation = await createConversationRsp.json() return conversation.id diff --git a/utils/chat.js b/utils/chat.js index ae2a206..28a2187 100644 --- a/utils/chat.js +++ b/utils/chat.js @@ -5,7 +5,7 @@ export async function getChatHistoryGroup (e, num) { // if (e.adapter === 'shamrock') { // return await e.group.getChatHistory(0, num, false) // } else { - let latestChats = await e.group.getChatHistory(0, 1) + let latestChats = await e.group.getChatHistory(e.seq || e.message_id, 1) if (latestChats.length > 0) { let latestChat = latestChats[0] if (latestChat) { diff --git a/utils/wordcloud/tokenizer.js b/utils/wordcloud/tokenizer.js index 17a19eb..e077955 100644 --- a/utils/wordcloud/tokenizer.js +++ b/utils/wordcloud/tokenizer.js @@ -8,7 +8,7 @@ class Tokenizer { throw new Error('no valid group id') } let group = e.bot.pickGroup(groupId, true) - let latestChat = await group.getChatHistory(0, 1) + let latestChat = await group.getChatHistory(undefined, 1) let seq = latestChat[0].seq let chats = latestChat function compareByTime (a, b) {