From d100c4b7ff05d6bc53a1dfdb14b4d8b345c0e3e7 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Mon, 19 Dec 2022 08:50:10 +0100 Subject: [PATCH] Ensure all possible time triggers are included --- inventory.py | 10 ++++++++++ twitch.py | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/inventory.py b/inventory.py index 5976daf..40d3544 100644 --- a/inventory.py +++ b/inventory.py @@ -1,6 +1,7 @@ from __future__ import annotations import re +from itertools import chain from typing import TYPE_CHECKING from functools import cached_property from datetime import datetime, timezone @@ -246,6 +247,15 @@ class DropsCampaign: def drops(self) -> abc.Iterable[TimedDrop]: return self.timed_drops.values() + @property + def time_triggers(self) -> set[datetime]: + return set( + chain( + (self.starts_at, self.ends_at), + *((d.starts_at, d.ends_at) for d in self.timed_drops.values()), + ) + ) + @property def active(self) -> bool: return self.starts_at <= datetime.now(timezone.utc) < self.ends_at diff --git a/twitch.py b/twitch.py index bdaf7d7..b4d9cea 100644 --- a/twitch.py +++ b/twitch.py @@ -1554,8 +1554,7 @@ class Twitch: ) self._drops.update({drop.id: drop for drop in campaign.drops}) if campaign.can_earn_within(next_hour): - switch_triggers.add(campaign.starts_at) - switch_triggers.add(campaign.ends_at) + switch_triggers.update(campaign.time_triggers) # NOTE: this fetches pictures from the CDN, so might be slow without a cache await self.gui.inv.add_campaign(campaign) # this is needed here explicitly, because images aren't always fetched