From 62a3bc715cf16ee881f66623ff0dea591158b4ed Mon Sep 17 00:00:00 2001 From: DevilXD Date: Fri, 7 Jan 2022 10:46:33 +0100 Subject: [PATCH] Better active drop search --- inventory.py | 9 --------- twitch.py | 13 ++++++------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/inventory.py b/inventory.py index 8585028..ea74ba1 100644 --- a/inventory.py +++ b/inventory.py @@ -155,12 +155,3 @@ class DropsCampaign: def get_drop(self, drop_id: str) -> Optional[TimedDrop]: return self.timed_drops.get(drop_id) - - def get_active_drop(self) -> TimedDrop: - if not self.active: - raise RuntimeError("You can't call this for an unactive campaign") - drops = sorted( - (drop for drop in self.timed_drops.values() if drop.can_earn), - key=lambda d: d.remaining_minutes, - ) - return drops[0] diff --git a/twitch.py b/twitch.py index d4227e8..c3aa095 100644 --- a/twitch.py +++ b/twitch.py @@ -191,12 +191,9 @@ class Twitch: self.gui.games.set_games(games) selected_game = self.gui.games.get_selection() # pre-display the active drop without a countdown - for campaign in self.inventory: - if campaign.active and campaign.game == selected_game: - active_drop = campaign.get_active_drop() - if active_drop is not None: - active_drop.display(countdown=False) - break + active_drop = self.get_active_drop(selected_game) + if active_drop is not None: + active_drop.display(countdown=False) self.change_state(State.CHANNEL_CLEANUP) elif self._state is State.CHANNEL_FETCH: if selected_game is None: @@ -693,9 +690,11 @@ class Twitch: def get_active_drop(self, game: Game) -> Optional[TimedDrop]: drops = sorted( ( - campaign.get_active_drop() + drop for campaign in self.inventory if campaign.active and campaign.game == game + for drop in campaign.timed_drops.values() + if drop.can_earn ), key=lambda d: d.remaining_minutes, )