Skip to content

Commit

Permalink
Higher sub tiers first
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed May 7, 2021
1 parent c74f250 commit 9e09b04
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions TwitchChannelPointsMiner/classes/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,16 @@ def send_minute_watched_events(self, streamers, priority, chunk_size=3):
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.
Expand Down Expand Up @@ -393,7 +398,7 @@ def load_channel_points_context(self, streamer):
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"])
Expand Down
19 changes: 17 additions & 2 deletions TwitchChannelPointsMiner/classes/entities/Streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Streamer(object):
"channel_points",
"minute_watched_requests",
"viewer_is_mod",
"viewer_has_points_multiplier",
"activeMultipliers",
"irc_chat",
"stream",
"raid",
Expand All @@ -90,7 +90,7 @@ def __init__(self, username, settings=None):
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()
Expand Down Expand Up @@ -170,6 +170,21 @@ def drops_condition(self):
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()
Expand Down

0 comments on commit 9e09b04

Please sign in to comment.