From 9e09b0483a4c9d064f72114ad5abfe676bb33dfb Mon Sep 17 00:00:00 2001 From: Thomas Couchoud Date: Fri, 7 May 2021 23:20:23 +0200 Subject: [PATCH] Higher sub tiers first --- README.md | 2 +- TwitchChannelPointsMiner/classes/Twitch.py | 17 +++++++++++------ .../classes/entities/Streamer.py | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9b4fb49..793368c 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,7 @@ You can watch only two streamers per time. With `priority` settings, you can sel Available values are the following: - `STREAK` - Catch the watch streak from all streamers - `DROPS` - Claim all drops from streamers with drops tags enabled - - `SUBSCRIBED` - Prioritize streamers you're subscribed to + - `SUBSCRIBED` - Prioritize streamers you're subscribed to (higher subscription tiers are mined first) - `ORDER` - Following the order of the list - `POINTS_ASCENDING` - On top the streamers with the lowest points - `POINTS_DESCEDING` - On top the streamers with the highest points diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index d9fdd1c..d7ade43 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -315,11 +315,16 @@ class Twitch(object): break elif prior == Priority.SUBSCRIBED and len(streamers_watching) < 2: - for index in streamers_index: - if streamers[index].viewer_has_points_multiplier is True: - streamers_watching.append(index) - if len(streamers_watching) == 2: - break + streamers_with_multiplier = [ + index + for index in streamers_index + if streamers[index].viewer_has_points_multiplier() + ] + streamers_with_multiplier = sorted( + streamers_with_multiplier, + key=lambda x: streamers[x].total_points_multiplier(), + ) + streamers_watching += streamers_with_multiplier[:2] """ Twitch has a limit - you can't watch more than 2 channels at one time. @@ -393,7 +398,7 @@ class Twitch(object): channel = response["data"]["community"]["channel"] community_points = channel["self"]["communityPoints"] streamer.channel_points = community_points["balance"] - streamer.viewer_has_points_multiplier = len(community_points["activeMultipliers"]) > 0 + streamer.activeMultipliers = community_points["activeMultipliers"] if community_points["availableClaim"] is not None: self.claim_bonus(streamer, community_points["availableClaim"]["id"]) diff --git a/TwitchChannelPointsMiner/classes/entities/Streamer.py b/TwitchChannelPointsMiner/classes/entities/Streamer.py index afd8dad..7422e91 100644 --- a/TwitchChannelPointsMiner/classes/entities/Streamer.py +++ b/TwitchChannelPointsMiner/classes/entities/Streamer.py @@ -70,7 +70,7 @@ class Streamer(object): "channel_points", "minute_watched_requests", "viewer_is_mod", - "viewer_has_points_multiplier", + "activeMultipliers", "irc_chat", "stream", "raid", @@ -90,7 +90,7 @@ class Streamer(object): self.channel_points = 0 self.minute_watched_requests = None self.viewer_is_mod = False - self.viewer_has_points_multiplier = False + self.activeMultipliers = None self.irc_chat = None self.stream = Stream() @@ -170,6 +170,21 @@ class Streamer(object): and self.stream.campaigns_ids != [] ) + def viewer_has_points_multiplier(self): + return self.activeMultipliers is not None and len(self.activeMultipliers) > 0 + + def total_points_multiplier(self): + return ( + sum( + map( + lambda x: x["factor"], + self.activeMultipliers, + ), + ) + if self.activeMultipliers is not None + else 0 + ) + # === ANALYTICS === # def persistent_annotations(self, event_type, event_text): event_type = event_type.upper()