Fix cleanup cleaning up priority channels

This commit is contained in:
DevilXD committed 2022-01-28 16:43:35 +01:00
1 parent bad1596324
commit 61a3d6560c
1 file changed
+15 -6
+15 -6
View File
@@ -166,6 +166,7 @@ class Twitch:
WebsocketTopic("User", "CommunityPoints", self._user_id, self.process_points), WebsocketTopic("User", "CommunityPoints", self._user_id, self.process_points),
]) ])
games: List[Game] = [] games: List[Game] = []
full_cleanup: bool = False
self.change_state(State.INVENTORY_FETCH) self.change_state(State.INVENTORY_FETCH)
while True: while True:
if self._state is State.IDLE: if self._state is State.IDLE:
@@ -206,22 +207,30 @@ class Twitch:
active_drop = self.get_active_drop() active_drop = self.get_active_drop()
if active_drop is not None: if active_drop is not None:
active_drop.display(countdown=False) active_drop.display(countdown=False)
# restart the watch loop if needed
self.restart_watching() self.restart_watching()
# signal channel cleanup that we're removing everything
full_cleanup = True
self.change_state(State.CHANNELS_CLEANUP) self.change_state(State.CHANNELS_CLEANUP)
elif self._state is State.CHANNELS_CLEANUP: elif self._state is State.CHANNELS_CLEANUP:
if self.game is None: if self.game is None or full_cleanup:
# remove everything # no game selected or we're doing full cleanup: remove everything
to_remove: List[Channel] = list(self.channels.values()) to_remove: List[Channel] = list(self.channels.values())
else: else:
# remove all channels that: # remove all channels that:
to_remove = [ to_remove = [
channel channel
for channel in self.channels.values() for channel in self.channels.values()
if channel.offline # are offline if (
or not channel.priority # aren't prioritized not channel.priority # aren't prioritized
# aren't streaming the game we want anymore and (
or channel.game is None or channel.game != self.game 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( self.websocket.remove_topics(
WebsocketTopic.as_str("Channel", "VideoPlayback", channel.id) WebsocketTopic.as_str("Channel", "VideoPlayback", channel.id)
for channel in to_remove for channel in to_remove