Skip to content

Commit 310bbea

Browse files
committed
🤷‍♀️Add some crutches to address Tuesday problems
1 parent 5c75447 commit 310bbea

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

src/core/bases/tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def __init__(
6161
super().__init__(coro, seconds, hours, minutes, time, count, reconnect, name)
6262
if wait_for_ready:
6363
self._before_loop = self._wait_for_ready
64+
# Not sure how I feel about it, but it's annoying that it silences `aiohttp.ClientError, asyncio.TimeoutError`
65+
# because valid aiohttp requests raise them as well !
66+
self.clear_exception_types()
6467

6568
async def _wait_for_ready(self, cog: HasBotAttribute) -> None: # *args: Any
6669
await cog.bot.wait_until_ready()

src/core/bot.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
import logging
66
import platform
77
import pprint
8-
9-
# import sys
8+
import sys
109
from dataclasses import dataclass
1110
from typing import TYPE_CHECKING, Any, TypedDict, override
1211

1312
import discord
14-
15-
# import steam
13+
import steam
1614
import twitchio
1715
from twitchio import eventsub
1816
from twitchio.ext import commands
@@ -366,17 +364,20 @@ async def load_tokens(self, _: str | None = None) -> None: # _ is `path`
366364
async def start(self) -> None:
367365
if "modules.public.dota_rp_flow" in self.modules_to_load:
368366
self.dota = Dota2Client(self)
369-
# try:
370-
await asyncio.gather(
371-
super().start(),
372-
self.dota.login(),
373-
)
367+
try:
368+
await asyncio.gather(
369+
super().start(),
370+
self.dota.login(),
371+
)
374372
# A potential workaround for steam login issues
375373
# https://github.com/Gobot1234/steam.py/issues/446
376-
# except steam.errors.NoCMsFound:
377-
# sys.exit(1)
378-
# except steam.errors.LoginError:
379-
# sys.exit(1)
374+
# Not sure if it works :D
375+
except steam.errors.NoCMsFound:
376+
log.warning("🔴 Encountered `steam.errors.NoCMsFound` - restarting. 🔴")
377+
sys.exit(1)
378+
except steam.errors.LoginError:
379+
log.warning("🔴 Encountered `steam.errors.LoginError` - restarting. 🔴")
380+
sys.exit(1)
380381
else:
381382
await super().start()
382383

src/modules/dev/webhook_logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def component_load(self) -> None:
8686
@override
8787
async def component_teardown(self) -> None:
8888
self.logging_worker.stop()
89-
log.warning("Tearing down logger via webhook.")
89+
# log.warning("Tearing down logger via webhook.")
9090
logging.getLogger().removeHandler(self.logs_handler)
9191
del self.logs_handler
9292
await super().component_teardown()

src/utils/dota/dota2client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import asyncio
34
import logging
45
from typing import TYPE_CHECKING, NamedTuple, override
56

@@ -69,9 +70,14 @@ async def close(self) -> None:
6970

7071
@override
7172
async def on_ready(self) -> None:
72-
log.info("Dota 2 Client: Ready - Successfully %s", self.user.name)
73-
await self.wait_until_gc_ready()
74-
log.info("Dota 2 Game Coordinator: Ready")
73+
log.info("Dota 2 Client: Ready %s, now waiting till Game Coordinator is ready;", self.user.name)
74+
try:
75+
async with asyncio.timeout(11 * 60): # 11 minutes
76+
await self.wait_until_gc_ready()
77+
log.info("Dota 2 Game Coordinator: Ready")
78+
except TimeoutError:
79+
log.warning("🔴 Failed to wait for Dota 2 Game Coordinator to get ready - restarting the bot. 🔴")
80+
await asyncio.create_subprocess_shell("sudo systemctl restart irebot")
7581

7682
@override
7783
async def on_user_update(self, before: User, after: User) -> None:

src/utils/dota/web_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def invoke(
4040
for _ in range(max_failures):
4141
async with self.session.get(url) as resp:
4242
# encoding='utf-8' errored out one day
43-
result = await resp.json(loads=orjson.loads, encoding="ISO-8859-1")
43+
result = await resp.json(loads=orjson.loads, content_type=None)
4444
if result:
4545
break
4646
# Valve, why does it return an empty dict `{}` on the very first request for every match...

0 commit comments

Comments
 (0)