Implement dynamic campaign status

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

View File

@@ -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:

View File

@@ -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():