Skip to content

Commit

Permalink
store player.volume + fix the player.paused storage from the previous…
Browse files Browse the repository at this point in the history
… commit

Signed-off-by: Draper <[email protected]>
  • Loading branch information
Drapersniper committed Apr 1, 2022
1 parent 3c089c3 commit e950ca1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion redbot/cogs/audio/apis/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/audio/core/events/lavalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 11 additions & 12 deletions redbot/cogs/audio/core/tasks/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"]

Expand Down
10 changes: 5 additions & 5 deletions redbot/cogs/audio/core/utilities/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e950ca1

Please sign in to comment.