From 61a3d6560cd13ee7cc0ef04c15a662f76044b3fe Mon Sep 17 00:00:00 2001 From: DevilXD Date: Fri, 28 Jan 2022 16:43:35 +0100 Subject: [PATCH] Fix cleanup cleaning up priority channels --- twitch.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/twitch.py b/twitch.py index 473ab317..76fd8154 100644 --- a/twitch.py +++ b/twitch.py @@ -166,6 +166,7 @@ async def run(self): WebsocketTopic("User", "CommunityPoints", self._user_id, self.process_points), ]) games: List[Game] = [] + full_cleanup: bool = False self.change_state(State.INVENTORY_FETCH) while True: if self._state is State.IDLE: @@ -206,22 +207,30 @@ async def run(self): active_drop = self.get_active_drop() if active_drop is not None: active_drop.display(countdown=False) + # restart the watch loop if needed self.restart_watching() + # signal channel cleanup that we're removing everything + full_cleanup = True self.change_state(State.CHANNELS_CLEANUP) elif self._state is State.CHANNELS_CLEANUP: - if self.game is None: - # remove everything + if self.game is None or full_cleanup: + # no game selected or we're doing full cleanup: remove everything to_remove: List[Channel] = list(self.channels.values()) else: # remove all channels that: to_remove = [ channel for channel in self.channels.values() - if channel.offline # are offline - or not channel.priority # aren't prioritized - # aren't streaming the game we want anymore - or channel.game is None or channel.game != self.game + if ( + not channel.priority # aren't prioritized + and ( + channel.offline # and are offline + # or online but aren't streaming the game we want anymore + or (channel.game is None or channel.game != self.game) + ) + ) ] + full_cleanup = False self.websocket.remove_topics( WebsocketTopic.as_str("Channel", "VideoPlayback", channel.id) for channel in to_remove