Fix a bug with websocket still running after all drops are mined out

This commit is contained in:
DevilXD committed 2021-12-05 18:11:37 +01:00
1 parent 32b62f75a1
commit 2917e3995c
1 file changed
+7 -5
+7 -5
View File
@@ -92,7 +92,6 @@ class Twitch:
• Changing the stream that's being watched if necessary • Changing the stream that's being watched if necessary
""" """
# Start our websocket connection # Start our websocket connection
self.websocket.start()
while True: while True:
# Claim the drops we can # Claim the drops we can
self.inventory = await self.get_inventory() self.inventory = await self.get_inventory()
@@ -114,6 +113,7 @@ class Twitch:
"Application Terminated.\nClose the console window to exit the application.", "Application Terminated.\nClose the console window to exit the application.",
) )
await asyncio.Future() await asyncio.Future()
self.websocket.start()
if not channel_names: if not channel_names:
# get a list of all channels with drops enabled # get a list of all channels with drops enabled
print("Fetching suitable live channels to watch...") print("Fetching suitable live channels to watch...")
@@ -122,8 +122,9 @@ class Twitch:
) )
for game, channels in live_streams.items(): for game, channels in live_streams.items():
for channel in channels: for channel in channels:
self.channels[channel.id] = channel if channel.id not in self.channels:
print(f"Added channel: {channel.name} for game: {game.name}") self.channels[channel.id] = channel
print(f"Added channel: {channel.name} for game: {game.name}")
else: else:
# Fetch information about all channels we're supposed to handle # Fetch information about all channels we're supposed to handle
for channel_name in channel_names: for channel_name in channel_names:
@@ -153,10 +154,11 @@ class Twitch:
) )
if self._campaign_change.is_set(): if self._campaign_change.is_set():
# we need to reevaluate all campaigns # we need to reevaluate all campaigns
# first of all, stop watching
self.stop_watching()
# reconnect the websocket # reconnect the websocket
await self.websocket.close() await self.websocket.close()
self.websocket.start() break # cycle the outer loop
break # cycles the outer loop
# otherwise, it was the channel change one # otherwise, it was the channel change one
for channel in self.channels.values(): for channel in self.channels.values():
if ( if (