diff --git a/channel.py b/channel.py index 81e9a08..33ff4bb 100644 --- a/channel.py +++ b/channel.py @@ -306,6 +306,15 @@ class Channel: raise MinerException("Error while spade_url extraction: step #2") return URLType(match.group(1)) + def _check_drops_enabled(self, available_drops: list[JsonType]) -> bool: + return any( + ( + (campaign := self._twitch._campaigns.get(campaign_data["id"])) is not None + and campaign.can_earn(self) + ) + for campaign_data in available_drops + ) + def external_update(self, channel_data: JsonType, available_drops: list[JsonType]): """ Update stream information based on data provided externally. @@ -317,9 +326,7 @@ class Channel: return stream = Stream.from_get_stream(self, channel_data) if not stream.drops_enabled: - stream.drops_enabled = any( - bool(campaign["timeBasedDrops"]) for campaign in available_drops - ) + stream.drops_enabled = self._check_drops_enabled(available_drops) self._stream = stream async def get_stream(self) -> Stream | None: @@ -344,11 +351,8 @@ class Channel: except MinerException: logger.log(CALL, f"AvailableDrops GQL call failed for channel: {self._login}") else: - stream.drops_enabled = any( - bool(campaign["timeBasedDrops"]) - for campaign in ( - available_drops_campaigns["data"]["channel"]["viewerDropCampaigns"] or [] - ) + stream.drops_enabled = self._check_drops_enabled( + available_drops_campaigns["data"]["channel"]["viewerDropCampaigns"] or [] ) return stream diff --git a/twitch.py b/twitch.py index 174fc0a..dcf013c 100644 --- a/twitch.py +++ b/twitch.py @@ -429,6 +429,7 @@ class Twitch: self.wanted_games: list[Game] = [] self.inventory: list[DropsCampaign] = [] self._drops: dict[str, TimedDrop] = {} + self._campaigns: dict[str, DropsCampaign] = {} self._mnt_triggers: deque[datetime] = deque() # NOTE: GQL is pretty volatile and breaks everything if one runs into their rate limit. # Do not modify the default, safe values. @@ -1464,6 +1465,7 @@ class Twitch: if campaign.can_earn_within(next_hour): switch_triggers.update(campaign.time_triggers) self.inventory.append(campaign) + self._campaigns[campaign.id] = campaign # concurrently add the campaigns into the GUI # NOTE: this fetches pictures from the CDN, so might be slow without a cache status_update(