Fix crash in [p]audiostats by using the new connected_at attr (#5046)

* This PR depends on Part 1 due to new `Player.guild` attribute and RLL bump to 0.8.1

- [player.store] notify_channel->channel
- [player.store] removed guild
- [player.store] removed connect
- changes in [p]audiostats

Co-authored-by: alec <50505980+aleclol@users.noreply.github.com>

* another one

* Update redbot/cogs/audio/core/commands/miscellaneous.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* style

Co-authored-by: alec <50505980+aleclol@users.noreply.github.com>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Draper 2021-05-19 16:56:53 +01:00 committed by GitHub
parent 439033ea28
commit 3a9edd9434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 56 additions and 116 deletions

View File

@ -937,7 +937,7 @@ class AudioAPIInterface:
autoplaylist = await self.config.guild(player.guild).autoplaylist() autoplaylist = await self.config.guild(player.guild).autoplaylist()
current_cache_level = CacheLevel(await self.config.cache_level()) current_cache_level = CacheLevel(await self.config.cache_level())
cache_enabled = CacheLevel.set_lavalink().is_subset(current_cache_level) cache_enabled = CacheLevel.set_lavalink().is_subset(current_cache_level)
notify_channel_id = player.fetch("channel") notify_channel_id = player.fetch("notify_channel")
playlist = None playlist = None
tracks = None tracks = None
if autoplaylist["enabled"]: if autoplaylist["enabled"]:

View File

@ -95,8 +95,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
} }
expected = tuple(emoji.values()) expected = tuple(emoji.values())
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if player.current: if player.current:
arrow = await self.draw_time(ctx) arrow = await self.draw_time(ctx)
pos = self.format_time(player.position) pos = self.format_time(player.position)
@ -218,8 +217,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Manage Tracks"), title=_("Unable To Manage Tracks"),
description=_("You need the DJ role to pause or resume tracks."), description=_("You need the DJ role to pause or resume tracks."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if not player.current: if not player.current:
return await self.send_embed_msg(ctx, title=_("Nothing playing.")) return await self.send_embed_msg(ctx, title=_("Nothing playing."))
description = await self.get_track_description( description = await self.get_track_description(
@ -273,8 +271,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
"to enqueue the previous song tracks." "to enqueue the previous song tracks."
), ),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if player.fetch("prev_song") is None: if player.fetch("prev_song") is None:
return await self.send_embed_msg( return await self.send_embed_msg(
ctx, title=_("Unable To Play Tracks"), description=_("No previous track.") ctx, title=_("Unable To Play Tracks"), description=_("No previous track.")
@ -340,8 +337,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Seek Tracks"), title=_("Unable To Seek Tracks"),
description=_("You need the DJ role or be the track requester to use seek."), description=_("You need the DJ role or be the track requester to use seek."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if player.current: if player.current:
if player.current.is_stream: if player.current.is_stream:
return await self.send_embed_msg( return await self.send_embed_msg(
@ -414,8 +410,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Toggle Shuffle"), title=_("Unable To Toggle Shuffle"),
description=_("You must be in the voice channel to toggle shuffle."), description=_("You must be in the voice channel to toggle shuffle."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
shuffle = await self.config.guild(ctx.guild).shuffle() shuffle = await self.config.guild(ctx.guild).shuffle()
await self.config.guild(ctx.guild).shuffle.set(not shuffle) await self.config.guild(ctx.guild).shuffle.set(not shuffle)
@ -459,8 +454,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Toggle Shuffle"), title=_("Unable To Toggle Shuffle"),
description=_("You must be in the voice channel to toggle shuffle."), description=_("You must be in the voice channel to toggle shuffle."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
bumped = await self.config.guild(ctx.guild).shuffle_bumped() bumped = await self.config.guild(ctx.guild).shuffle_bumped()
await self.config.guild(ctx.guild).shuffle_bumped.set(not bumped) await self.config.guild(ctx.guild).shuffle_bumped.set(not bumped)
@ -517,8 +511,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Skip Tracks"), title=_("Unable To Skip Tracks"),
description=_("You can only skip the current track."), description=_("You can only skip the current track."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if vote_enabled: if vote_enabled:
if not can_skip: if not can_skip:
if skip_to_track is not None: if skip_to_track is not None:
@ -597,8 +590,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Stop Player"), title=_("Unable To Stop Player"),
description=_("You need the DJ role to stop the music."), description=_("You need the DJ role to stop the music."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if ( if (
player.is_playing player.is_playing
or (not player.is_playing and player.paused) or (not player.is_playing and player.paused)
@ -662,18 +654,14 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
description=_("I don't have permission to connect to your channel."), description=_("I don't have permission to connect to your channel."),
) )
if not self._player_check(ctx): if not self._player_check(ctx):
await lavalink.connect( player = await lavalink.connect(
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id) player.store("notify_channel", ctx.channel.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
else: else:
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if ( if (
ctx.author.voice.channel == player.channel ctx.author.voice.channel == player.channel
and ctx.guild.me in ctx.author.voice.channel.members and ctx.guild.me in ctx.author.voice.channel.members
@ -724,8 +712,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Change Volume"), title=_("Unable To Change Volume"),
description=_("You must be in the voice channel to change the volume."), description=_("You must be in the voice channel to change the volume."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if dj_enabled and not can_skip and not await self._has_dj_role(ctx, ctx.author): if dj_enabled and not can_skip and not await self._has_dj_role(ctx, ctx.author):
return await self.send_embed_msg( return await self.send_embed_msg(
ctx, ctx,
@ -738,8 +725,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
if self._player_check(ctx): if self._player_check(ctx):
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
await player.set_volume(vol) await player.set_volume(vol)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
embed = discord.Embed(title=_("Volume:"), description=f"{vol}%") embed = discord.Embed(title=_("Volume:"), description=f"{vol}%")
if not self._player_check(ctx): if not self._player_check(ctx):
@ -772,8 +758,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Toggle Repeat"), title=_("Unable To Toggle Repeat"),
description=_("You must be in the voice channel to toggle repeat."), description=_("You must be in the voice channel to toggle repeat."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
autoplay = await self.config.guild(ctx.guild).auto_play() autoplay = await self.config.guild(ctx.guild).auto_play()
repeat = await self.config.guild(ctx.guild).repeat() repeat = await self.config.guild(ctx.guild).repeat()
@ -817,8 +802,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Modify Queue"), title=_("Unable To Modify Queue"),
description=_("You must be in the voice channel to manage the queue."), description=_("You must be in the voice channel to manage the queue."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if isinstance(index_or_url, int): if isinstance(index_or_url, int):
if index_or_url > len(player.queue) or index_or_url < 1: if index_or_url > len(player.queue) or index_or_url < 1:
return await self.send_embed_msg( return await self.send_embed_msg(
@ -899,8 +883,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Bump Track"), title=_("Unable To Bump Track"),
description=_("Song number must be greater than 1 and within the queue limit."), description=_("Song number must be greater than 1 and within the queue limit."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
bump_index = index - 1 bump_index = index - 1
bump_song = player.queue[bump_index] bump_song = player.queue[bump_index]
bump_song.extras["bumped"] = True bump_song.extras["bumped"] = True

View File

@ -173,8 +173,7 @@ class EqualizerCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Load Preset"), title=_("Unable To Load Preset"),
description=_("You need the DJ role to load equalizer presets."), description=_("You need the DJ role to load equalizer presets."),
) )
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq_values) await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq_values)
await self._eq_check(ctx, player) await self._eq_check(ctx, player)
eq = player.fetch("eq", Equalizer()) eq = player.fetch("eq", Equalizer())
@ -203,8 +202,7 @@ class EqualizerCommands(MixinMeta, metaclass=CompositeMetaClass):
description=_("You need the DJ role to reset the equalizer."), description=_("You need the DJ role to reset the equalizer."),
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
eq = player.fetch("eq", Equalizer()) eq = player.fetch("eq", Equalizer())
for band in range(eq.band_count): for band in range(eq.band_count):
@ -287,8 +285,7 @@ class EqualizerCommands(MixinMeta, metaclass=CompositeMetaClass):
return await eq_exists_msg.edit(embed=embed2) return await eq_exists_msg.edit(embed=embed2)
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
eq = player.fetch("eq", Equalizer()) eq = player.fetch("eq", Equalizer())
to_append = {eq_preset: {"author": ctx.author.id, "bands": eq.bands}} to_append = {eq_preset: {"author": ctx.author.id, "bands": eq.bands}}
new_eq_presets = {**eq_presets, **to_append} new_eq_presets = {**eq_presets, **to_append}
@ -330,8 +327,7 @@ class EqualizerCommands(MixinMeta, metaclass=CompositeMetaClass):
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
band_names = [ band_names = [
"25", "25",
"40", "40",

View File

@ -45,13 +45,19 @@ class MiscellaneousCommands(MixinMeta, metaclass=CompositeMetaClass):
async def command_audiostats(self, ctx: commands.Context): async def command_audiostats(self, ctx: commands.Context):
"""Audio stats.""" """Audio stats."""
server_num = len(lavalink.active_players()) server_num = len(lavalink.active_players())
total_num = len(lavalink.all_players()) total_num = len(lavalink.all_connected_players())
msg = "" msg = ""
async for p in AsyncIter(lavalink.all_players()): async for p in AsyncIter(lavalink.all_connected_players()):
connect_start = p.fetch("connect") connect_dur = (
connect_dur = self.get_time_string( self.get_time_string(
int((datetime.datetime.utcnow() - connect_start).total_seconds()) int(
(
datetime.datetime.now(datetime.timezone.utc) - p.connected_at
).total_seconds()
)
)
or "0s"
) )
try: try:
if not p.current: if not p.current:
@ -59,7 +65,7 @@ class MiscellaneousCommands(MixinMeta, metaclass=CompositeMetaClass):
current_title = await self.get_track_description( current_title = await self.get_track_description(
p.current, self.local_folder_current_path p.current, self.local_folder_current_path
) )
msg += "{} [`{}`]: {}\n".format(p.guild.name, connect_dur, current_title) msg += f"{p.guild.name} [`{connect_dur}`]: {current_title}\n"
except AttributeError: except AttributeError:
msg += "{} [`{}`]: **{}**\n".format( msg += "{} [`{}`]: **{}**\n".format(
p.guild.name, connect_dur, _("Nothing playing.") p.guild.name, connect_dur, _("Nothing playing.")

View File

@ -86,10 +86,6 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except AttributeError: except AttributeError:
return await self.send_embed_msg( return await self.send_embed_msg(
ctx, ctx,
@ -103,8 +99,7 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
description=_("Connection to Lavalink has not yet been established."), description=_("Connection to Lavalink has not yet been established."),
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
await self._eq_check(ctx, player) await self._eq_check(ctx, player)
await self.set_player_settings(ctx) await self.set_player_settings(ctx)
if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip: if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip:
@ -197,10 +192,6 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except AttributeError: except AttributeError:
return await self.send_embed_msg( return await self.send_embed_msg(
ctx, ctx,
@ -214,8 +205,7 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
description=_("Connection to Lavalink has not yet been established."), description=_("Connection to Lavalink has not yet been established."),
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
await self._eq_check(ctx, player) await self._eq_check(ctx, player)
await self.set_player_settings(ctx) await self.set_player_settings(ctx)
if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip: if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip:
@ -464,10 +454,6 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except AttributeError: except AttributeError:
return await self.send_embed_msg( return await self.send_embed_msg(
ctx, ctx,
@ -481,9 +467,7 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
description=_("Connection to Lavalink has not yet been established."), description=_("Connection to Lavalink has not yet been established."),
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("notify_channel", ctx.channel.id)
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
await self._eq_check(ctx, player) await self._eq_check(ctx, player)
await self.set_player_settings(ctx) await self.set_player_settings(ctx)
if ( if (
@ -584,10 +568,6 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except AttributeError: except AttributeError:
return await self.send_embed_msg( return await self.send_embed_msg(
ctx, ctx,
@ -601,9 +581,7 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
description=_("Connection to Lavalink has not yet been established."), description=_("Connection to Lavalink has not yet been established."),
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("notify_channel", ctx.channel.id)
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
await self._eq_check(ctx, player) await self._eq_check(ctx, player)
await self.set_player_settings(ctx) await self.set_player_settings(ctx)
if ( if (
@ -623,7 +601,7 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
try: try:
await self.api_interface.autoplay(player, self.playlist_api) await self.api_interface.autoplay(player, self.playlist_api)
except DatabaseError: except DatabaseError:
notify_channel = player.fetch("channel") notify_channel = player.fetch("notify_channel")
if notify_channel: if notify_channel:
notify_channel = self.bot.get_channel(notify_channel) notify_channel = self.bot.get_channel(notify_channel)
await self.send_embed_msg(notify_channel, title=_("Couldn't get a valid track.")) await self.send_embed_msg(notify_channel, title=_("Couldn't get a valid track."))
@ -712,10 +690,6 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except AttributeError: except AttributeError:
return await self.send_embed_msg( return await self.send_embed_msg(
ctx, ctx,
@ -730,8 +704,7 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass):
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
guild_data = await self.config.guild(ctx.guild).all() guild_data = await self.config.guild(ctx.guild).all()
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
can_skip = await self._can_instaskip(ctx, ctx.author) can_skip = await self._can_instaskip(ctx, ctx.author)
if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip: if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip:
return await self.send_embed_msg( return await self.send_embed_msg(

View File

@ -338,14 +338,11 @@ class QueueCommands(MixinMeta, metaclass=CompositeMetaClass):
title=_("Unable To Shuffle Queue"), title=_("Unable To Shuffle Queue"),
description=_("I don't have permission to connect to your channel."), description=_("I don't have permission to connect to your channel."),
) )
await lavalink.connect( player = await lavalink.connect(
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id) player.store("notify_channel", ctx.channel.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except AttributeError: except AttributeError:
ctx.command.reset_cooldown(ctx) ctx.command.reset_cooldown(ctx)
return await self.send_embed_msg( return await self.send_embed_msg(

View File

@ -196,7 +196,7 @@ class AudioEvents(MixinMeta, metaclass=CompositeMetaClass):
requester: discord.Member, requester: discord.Member,
player: lavalink.Player, player: lavalink.Player,
): ):
notify_channel = self.bot.get_channel(player.fetch("channel")) notify_channel = self.bot.get_channel(player.fetch("notify_channel"))
has_perms = self._has_notify_perms(notify_channel) has_perms = self._has_notify_perms(notify_channel)
tries = 0 tries = 0
while not player._is_playing: while not player._is_playing:

View File

@ -90,9 +90,9 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
notify_channel = player.fetch("channel") notify_channel = player.fetch("notify_channel")
if not notify_channel: if not notify_channel:
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
self._daily_global_playlist_cache.setdefault( self._daily_global_playlist_cache.setdefault(
self.bot.user.id, await self.config.daily_playlists() self.bot.user.id, await self.config.daily_playlists()

View File

@ -120,7 +120,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
await self.api_interface.persistent_queue_api.played( await self.api_interface.persistent_queue_api.played(
guild_id=guild_id, track_id=current_track.track_identifier guild_id=guild_id, track_id=current_track.track_identifier
) )
notify_channel = player.fetch("channel") notify_channel = player.fetch("notify_channel")
if notify_channel and autoplay: if notify_channel and autoplay:
await self.config.guild_from_id(guild_id=guild_id).currently_auto_playing_in.set( 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]
@ -145,7 +145,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
and self.playlist_api is not None and self.playlist_api is not None
and self.api_interface is not None and self.api_interface is not None
): ):
notify_channel_id = player.fetch("channel") notify_channel_id = player.fetch("notify_channel")
try: try:
await self.api_interface.autoplay(player, self.playlist_api) await self.api_interface.autoplay(player, self.playlist_api)
except DatabaseError: except DatabaseError:
@ -168,7 +168,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
) )
return return
if event_type == lavalink.LavalinkEvents.TRACK_START and notify: if event_type == lavalink.LavalinkEvents.TRACK_START and notify:
notify_channel_id = player.fetch("channel") notify_channel_id = player.fetch("notify_channel")
notify_channel = self.bot.get_channel(notify_channel_id) notify_channel = self.bot.get_channel(notify_channel_id)
if notify_channel and self._has_notify_perms(notify_channel): if notify_channel and self._has_notify_perms(notify_channel):
if player.fetch("notify_message") is not None: if player.fetch("notify_message") is not None:
@ -207,7 +207,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
if event_type == lavalink.LavalinkEvents.QUEUE_END: if event_type == lavalink.LavalinkEvents.QUEUE_END:
if not autoplay: if not autoplay:
notify_channel_id = player.fetch("channel") notify_channel_id = player.fetch("notify_channel")
notify_channel = self.bot.get_channel(notify_channel_id) notify_channel = self.bot.get_channel(notify_channel_id)
if notify_channel and notify and self._has_notify_perms(notify_channel): if notify_channel and notify and self._has_notify_perms(notify_channel):
await self.send_embed_msg(notify_channel, title=_("Queue ended.")) await self.send_embed_msg(notify_channel, title=_("Queue ended."))
@ -226,7 +226,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
lavalink.LavalinkEvents.TRACK_EXCEPTION, lavalink.LavalinkEvents.TRACK_EXCEPTION,
lavalink.LavalinkEvents.TRACK_STUCK, lavalink.LavalinkEvents.TRACK_STUCK,
]: ]:
message_channel = player.fetch("channel") message_channel = player.fetch("notify_channel")
while True: while True:
if current_track in player.queue: if current_track in player.queue:
player.queue.remove(current_track) player.queue.remove(current_track)

View File

@ -129,11 +129,8 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
if not (perms.connect and perms.speak): if not (perms.connect and perms.speak):
vc = None vc = None
break break
await lavalink.connect(vc, deafen=auto_deafen) player = await lavalink.connect(vc, deafen=auto_deafen)
player = lavalink.get_player(guild.id) player.store("notify_channel", notify_channel_id)
player.store("connect", datetime.datetime.utcnow())
player.store("guild", guild_id)
player.store("channel", notify_channel_id)
break break
except IndexError: except IndexError:
await asyncio.sleep(5) await asyncio.sleep(5)
@ -201,11 +198,8 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
if not (perms.connect and perms.speak): if not (perms.connect and perms.speak):
vc = None vc = None
break break
await lavalink.connect(vc, deafen=auto_deafen) player = await lavalink.connect(vc, deafen=auto_deafen)
player = lavalink.get_player(guild.id) player.store("notify_channel", notify_channel_id)
player.store("connect", datetime.datetime.utcnow())
player.store("guild", guild_id)
player.store("channel", notify_channel_id)
break break
except IndexError: except IndexError:
await asyncio.sleep(5) await asyncio.sleep(5)
@ -228,7 +222,7 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
player.maybe_shuffle() player.maybe_shuffle()
log.info("Restored %r", player) log.info("Restored %r", player)
if not player.is_playing: if not player.is_playing:
notify_channel = player.fetch("channel") notify_channel = player.fetch("notify_channel")
try: try:
await self.api_interface.autoplay(player, self.playlist_api) await self.api_interface.autoplay(player, self.playlist_api)
except DatabaseError: except DatabaseError:

View File

@ -103,10 +103,6 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except AttributeError: except AttributeError:
return await self.send_embed_msg(ctx, title=_("Connect to a voice channel first.")) return await self.send_embed_msg(ctx, title=_("Connect to a voice channel first."))
except IndexError: except IndexError:
@ -114,6 +110,7 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
ctx, title=_("Connection to Lavalink has not yet been established.") ctx, title=_("Connection to Lavalink has not yet been established.")
) )
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("notify_channel", ctx.channel.id)
guild_data = await self.config.guild(ctx.guild).all() guild_data = await self.config.guild(ctx.guild).all()
if len(player.queue) >= 10000: if len(player.queue) >= 10000:
return await self.send_embed_msg( return await self.send_embed_msg(

View File

@ -546,10 +546,6 @@ class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass):
ctx.author.voice.channel, ctx.author.voice.channel,
deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(), deafen=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
) )
player = lavalink.get_player(ctx.guild.id)
player.store("connect", datetime.datetime.utcnow())
player.store("channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
except IndexError: except IndexError:
await self.send_embed_msg( await self.send_embed_msg(
ctx, ctx,
@ -564,10 +560,8 @@ class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass):
description=_("Connect to a voice channel first."), description=_("Connect to a voice channel first."),
) )
return False return False
player = lavalink.get_player(ctx.guild.id) player = lavalink.get_player(ctx.guild.id)
player.store("channel", ctx.channel.id) player.store("notify_channel", ctx.channel.id)
player.store("guild", ctx.guild.id)
if ( if (
not ctx.author.voice or ctx.author.voice.channel != player.channel not ctx.author.voice or ctx.author.voice.channel != player.channel
) and not await self._can_instaskip(ctx, ctx.author): ) and not await self._can_instaskip(ctx, ctx.author):