diff --git a/src/europython_discord/programme_notifications/cog.py b/src/europython_discord/programme_notifications/cog.py index cc9160c..12135f4 100644 --- a/src/europython_discord/programme_notifications/cog.py +++ b/src/europython_discord/programme_notifications/cog.py @@ -40,10 +40,30 @@ async def on_ready(self) -> None: await self.purge_all_room_channels() _logger.debug(f"Simulated start time: {self.config.simulated_start_time}") _logger.debug(f"Fast mode: {self.config.fast_mode}") + _logger.info("Posting livestream URLs for all rooms...") + await self.post_all_livestream_urls() _logger.info("Starting the session notifier...") self.notify_sessions.start() _logger.info("Cog 'Programme Notifications' is ready") + async def post_all_livestream_urls(self) -> None: + if self.livestream_connector.livestreams_by_room is None: + await self.livestream_connector.fetch_livestreams() + + for room_name in self.config.rooms_to_channel_names: + room_channel = self._get_room_channel(room_name) + if room_channel is None: + continue + + urls_by_date = self.livestream_connector.livestreams_by_room.get(room_name) + if not urls_by_date: + continue + + topic = "\n".join( + f"Stream {day.strftime('%A')}: {url}" for day, url in sorted(urls_by_date.items()) + ) + await room_channel.edit(topic=topic) + async def cog_load(self) -> None: """Start schedule updater task.""" _logger.info( @@ -105,11 +125,8 @@ async def notify_sessions(self) -> None: # send session notification message to room and main channel await main_notification_channel.send(embed=embed) - # update room's livestream URL + # send session notification message to room if room_channel is not None: - await room_channel.edit( - topic=f"Livestream: [YouTube]({livestream_url})" if livestream_url else "" - ) await room_channel.send( content=f"# Starting in 5 minutes @ {session.rooms[0]}", embed=embed,