Improve on the CALL logging, added useful comments

This commit is contained in:
DevilXD committed 2022-12-14 14:43:02 +01:00
1 parent f9b8d8e9a8
commit 07708e9ab1
2 files changed
+29 -23

No files matched your search

+12 -7
View File
@@ -272,15 +272,20 @@ class Channel:
""" """
await asyncio.sleep(ONLINE_DELAY.total_seconds()) await asyncio.sleep(ONLINE_DELAY.total_seconds())
self._pending_stream_up = None # for 'display' to work properly self._pending_stream_up = None # for 'display' to work properly
await self.update_stream(trigger_events=True) await self.update_stream(trigger_events=True) # triggers 'display' via the event
def set_online(self): def check_online(self):
""" """
Sets the channel status to PENDING_ONLINE, where after ONLINE_DELAY, Sets up a task that will wait ONLINE_DELAY duration,
it's going to be set to ONLINE. and then check for the stream being ONLINE OR OFFLINE.
This is called externally, if we receive an event about this happening. If the channel is OFFLINE, it sets the channel's status to PENDING_ONLINE,
This is also called when an already online channel needs a delayed status update. where after ONLINE_DELAY, it's going to be set to ONLINE.
If the channel is ONLINE already, after ONLINE_DELAY,
it's status is going to be double-checked to ensure it's actually ONLINE.
This is called externally, if we receive an event about the status possibly being ONLINE
or having to be updated.
""" """
if self._pending_stream_up is None: if self._pending_stream_up is None:
self._pending_stream_up = asyncio.create_task(self._online_delay()) self._pending_stream_up = asyncio.create_task(self._online_delay())
@@ -290,7 +295,7 @@ class Channel:
""" """
Sets the channel status to OFFLINE. Cancels PENDING_ONLINE if applicable. Sets the channel status to OFFLINE. Cancels PENDING_ONLINE if applicable.
This is called externally, if we receive an event about this happening. This is called externally, if we receive an event indicating the channel is now OFFLINE.
""" """
needs_display: bool = False needs_display: bool = False
if self._pending_stream_up is not None: if self._pending_stream_up is not None:
+17 -16
View File
@@ -1099,7 +1099,7 @@ class Twitch:
if msg_type == "viewcount": if msg_type == "viewcount":
if not channel.online: if not channel.online:
# if it's not online for some reason, set it so # if it's not online for some reason, set it so
channel.set_online() channel.check_online()
else: else:
viewers = message["viewers"] viewers = message["viewers"]
channel.viewers = viewers channel.viewers = viewers
@@ -1108,7 +1108,7 @@ class Twitch:
elif msg_type == "stream-down": elif msg_type == "stream-down":
channel.set_offline() channel.set_offline()
elif msg_type == "stream-up": elif msg_type == "stream-up":
channel.set_online() channel.check_online()
elif msg_type == "commercial": elif msg_type == "commercial":
# skip these # skip these
pass pass
@@ -1132,22 +1132,16 @@ class Twitch:
if channel is None: if channel is None:
logger.error(f"Broadcast settings update for a non-existing channel: {channel_id}") logger.error(f"Broadcast settings update for a non-existing channel: {channel_id}")
return return
if message["old_status"] != message["status"]:
status_change = f"\n{message['old_status']} -> {message['status']}"
else:
status_change = ''
if message["old_game"] != message["game"]: if message["old_game"] != message["game"]:
game_change = f"\n{message['old_game']} -> {message['game']}" game_change = f", game changed: {message['old_game']} -> {message['game']}"
else: else:
game_change = '' game_change = ''
logger.log( logger.log(CALL, f"Channel update from websocket: {channel.name}{game_change}")
CALL, f"Channel update from websocket: {channel.name}{status_change}{game_change}"
)
# There's no information about channel tags here, but this event is triggered # There's no information about channel tags here, but this event is triggered
# when the tags change. We can use this to just update the stream data after the change. # when the tags change. We can use this to just update the stream data after the change.
# Use 'set_online' to introduce a delay, allowing for multiple title and tags # Use 'set_online' to introduce a delay, allowing for multiple title and tags
# changes before we update. This eventually calls 'on_channel_update' below. # changes before we update. This eventually calls 'on_channel_update' below.
channel.set_online() channel.check_online()
def on_channel_update( def on_channel_update(
self, channel: Channel, stream_before: Stream | None, stream_after: Stream | None self, channel: Channel, stream_before: Stream | None, stream_after: Stream | None
@@ -1173,20 +1167,27 @@ class Twitch:
logger.info(f"{channel.name} goes ONLINE") logger.info(f"{channel.name} goes ONLINE")
else: else:
# Channel was OFFLINE and stays that way # Channel was OFFLINE and stays that way
# Nothing to do here for now logger.log(CALL, f"{channel.name} stays OFFLINE")
return
else: else:
watching_channel = self.watching_channel.get_with_default(None) watching_channel = self.watching_channel.get_with_default(None)
if ( if (
watching_channel is not None watching_channel is not None
and watching_channel == channel and watching_channel == channel # the watching channel was the one updated
and not self.can_watch(channel) and not self.can_watch(channel) # we can't watch it anymore
): ):
# NOTE: In these cases, channel was the watching channel
if stream_after is None: if stream_after is None:
# Channel going OFFLINE # Channel going OFFLINE
self.print(_("status", "goes_offline").format(channel=channel.name)) self.print(_("status", "goes_offline").format(channel=channel.name))
# if the channel stays online, we silently trigger a 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) self.change_state(State.CHANNEL_SWITCH)
# NOTE: In these cases, it wasn't the watching channel
elif stream_after is None: elif stream_after is None:
logger.info(f"{channel.name} goes OFFLINE") logger.info(f"{channel.name} goes OFFLINE")
else: else: