From 1dc12afe7d3cab3c4932688c0ab8e2a06f15f191 Mon Sep 17 00:00:00 2001 From: Mrlolpro Date: Mon, 12 Dec 2022 20:49:57 +0100 Subject: [PATCH] feat: detect capacity limit --- src/openai-auth-2captcha.ts | 9 +++++---- src/openai-auth.ts | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/openai-auth-2captcha.ts b/src/openai-auth-2captcha.ts index b8e4e5b..a7de038 100644 --- a/src/openai-auth-2captcha.ts +++ b/src/openai-auth-2captcha.ts @@ -67,6 +67,11 @@ export async function getOpenAIAuth2Captcha({ // NOTE: this is where you may encounter a CAPTCHA await page.solveRecaptchas() + var capacityLimit = await page.$('[role="alert"]') + if (capacityLimit) { + throw `ChatGPT is at capacity right now` + } + await page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs }) // once we get to this point, the Cloudflare cookies are available @@ -91,10 +96,6 @@ export async function getOpenAIAuth2Captcha({ waitUntil: 'networkidle0' }) ]) - /*var capacityLimit = await page.$('') - if (capacityLimit) { - throw `ChatGPT is at capacity right now` - }*/ } const pageCookies = await page.cookies() diff --git a/src/openai-auth.ts b/src/openai-auth.ts index 74a2151..faf99af 100644 --- a/src/openai-auth.ts +++ b/src/openai-auth.ts @@ -62,6 +62,10 @@ export async function getOpenAIAuth({ await page.goto('https://chat.openai.com/auth/login') // NOTE: this is where you may encounter a CAPTCHA + var capacityLimit = await page.$('[role="alert"]') + if (capacityLimit) { + throw `ChatGPT is at capacity right now` + } await page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs })