Skip to content

Commit

Permalink
Log AvailableDrops errors, preventing crashes if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilXD committed Feb 18, 2024
1 parent a536dde commit 5dea41a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from utils import invalidate_cache, json_minify, Game
from exceptions import MinerException, RequestException
from constants import GQL_OPERATIONS, ONLINE_DELAY, URLType
from constants import CALL, GQL_OPERATIONS, ONLINE_DELAY, URLType

if TYPE_CHECKING:
from twitch import Twitch
Expand Down Expand Up @@ -259,13 +259,18 @@ async def get_stream(self) -> Stream | None:
if not stream_data["stream"]:
return None
stream = Stream.from_get_stream(self, stream_data)
available_drops: JsonType = await self._twitch.gql_request(
GQL_OPERATIONS["AvailableDrops"].with_variables({"channelID": str(self.id)})
)
stream.drops_enabled = any(
bool(c["timeBasedDrops"])
for c in (available_drops["data"]["channel"]["viewerDropCampaigns"] or [])
)
if not stream.drops_enabled:
try:
available_drops: JsonType = await self._twitch.gql_request(
GQL_OPERATIONS["AvailableDrops"].with_variables({"channelID": str(self.id)})
)
except MinerException:
logger.log(CALL, f"AvailableDrops GQL call failed for channel: {self._login}")
else:
stream.drops_enabled = any(
bool(c["timeBasedDrops"])
for c in (available_drops["data"]["channel"]["viewerDropCampaigns"] or [])
)
return stream

async def update_stream(self, *, trigger_events: bool) -> bool:
Expand Down

0 comments on commit 5dea41a

Please sign in to comment.