Ensure all possible time triggers are included

This commit is contained in:
DevilXD committed 2022-12-19 08:50:10 +01:00
1 parent 41430b5027
commit d100c4b7ff
2 files changed
+11 -2

No files matched your search

+10
View File
@@ -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
+1 -2
View File
@@ -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