shamhi / TapSwapBot

Bot that mines coins in Tapswap
https://t.me/tapswap_bot
268 stars 92 forks source link

wait_s error #67

Open kunokareal opened 3 months ago

kunokareal commented 3 months ago

since recently sometimes when logging in it randomly returns an object containing wait_s field, in which case an "app is overloaded" screen is shown with a timer.

i'm too lazy to open a proper pr, so here's the gist:

diff --git a/bot/core/tapper.py b/bot/core/tapper.py
index 3e8c258..d8bffa6 100644
--- a/bot/core/tapper.py
+++ b/bot/core/tapper.py
@@ -97,6 +97,12 @@ class Tapper:
             response.raise_for_status()

             response_json = await response.json()
+            wait_s = response_json.get('wait_s')
+            if wait_s:
+                logger.error(f"{self.session_name} | App overloaded, waiting for: {wait_s}")
+                await asyncio.sleep(delay=wait_s)
+                return self.login(http_client, tg_web_data)
+
             chq = response_json.get('chq')
             if chq:
                 chq_result = extract_chq(chq=chq)
NLegal commented 3 months ago

Adjusted a bit:

    async def login(self, http_client: aiohttp.ClientSession, tg_web_data: str) -> tuple[dict[str], str]:
        response_text = ''
        try:
            response = await http_client.post(url='https://api.tapswap.ai/api/account/login',
                                              json={"init_data": tg_web_data, "referrer": ""})
            response_text = await response.text()
            response.raise_for_status()

            response_json = await response.json()

            wait_s = response_json.get('wait_s')
            if wait_s:
                logger.error(f"{self.session_name} | App overloaded, waiting for: {wait_s}")
                await asyncio.sleep(delay=wait_s)
                return await self.login(http_client, tg_web_data)

            chq = response_json.get('chq')
            if chq:
                chq_result = extract_chq(chq=chq)

                response = await http_client.post(url='https://api.tapswap.ai/api/account/login',
                                                json={"chr": chq_result, "init_data": tg_web_data, "referrer": ""})
                response_text = await response.text()
                response.raise_for_status()

                response_json = await response.json()

            access_token = response_json['access_token']
            profile_data = response_json

            return profile_data, access_token
        except Exception as error:
            logger.error(f"{self.session_name} | Unknown error while getting Access Token: {error} | "
                         f"Response text: {escape_html(response_text)[:128]}...")
            await asyncio.sleep(delay=3)