Don't let the active drop search straight up lie to the user

This commit is contained in:
DevilXD committed 2022-11-15 21:40:24 +01:00
1 parent 008dffb212
commit 6f3da7b0cc
1 file changed
+14 -13
+14 -13
View File
@@ -1074,23 +1074,24 @@ class Twitch:
self.inventory.append(campaign) self.inventory.append(campaign)
def get_active_drop(self, channel: Channel | None = None) -> TimedDrop | None: def get_active_drop(self, channel: Channel | None = None) -> TimedDrop | None:
if not self.games: if not self.wanted_games:
return None return None
watching_channel = self.watching_channel.get_with_default(channel) watching_channel = self.watching_channel.get_with_default(channel)
if watching_channel is None:
# if we aren't watching anything, we can't earn any drops
return None
watching_game: Game | None = watching_channel.game
if watching_game is None:
# if the channel isn't playing anything in particular, we can't determine the drop
return None
drops: list[TimedDrop] = [] drops: list[TimedDrop] = []
strict_drops: list[TimedDrop] = []
game: Game | None = watching_channel is not None and watching_channel.game or None
for campaign in self.inventory: for campaign in self.inventory:
if campaign.game in self.games and campaign.can_earn(watching_channel): if (
new_drops = [drop for drop in campaign.drops if drop.can_earn(watching_channel)] campaign.game == watching_game # campaign's game matches watching game
drops.extend(new_drops) and campaign.can_earn(watching_channel) # can be earned on this channel
# 'strict_drops' has an additional condition - watching channel game must match ):
# the campaign's game. If this list would end up empty, # add only the drops we can actually earn
# we use 'drops' as a fallback without this extra condition. drops.extend(drop for drop in campaign.drops if drop.can_earn(watching_channel))
if game is not None and campaign.game == game:
strict_drops.extend(new_drops)
if strict_drops:
drops = strict_drops
if drops: if drops:
drops.sort(key=lambda d: d.remaining_minutes) drops.sort(key=lambda d: d.remaining_minutes)
return drops[0] return drops[0]