From 651d73a3420981b6a9916f79704407799c327cb4 Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Sun, 15 Dec 2024 12:03:12 +0100 Subject: [PATCH] Fix an issue with the miner not switching to a channel in a particular case; The case involves an ONLINE channel, that stays ONLINE, but had it's tags and status updated from non-watchable to watchable --- twitch.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/twitch.py b/twitch.py index 0944999c..6d5003db 100644 --- a/twitch.py +++ b/twitch.py @@ -1102,10 +1102,8 @@ def on_channel_update( if stream_before is None: if stream_after is not None: # Channel going ONLINE - if ( - self.can_watch(channel) # we can watch the channel - and self.should_switch(channel) # and we should! - ): + if self.can_watch(channel) and self.should_switch(channel): + # we can watch the channel, and we should self.print(_("status", "goes_online").format(channel=channel.name)) self.watch(channel) else: @@ -1115,33 +1113,38 @@ def on_channel_update( logger.log(CALL, f"{channel.name} stays OFFLINE") else: watching_channel = self.watching_channel.get_with_default(None) - if ( - watching_channel is not None - and watching_channel == channel # the watching channel was the one updated - and not self.can_watch(channel) # we can't watch it anymore - ): + # check if the watching channel was the one updated + if watching_channel is not None and watching_channel == channel: # NOTE: In these cases, channel was the watching channel - if stream_after is None: - # Channel going OFFLINE - self.print(_("status", "goes_offline").format(channel=channel.name)) + if not self.can_watch(channel): + # we can't watch it anymore + if stream_after is None: + # Channel going OFFLINE + self.print(_("status", "goes_offline").format(channel=channel.name)) + else: + # Channel stays ONLINE, but we can't watch it anymore + logger.info( + f"{channel.name} status has been updated, switching... " + f"(🎁: {stream_before.drops_enabled and '✔' or '❌'} -> " + f"{stream_after.drops_enabled and '✔' or '❌'})" + ) + self.change_state(State.CHANNEL_SWITCH) else: - # Channel stays ONLINE, but we can't watch it anymore - logger.info( - f"{channel.name} status has been updated, switching... " - f"(🎁: {stream_before.drops_enabled and '✔' or '❌'} -> " - f"{stream_after.drops_enabled and '✔' or '❌'})" - ) - self.change_state(State.CHANNEL_SWITCH) + # Channel stays ONLINE, and we can still watch it - no change + pass # NOTE: In these cases, it wasn't the watching channel elif stream_after is None: logger.info(f"{channel.name} goes OFFLINE") else: - # Channel is and stays ONLINE, but has been updated + # Channel stays ONLINE, but has been updated logger.info( f"{channel.name} status has been updated " f"(🎁: {stream_before.drops_enabled and '✔' or '❌'} -> " f"{stream_after.drops_enabled and '✔' or '❌'})" ) + if self.can_watch(channel) and self.should_switch(channel): + # ... and we can and should watch it + self.watch(channel) channel.display() @task_wrapper