Skip to content

Commit

Permalink
remove unnecessary can_earn_within_next_hour()
Browse files Browse the repository at this point in the history
  • Loading branch information
Arne-Weber authored and Windows200000 committed Jun 5, 2024
1 parent a43a622 commit 42a7fa4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 0 additions & 4 deletions inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,3 @@ def can_earn_within(self, stamp: datetime) -> bool:
and self.starts_at < stamp
and any(drop.can_earn_within(stamp) for drop in self.drops)
)

def can_earn_within_next_hour(self):
next_hour = datetime.now(timezone.utc) + timedelta(hours=1)
return self.can_earn_within(next_hour)
9 changes: 6 additions & 3 deletions twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,10 +898,11 @@ async def _run(self):
# NOTE: we use another set so that we can set them online separately
no_acl: set[Game] = set()
acl_channels: OrderedSet[Channel] = OrderedSet()
next_hour = datetime.now(timezone.utc) + timedelta(hours=1)
for campaign in self.inventory:
if (
campaign.game in self.wanted_games
and campaign.can_earn_within_next_hour()
and campaign.can_earn_within(next_hour)
):
if campaign.allowed_channels:
acl_channels.update(campaign.allowed_channels)
Expand Down Expand Up @@ -1623,13 +1624,14 @@ def filter_campaigns(self, campaign: list[DropsCampaign]):
priority = self.settings.priority
priority_only = self.settings.priority_only
game = campaign.game
next_hour = datetime.now(timezone.utc) + timedelta(hours=1)
if (
game not in self.wanted_games # isn't already there
and game.name not in exclude # and isn't excluded
# and isn't excluded by priority_only
and (not priority_only or game.name in priority)
# and can be progressed within the next hour
and campaign.can_earn_within_next_hour()
and campaign.can_earn_within(next_hour)
):
return True
return False
Expand Down Expand Up @@ -1680,12 +1682,13 @@ async def fetch_inventory(self) -> None:
self.gui.inv.clear()
self.inventory.clear()
switch_triggers: set[datetime] = set()
next_hour = datetime.now(timezone.utc) + timedelta(hours=1)
for i, campaign in enumerate(campaigns, start=1):
status_update(
_("gui", "status", "adding_campaigns").format(counter=f"({i}/{len(campaigns)})")
)
self._drops.update({drop.id: drop for drop in campaign.drops})
if campaign.can_earn_within_next_hour():
if campaign.can_earn_within(next_hour):
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)
Expand Down

0 comments on commit 42a7fa4

Please sign in to comment.