From 6b30f93f71d9f8fafab69ef296bab3ddba5c003c Mon Sep 17 00:00:00 2001 From: DevilXD Date: Wed, 12 Jan 2022 11:36:36 +0100 Subject: [PATCH] Implement dynamic campaign status --- inventory.py | 13 ++++++++++--- twitch.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/inventory.py b/inventory.py index 543e6d0..b100e90 100644 --- a/inventory.py +++ b/inventory.py @@ -52,8 +52,8 @@ class BaseDrop: def can_earn(self) -> bool: return ( self.preconditions # preconditions are met - and self.campaign.active # campaign is active and not self.is_claimed # drop isn't already claimed + and self.campaign.active # campaign is active and self.starts_at <= datetime.utcnow() < self.ends_at # it's within the timeframe ) @@ -136,7 +136,6 @@ class DropsCampaign: self.game: Game = Game(data["game"]) self.starts_at: datetime = datetime.strptime(data["startAt"], "%Y-%m-%dT%H:%M:%SZ") self.ends_at: datetime = datetime.strptime(data["endAt"], "%Y-%m-%dT%H:%M:%SZ") - self.status: str = data["status"] allowed = data["allow"] self.allowed_channels: List[str] = [] if allowed["channels"] is not None: @@ -147,7 +146,15 @@ class DropsCampaign: @property def active(self): - return self.status == "ACTIVE" + return self.starts_at <= datetime.utcnow() < self.ends_at + + @property + def upcoming(self) -> bool: + return datetime.utcnow() < self.starts_at + + @property + def expired(self) -> bool: + return self.ends_at <= datetime.utcnow() @property def total_drops(self) -> int: diff --git a/twitch.py b/twitch.py index 409e5de..8e12d9a 100644 --- a/twitch.py +++ b/twitch.py @@ -210,7 +210,7 @@ class Twitch: await self.fetch_inventory() games.clear() for campaign in self.inventory: - if campaign.status == "UPCOMING": + if campaign.upcoming: # we have no use in processing upcoming campaigns here continue for drop in campaign.timed_drops.values():