Account for game being none

This commit is contained in:
DevilXD
2021-12-10 15:33:24 +01:00
parent 97521c11e9
commit 99e1ce0fcc
2 changed files with 13 additions and 5 deletions

View File

@@ -29,7 +29,11 @@ class Stream:
self.viewer_count = stream["viewersCount"]
self.drops_enabled = any(tag["id"] == DROPS_ENABLED_TAG for tag in stream["tags"])
settings = data["broadcastSettings"]
self.game: Game = Game(settings["game"])
self.game: Optional[Game]
if settings["game"] is not None:
self.game = Game(settings["game"])
else:
self.game = None
self.title = settings["title"]
self._timestamp = datetime.now(timezone.utc)

View File

@@ -161,8 +161,9 @@ class Twitch:
for channel in self.channels.values():
if (
channel.stream is not None # steam online
and channel.stream.game is not None # there's game information
and channel.stream.drops_enabled # drops are enabled
and channel.stream.game in games # streams a game we can earn drops in
and channel.stream.game in games # it's a game we can earn drops in
):
self.watch(channel)
refresh_channels = True
@@ -204,10 +205,13 @@ class Twitch:
await self.claim_points(channel_data["id"], claim_available["id"])
logger.info("Claimed bonus points")
i = (i + 1) % 30
await asyncio.sleep(59)
await asyncio.sleep(58)
game = channel.stream.game.name if channel.stream is not None else "<Unknown>"
print(f"Watching: {channel.name}, game: {game}")
if channel.stream is not None and channel.stream.game is not None:
game_name = channel.stream.game.name
else:
game_name = "<Unknown>"
print(f"Watching: {channel.name}, game: {game_name}")
self._watching_channel = channel
self._watching_task = asyncio.create_task(watcher(channel))