This commit is contained in:
2026-07-23 03:03:14 +02:00
parent ef1c914e23
commit ad1736ebf1
47 changed files with 451 additions and 158 deletions
+12 -9
View File
@@ -87,25 +87,28 @@ class BotAuthMixin:
self._log(f"Signup failed, retrying as {self.state.username}")
return False
async def _fetch_account_api_key(self) -> str:
async def _fetch_own_profile(self) -> dict:
if not self.state.username:
return ""
return {}
try:
key = await self.b.page.evaluate(
data = await self.b.page.evaluate(
"""async (username) => {
const resp = await fetch(`/profile/${username}`, {
headers: {Accept: 'application/json'},
});
if (!resp.ok) return '';
const data = await resp.json();
return data.api_key || '';
if (!resp.ok) return null;
return await resp.json();
}""",
self.state.username,
)
except Exception as e:
logger.debug("fetch account api key failed: %s", e)
return ""
return (key or "").strip()
logger.debug("fetch own profile failed: %s", e)
return {}
return data if isinstance(data, dict) else {}
async def _fetch_account_api_key(self) -> str:
profile = await self._fetch_own_profile()
return (profile.get("api_key") or "").strip()
async def _adopt_account_api_key(self) -> bool:
for attempt in range(5):