Implement dynamic campaign status

This commit is contained in:
DevilXD committed 2022-01-12 11:36:36 +01:00
1 parent 9f7c865abb
commit 6b30f93f71
2 files changed
+11 -4

No files matched your search

+10 -3
View File
@@ -52,8 +52,8 @@ class BaseDrop:
def can_earn(self) -> bool: def can_earn(self) -> bool:
return ( return (
self.preconditions # preconditions are met self.preconditions # preconditions are met
and self.campaign.active # campaign is active
and not self.is_claimed # drop isn't already claimed 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 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.game: Game = Game(data["game"])
self.starts_at: datetime = datetime.strptime(data["startAt"], "%Y-%m-%dT%H:%M:%SZ") 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.ends_at: datetime = datetime.strptime(data["endAt"], "%Y-%m-%dT%H:%M:%SZ")
self.status: str = data["status"]
allowed = data["allow"] allowed = data["allow"]
self.allowed_channels: List[str] = [] self.allowed_channels: List[str] = []
if allowed["channels"] is not None: if allowed["channels"] is not None:
@@ -147,7 +146,15 @@ class DropsCampaign:
@property @property
def active(self): 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 @property
def total_drops(self) -> int: def total_drops(self) -> int:
+1 -1
View File
@@ -210,7 +210,7 @@ class Twitch:
await self.fetch_inventory() await self.fetch_inventory()
games.clear() games.clear()
for campaign in self.inventory: for campaign in self.inventory:
if campaign.status == "UPCOMING": if campaign.upcoming:
# we have no use in processing upcoming campaigns here # we have no use in processing upcoming campaigns here
continue continue
for drop in campaign.timed_drops.values(): for drop in campaign.timed_drops.values():