diff --git a/redbot/cogs/audio/apis/interface.py b/redbot/cogs/audio/apis/interface.py index bf3f6f8328b7..877387515c64 100644 --- a/redbot/cogs/audio/apis/interface.py +++ b/redbot/cogs/audio/apis/interface.py @@ -1005,7 +1005,7 @@ async def autoplay(self, player: lavalink.Player, playlist_api: PlaylistWrapper) await self.config.guild_from_id( guild_id=player.guild.id ).currently_auto_playing_in.set( - [notify_channel_id, player.channel.id, player.paused] + [notify_channel_id, player.channel.id, player.paused, player.volume] ) else: await self.config.guild_from_id( diff --git a/redbot/cogs/audio/core/events/lavalink.py b/redbot/cogs/audio/core/events/lavalink.py index 775e0f0f2570..44aec35b163e 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, player.paused] + [notify_channel, player.channel.id, player.paused, player.volume] ) 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 dd4af240ef99..9611e3682267 100644 --- a/redbot/cogs/audio/core/tasks/startup.py +++ b/redbot/cogs/audio/core/tasks/startup.py @@ -90,18 +90,20 @@ 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]], Optional[bool]] = {} + metadata: Dict[int, Tuple[int, int, bool, int]] = {} 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, paused = guild_data["currently_auto_playing_in"] - metadata[guild_id] = (notify_channel, vc_id, paused) + notify_channel, vc_id, paused, volume = guild_data["currently_auto_playing_in"] + metadata[guild_id] = (notify_channel, vc_id, paused, volume) if guild_data["last_known_vc_and_notify_channels"]: - notify_channel, vc_id, paused = guild_data["last_known_vc_and_notify_channels"] + notify_channel, vc_id, paused, volume = guild_data[ + "last_known_vc_and_notify_channels" + ] if vc_id: - metadata[guild_id] = (notify_channel, vc_id, paused) + metadata[guild_id] = (notify_channel, vc_id, paused, volume) if guild_data["last_known_track"]: guild = self.bot.get_guild(guild_id) if not guild: @@ -142,16 +144,14 @@ async def restore_players(self) -> None: vc = 0 shuffle = all_guilds[guild.id]["shuffle"] repeat = all_guilds[guild.id]["repeat"] - volume = all_guilds[guild.id]["volume"] shuffle_bumped = all_guilds[guild.id]["shuffle_bumped"] auto_deafen = all_guilds[guild.id]["auto_deafen"] - paused = False + notify_channel_id, vc_id, paused, volume = metadata.pop( + guild_id, (None, track_data[-1].room_id, False, all_guilds[guild.id]["volume"]) + ) if player is None: while tries < 5 and vc is not None: try: - notify_channel_id, vc_id, paused = metadata.pop( - guild_id, (None, track_data[-1].room_id) - ) vc = guild.get_channel(vc_id) if not vc: break @@ -220,7 +220,7 @@ async def restore_players(self) -> None: 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, paused) in metadata.items(): + for guild_id, (notify_channel_id, vc_id, paused, volume) in metadata.items(): guild = self.bot.get_guild(guild_id) player: Optional[lavalink.Player] = None vc = 0 @@ -237,7 +237,6 @@ async def restore_players(self) -> None: if player is None: shuffle = all_guilds[guild.id]["shuffle"] repeat = all_guilds[guild.id]["repeat"] - volume = all_guilds[guild.id]["volume"] shuffle_bumped = all_guilds[guild.id]["shuffle_bumped"] auto_deafen = all_guilds[guild.id]["auto_deafen"] diff --git a/redbot/cogs/audio/core/utilities/player.py b/redbot/cogs/audio/core/utilities/player.py index c43cd9e1cf79..eb3d660a15a6 100644 --- a/redbot/cogs/audio/core/utilities/player.py +++ b/redbot/cogs/audio/core/utilities/player.py @@ -42,12 +42,12 @@ async def save_player_state(self) -> None: if guild_id: last_known_vc_and_notify_channels = ( "last_known_vc_and_notify_channels", - [notify_channel, vc_id], + [notify_channel, vc_id, player.paused, player.volume], ) - if player.current: - data = self.get_track_json(player, position="np") - data["info"]["timestamp"] = player.position - last_known_track = ("last_known_track", data, player.paused) + if player.current: + data = self.get_track_json(player, position="np") + data["info"]["timestamp"] = player.position + last_known_track = ("last_known_track", data) if last_known_vc_and_notify_channels or last_known_track: guild_data[guild_id] = [] if last_known_vc_and_notify_channels: