Skip to content

Commit

Permalink
Update Audio to use RLL 0.11.0rc0 (#5631)
Browse files Browse the repository at this point in the history
* Replace player.manager to player.node

* Try using bot.is_closed instead of get_voice_ws.

* Use Shard.is_closed instead of bot.is_closed.

* Use RLL PR as dep.

* Update audio to use add dep to Cog-Creators/Red-Lavalink#122

* few thing missing

* Missing `player.manager.node` -> `player.node` change

* Update setup.cfg

Co-authored-by: PredaaA <46051820+PredaaA@users.noreply.github.com>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 31, 2022
1 parent 9ec85d4 commit 511de51
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
10 changes: 5 additions & 5 deletions redbot/cogs/audio/core/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ async def can_manage_playlist(

@abstractmethod
async def _maybe_update_playlist(
self, ctx: commands.Context, player: lavalink.player_manager.Player, playlist: "Playlist"
self, ctx: commands.Context, player: lavalink.player.Player, playlist: "Playlist"
) -> Tuple[List[lavalink.Track], List[lavalink.Track], "Playlist"]:
raise NotImplementedError()

Expand Down Expand Up @@ -424,7 +424,7 @@ async def _search_button_action(

@abstractmethod
async def get_localtrack_folder_tracks(
self, ctx, player: lavalink.player_manager.Player, query: "Query"
self, ctx, player: lavalink.player.Player, query: "Query"
) -> List[lavalink.rest_api.Track]:
raise NotImplementedError()

Expand Down Expand Up @@ -475,7 +475,7 @@ async def _build_queue_page(
self,
ctx: commands.Context,
queue: list,
player: lavalink.player_manager.Player,
player: lavalink.player.Player,
page_num: int,
) -> discord.Embed:
raise NotImplementedError()
Expand All @@ -500,7 +500,7 @@ async def _build_queue_search_page(
async def fetch_playlist_tracks(
self,
ctx: commands.Context,
player: lavalink.player_manager.Player,
player: lavalink.player.Player,
query: "Query",
skip_cache: bool = False,
) -> Union[discord.Message, None, List[MutableMapping]]:
Expand Down Expand Up @@ -534,7 +534,7 @@ async def _load_v2_playlist(
self,
ctx: commands.Context,
uploaded_track_list,
player: lavalink.player_manager.Player,
player: lavalink.player.Player,
playlist_url: str,
uploaded_playlist_name: str,
scope: str,
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/audio/core/events/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def on_red_audio_track_auto_play(

if notify_channel and has_perms and not player.fetch("autoplay_notified", False):
if (
len(player.manager.players) < 10
len(player.node.players) < 10
or not player._last_resume
and player._last_resume + datetime.timedelta(seconds=60)
> datetime.datetime.now(tz=datetime.timezone.utc)
Expand Down
13 changes: 5 additions & 8 deletions redbot/cogs/audio/core/events/lavalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import discord
import lavalink
from discord.backoff import ExponentialBackoff
from discord.gateway import DiscordWebSocket
from red_commons.logging import getLogger

from redbot.core.i18n import Translator, set_contextual_locales_from_guild
Expand Down Expand Up @@ -100,7 +99,7 @@ async def lavalink_event_handler(
exc_info=exc,
)
return
if not player.manager.node.ready:
if not player.node.ready:
log.debug("Player node is not ready discarding event")
log.verbose(
"Received a new discard lavalink event for %s: %s: %r", guild_id, event_type, extra
Expand Down Expand Up @@ -340,14 +339,13 @@ async def _websocket_closed_handler(
disconnect: bool,
) -> None:
guild_id = guild.id
shard = self.bot.shards[guild.shard_id]
event_channel_id = extra.get("channelID")
try:
if not self._ws_resume[guild_id].is_set():
await self._ws_resume[guild_id].wait()
else:
self._ws_resume[guild_id].clear()
node = player.node
voice_ws: DiscordWebSocket = node.get_voice_ws(guild_id)
code = extra.get("code")
by_remote = extra.get("byRemote", "")
reason = extra.get("reason", "No Specified Reason").strip()
Expand Down Expand Up @@ -387,7 +385,7 @@ async def _websocket_closed_handler(
self._ws_op_codes[guild_id]._init(self._ws_op_codes[guild_id]._maxsize)
return

if voice_ws.socket._closing or voice_ws.socket.closed or not voice_ws.open:
if shard.is_closed():
if player._con_delay:
delay = player._con_delay.delay()
else:
Expand All @@ -399,7 +397,7 @@ async def _websocket_closed_handler(
"Socket Closed %s. "
"Code: %s -- Remote: %s -- %s, %r",
guild_id,
voice_ws.socket._closing or voice_ws.socket.closed,
shard.is_closed(),
code,
by_remote,
reason,
Expand All @@ -412,8 +410,7 @@ async def _websocket_closed_handler(
delay,
)
await asyncio.sleep(delay)
while voice_ws.socket._closing or voice_ws.socket.closed or not voice_ws.open:
voice_ws = node.get_voice_ws(guild_id)
while shard.is_closed():
await asyncio.sleep(0.1)

if has_perm and player.current and player.is_playing:
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/audio/core/tasks/lavalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def lavalink_attempt_connect(self, timeout: int = 50, manual: bool = False
bot=self.bot,
host=host,
password=password,
ws_port=port,
port=port,
timeout=timeout,
resume_key=f"Red-Core-Audio-{self.bot.user.id}-{data_manager.instance_name}",
secured=secured,
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/audio/core/utilities/local_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def get_localtrack_folder_list(self, ctx: commands.Context, query: Query)
)

async def get_localtrack_folder_tracks(
self, ctx, player: lavalink.player_manager.Player, query: Query
self, ctx, player: lavalink.player.Player, query: Query
) -> List[lavalink.rest_api.Track]:
"""Return a list of tracks per the provided query."""
if not await self.localtracks_folder_exists(ctx) or self.api_interface is None:
Expand Down
6 changes: 3 additions & 3 deletions redbot/cogs/audio/core/utilities/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ async def _load_v2_playlist(
self,
ctx: commands.Context,
uploaded_track_list,
player: lavalink.player_manager.Player,
player: lavalink.player.Player,
playlist_url: str,
uploaded_playlist_name: str,
scope: str,
Expand Down Expand Up @@ -481,7 +481,7 @@ async def _load_v2_playlist(
await playlist_msg.edit(embed=embed3)

async def _maybe_update_playlist(
self, ctx: commands.Context, player: lavalink.player_manager.Player, playlist: Playlist
self, ctx: commands.Context, player: lavalink.player.Player, playlist: Playlist
) -> Tuple[List[lavalink.Track], List[lavalink.Track], Playlist]:
if getattr(playlist, "id", 0) == 42069:
_, updated_tracks = await self._get_bundled_playlist_tracks()
Expand Down Expand Up @@ -580,7 +580,7 @@ async def _playlist_check(self, ctx: commands.Context) -> bool:
async def fetch_playlist_tracks(
self,
ctx: commands.Context,
player: lavalink.player_manager.Player,
player: lavalink.player.Player,
query: Query,
skip_cache: bool = False,
) -> Union[discord.Message, None, List[MutableMapping]]:
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/audio/core/utilities/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def _build_queue_page(
self,
ctx: commands.Context,
queue: list,
player: lavalink.player_manager.Player,
player: lavalink.player.Player,
page_num: int,
) -> discord.Embed:
shuffle = await self.config.guild(ctx.guild).shuffle()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ install_requires =
pytz==2021.1
PyYAML==5.4.1
Red-Commons==1.0.0
Red-Lavalink==0.10.0
Red-Lavalink==0.11.0rc0
rich==10.9.0
schema==0.7.4
six==1.16.0
Expand Down

0 comments on commit 511de51

Please sign in to comment.