diff --git a/redbot/cogs/audio/apis/interface.py b/redbot/cogs/audio/apis/interface.py index 636cece656f0..bf3f6f8328b7 100644 --- a/redbot/cogs/audio/apis/interface.py +++ b/redbot/cogs/audio/apis/interface.py @@ -1004,7 +1004,9 @@ async def autoplay(self, player: lavalink.Player, playlist_api: PlaylistWrapper) if notify_channel_id: await self.config.guild_from_id( guild_id=player.guild.id - ).currently_auto_playing_in.set([notify_channel_id, player.channel.id]) + ).currently_auto_playing_in.set( + [notify_channel_id, player.channel.id, player.paused] + ) else: await self.config.guild_from_id( guild_id=player.guild.id diff --git a/redbot/cogs/audio/core/events/lavalink.py b/redbot/cogs/audio/core/events/lavalink.py index 4dd4b4b5430f..775e0f0f2570 100644 --- a/redbot/cogs/audio/core/events/lavalink.py +++ b/redbot/cogs/audio/core/events/lavalink.py @@ -143,7 +143,7 @@ async def lavalink_event_handler( notify_channel = player.fetch("notify_channel") if notify_channel and autoplay: await self.config.guild_from_id(guild_id=guild_id).currently_auto_playing_in.set( - [notify_channel, player.channel.id] + [notify_channel, player.channel.id, player.paused] ) else: await self.config.guild_from_id(guild_id=guild_id).currently_auto_playing_in.set( diff --git a/redbot/cogs/audio/core/tasks/startup.py b/redbot/cogs/audio/core/tasks/startup.py index 12ac357dc5a9..dd4af240ef99 100644 --- a/redbot/cogs/audio/core/tasks/startup.py +++ b/redbot/cogs/audio/core/tasks/startup.py @@ -90,18 +90,18 @@ async def restore_players(self) -> None: ) log.warning("Audio will attempt queue restore on next restart.") return - metadata: Dict[int, Tuple[Optional[int], Optional[int]]] = {} + metadata: Dict[int, Tuple[Optional[int], Optional[int]], Optional[bool]] = {} current_track_meta: Dict[int, lavalink.Track] = {} all_guilds = await self.config.all_guilds() async for guild_id, guild_data in AsyncIter(all_guilds.items(), steps=100): if guild_data["auto_play"]: if guild_data["currently_auto_playing_in"]: - notify_channel, vc_id = guild_data["currently_auto_playing_in"] - metadata[guild_id] = (notify_channel, vc_id) + notify_channel, vc_id, paused = guild_data["currently_auto_playing_in"] + metadata[guild_id] = (notify_channel, vc_id, paused) if guild_data["last_known_vc_and_notify_channels"]: - notify_channel, vc_id = guild_data["last_known_vc_and_notify_channels"] + notify_channel, vc_id, paused = guild_data["last_known_vc_and_notify_channels"] if vc_id: - metadata[guild_id] = (notify_channel, vc_id) + metadata[guild_id] = (notify_channel, vc_id, paused) if guild_data["last_known_track"]: guild = self.bot.get_guild(guild_id) if not guild: @@ -145,11 +145,11 @@ async def restore_players(self) -> None: volume = all_guilds[guild.id]["volume"] shuffle_bumped = all_guilds[guild.id]["shuffle_bumped"] auto_deafen = all_guilds[guild.id]["auto_deafen"] - + paused = False if player is None: while tries < 5 and vc is not None: try: - notify_channel_id, vc_id = metadata.pop( + notify_channel_id, vc_id, paused = metadata.pop( guild_id, (None, track_data[-1].room_id) ) vc = guild.get_channel(vc_id) @@ -199,6 +199,7 @@ async def restore_players(self) -> None: player.repeat = repeat player.shuffle = shuffle player.shuffle_bumped = shuffle_bumped + player._paused = paused if player.volume != volume: await player.set_volume(volume) if player.guild.id in current_track_meta: @@ -206,19 +207,20 @@ async def restore_players(self) -> None: await player.resume( current_track_meta[player.guild.id], start=current_track_meta[player.guild.id].start_timestamp, + pause=paused, ) for track in track_data: track = track.track_object player.add(guild.get_member(track.extras.get("requester")) or guild.me, track) player.maybe_shuffle() - if not player.is_playing: + if not player.is_playing and not player.paused: await player.play() log.debug("Restored %r", player) except Exception as exc: log.debug("Error restoring player in %s", guild_id, exc_info=exc) await self.api_interface.persistent_queue_api.drop(guild_id) - for guild_id, (notify_channel_id, vc_id) in metadata.items(): + for guild_id, (notify_channel_id, vc_id, paused) in metadata.items(): guild = self.bot.get_guild(guild_id) player: Optional[lavalink.Player] = None vc = 0 @@ -284,6 +286,7 @@ async def restore_players(self) -> None: player.repeat = repeat player.shuffle = shuffle player.shuffle_bumped = shuffle_bumped + player._paused = paused if player.volume != volume: await player.set_volume(volume) player.maybe_shuffle() @@ -293,8 +296,9 @@ async def restore_players(self) -> None: await player.resume( current_track_meta[player.guild.id], start=current_track_meta[player.guild.id].start_timestamp, + pause=paused, ) - elif not player.is_playing: + elif not player.is_playing and not player.paused: notify_channel = player.fetch("notify_channel") try: await self.api_interface.autoplay(player, self.playlist_api) diff --git a/redbot/cogs/audio/core/utilities/player.py b/redbot/cogs/audio/core/utilities/player.py index aac4f107e253..c43cd9e1cf79 100644 --- a/redbot/cogs/audio/core/utilities/player.py +++ b/redbot/cogs/audio/core/utilities/player.py @@ -47,7 +47,7 @@ async def save_player_state(self) -> None: if player.current: data = self.get_track_json(player, position="np") data["info"]["timestamp"] = player.position - last_known_track = ("last_known_track", data) + last_known_track = ("last_known_track", data, player.paused) if last_known_vc_and_notify_channels or last_known_track: guild_data[guild_id] = [] if last_known_vc_and_notify_channels: