mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: 区分token过期和出验证码,避免大量无效过码请求和错误
This commit is contained in:
parent
12a94d8086
commit
e4854e68f5
2 changed files with 34 additions and 24 deletions
30
apps/chat.js
30
apps/chat.js
|
|
@ -1678,19 +1678,29 @@ export class chatgpt extends plugin {
|
|||
} catch (error) {
|
||||
logger.error(error)
|
||||
const message = error?.message || error?.data?.message || error || '出错了'
|
||||
const { maxConv } = error
|
||||
if (message && typeof message === 'string' && message.indexOf('CaptchaChallenge') > -1) {
|
||||
if (bingToken) {
|
||||
await e.reply('出现必应验证码,尝试解决中')
|
||||
try {
|
||||
let captchaResolveResult = await solveCaptchaOneShot(bingToken)
|
||||
if (captchaResolveResult?.success) {
|
||||
await e.reply('验证码已解决')
|
||||
} else {
|
||||
await e.reply('验证码解决失败')
|
||||
if (maxConv > 20) {
|
||||
// maxConv为30说明token有效,可以通过解验证码码服务过码
|
||||
await e.reply('出现必应验证码,尝试解决中')
|
||||
try {
|
||||
let captchaResolveResult = await solveCaptchaOneShot(bingToken)
|
||||
if (captchaResolveResult?.success) {
|
||||
await e.reply('验证码已解决')
|
||||
} else {
|
||||
logger.error(captchaResolveResult)
|
||||
await e.reply('验证码解决失败: ' + captchaResolveResult.error)
|
||||
retry = 0
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
await e.reply('验证码解决失败: ' + err)
|
||||
retry = 0
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
await e.reply('验证码解决失败')
|
||||
} else {
|
||||
// 未登录用户maxConv目前为5或10,出验证码没救
|
||||
logger.warn(`token [${bingToken}] 无效或已过期`)
|
||||
}
|
||||
}
|
||||
} else
|
||||
|
|
|
|||
|
|
@ -18,16 +18,12 @@ if (!globalThis.fetch) {
|
|||
globalThis.Request = Request
|
||||
globalThis.Response = Response
|
||||
}
|
||||
// workaround for ver 7.x and ver 5.x
|
||||
let proxy = HttpsProxyAgent
|
||||
if (typeof proxy !== 'function') {
|
||||
proxy = HttpsProxyAgent.HttpsProxyAgent
|
||||
}
|
||||
|
||||
// async function getWebSocket () {
|
||||
// let WebSocket
|
||||
// try {
|
||||
// WebSocket = (await import('ws')).default
|
||||
// } catch (error) {
|
||||
// throw new Error('ws依赖未安装,请使用pnpm install ws安装')
|
||||
// }
|
||||
// return WebSocket
|
||||
// }
|
||||
async function getKeyv () {
|
||||
let Keyv
|
||||
try {
|
||||
|
|
@ -98,7 +94,7 @@ export default class SydneyAIClient {
|
|||
fetchOptions.headers.cookie = this.opts.cookies || `_U=${this.opts.userToken}`
|
||||
}
|
||||
if (this.opts.proxy) {
|
||||
fetchOptions.agent = HttpsProxyAgent(Config.proxy)
|
||||
fetchOptions.agent = proxy(Config.proxy)
|
||||
}
|
||||
let accessible = !(await isCN()) || this.opts.proxy
|
||||
if (accessible && !Config.sydneyForceUseReverse) {
|
||||
|
|
@ -137,7 +133,7 @@ export default class SydneyAIClient {
|
|||
let agent
|
||||
let sydneyHost = 'wss://sydney.bing.com'
|
||||
if (this.opts.proxy) {
|
||||
agent = new HttpsProxyAgent(this.opts.proxy)
|
||||
agent = proxy(this.opts.proxy)
|
||||
}
|
||||
if (Config.sydneyWebsocketUseProxy) {
|
||||
sydneyHost = Config.sydneyReverseProxy.replace('https://', 'wss://').replace('http://', 'ws://')
|
||||
|
|
@ -365,6 +361,7 @@ export default class SydneyAIClient {
|
|||
if (Config.enableGenerateContents) {
|
||||
optionsSets.push(...['gencontentv3'])
|
||||
}
|
||||
let maxConv = Config.maxNumUserMessagesInConversation
|
||||
const currentDate = moment().format('YYYY-MM-DDTHH:mm:ssZ')
|
||||
const imageDate = await this.kblobImage(opts.imageUrl)
|
||||
// console.log(imageDate)
|
||||
|
|
@ -568,7 +565,8 @@ export default class SydneyAIClient {
|
|||
const messages = event?.arguments?.[0]?.messages
|
||||
if (!messages?.length || messages[0].author !== 'bot') {
|
||||
if (event?.arguments?.[0]?.throttling?.maxNumUserMessagesInConversation) {
|
||||
Config.maxNumUserMessagesInConversation = event?.arguments?.[0]?.throttling?.maxNumUserMessagesInConversation
|
||||
maxConv = event?.arguments?.[0]?.throttling?.maxNumUserMessagesInConversation
|
||||
Config.maxNumUserMessagesInConversation = maxConv
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -762,7 +760,8 @@ export default class SydneyAIClient {
|
|||
conversationExpiryTime,
|
||||
response: reply.text,
|
||||
details: reply,
|
||||
apology: Config.sydneyApologyIgnored && apology
|
||||
apology: Config.sydneyApologyIgnored && apology,
|
||||
maxConv
|
||||
}
|
||||
} catch (err) {
|
||||
await this.conversationsCache.set(conversationKey, conversation)
|
||||
|
|
@ -771,6 +770,7 @@ export default class SydneyAIClient {
|
|||
conversationId,
|
||||
clientId
|
||||
}
|
||||
err.maxConv = maxConv
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
|
@ -797,7 +797,7 @@ export default class SydneyAIClient {
|
|||
body: formData
|
||||
}
|
||||
if (this.opts.proxy) {
|
||||
fetchOptions.agent = HttpsProxyAgent(Config.proxy)
|
||||
fetchOptions.agent = proxy(Config.proxy)
|
||||
}
|
||||
let accessible = !(await isCN()) || this.opts.proxy
|
||||
let response = await fetch(`${accessible ? 'https://www.bing.com' : this.opts.host}/images/kblob`, fetchOptions)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue