diff --git a/redbot/cogs/audio/core/abc.py b/redbot/cogs/audio/core/abc.py index f99069ca4..da6ad9989 100644 --- a/redbot/cogs/audio/core/abc.py +++ b/redbot/cogs/audio/core/abc.py @@ -549,5 +549,10 @@ class MixinMeta(ABC): async def icyparser(self, url: str) -> Optional[str]: raise NotImplementedError() + @abstractmethod async def self_deafen(self, player: lavalink.Player) -> None: raise NotImplementedError() + + @abstractmethod + def can_join_and_speak(self, channel: discord.VoiceChannel) -> bool: + raise NotImplementedError() diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index cbd24588e..f9ea3c05b 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -643,7 +643,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass): try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): @@ -651,7 +651,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass): return await self.send_embed_msg( ctx, title=_("Unable To Join Voice Channel"), - description=_("I don't have permission to connect to your channel."), + description=_("I don't have permission to connect and speak in your channel."), ) if not self._player_check(ctx): player = await lavalink.connect( diff --git a/redbot/cogs/audio/core/commands/player.py b/redbot/cogs/audio/core/commands/player.py index 104ec481f..70f31f6b5 100644 --- a/redbot/cogs/audio/core/commands/player.py +++ b/redbot/cogs/audio/core/commands/player.py @@ -73,14 +73,16 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass): return await self.send_embed_msg(ctx, title=msg, description=desc) try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): return await self.send_embed_msg( ctx, title=_("Unable To Play Tracks"), - description=_("I don't have permission to connect to your channel."), + description=_( + "I don't have permission to connect and speak in your channel." + ), ) await lavalink.connect( ctx.author.voice.channel, @@ -179,14 +181,16 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass): return await self.send_embed_msg(ctx, title=msg, description=desc) try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): return await self.send_embed_msg( ctx, title=_("Unable To Play Tracks"), - description=_("I don't have permission to connect to your channel."), + description=_( + "I don't have permission to connect and speak in your channel." + ), ) await lavalink.connect( ctx.author.voice.channel, @@ -441,14 +445,16 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass): return await self.send_embed_msg(ctx, title=msg, description=desc) try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): return await self.send_embed_msg( ctx, title=_("Unable To Play Tracks"), - description=_("I don't have permission to connect to your channel."), + description=_( + "I don't have permission to connect and speak in your channel." + ), ) await lavalink.connect( ctx.author.voice.channel, @@ -555,14 +561,16 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass): return await self.send_embed_msg(ctx, title=msg, description=desc) try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): return await self.send_embed_msg( ctx, title=_("Unable To Play Tracks"), - description=_("I don't have permission to connect to your channel."), + description=_( + "I don't have permission to connect and speak in your channel." + ), ) await lavalink.connect( ctx.author.voice.channel, @@ -677,14 +685,16 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass): return await self.send_embed_msg(ctx, title=msg, description=desc) try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): return await self.send_embed_msg( ctx, title=_("Unable To Search For Tracks"), - description=_("I don't have permission to connect to your channel."), + description=_( + "I don't have permission to connect and speak in your channel." + ), ) await lavalink.connect( ctx.author.voice.channel, diff --git a/redbot/cogs/audio/core/commands/queue.py b/redbot/cogs/audio/core/commands/queue.py index 8edb794f4..323b1ddb6 100644 --- a/redbot/cogs/audio/core/commands/queue.py +++ b/redbot/cogs/audio/core/commands/queue.py @@ -328,7 +328,7 @@ class QueueCommands(MixinMeta, metaclass=CompositeMetaClass): ) try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): @@ -336,7 +336,7 @@ class QueueCommands(MixinMeta, metaclass=CompositeMetaClass): return await self.send_embed_msg( ctx, title=_("Unable To Shuffle Queue"), - description=_("I don't have permission to connect to your channel."), + description=_("I don't have permission to connect and speak in your channel."), ) player = await lavalink.connect( ctx.author.voice.channel, diff --git a/redbot/cogs/audio/core/events/lavalink.py b/redbot/cogs/audio/core/events/lavalink.py index 1d0b7acb5..d4ad15f52 100644 --- a/redbot/cogs/audio/core/events/lavalink.py +++ b/redbot/cogs/audio/core/events/lavalink.py @@ -338,8 +338,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass): self._ws_op_codes[guild_id]._init(self._ws_op_codes[guild_id]._maxsize) return if player.channel: - current_perms = player.channel.permissions_for(player.guild.me) - has_perm = current_perms.speak and current_perms.connect + has_perm = self.can_join_and_speak(player.channel) else: has_perm = False if code in (1000,) and has_perm and player.current and player.is_playing: diff --git a/redbot/cogs/audio/core/utilities/playlists.py b/redbot/cogs/audio/core/utilities/playlists.py index ff73cb8e0..2eb03ea87 100644 --- a/redbot/cogs/audio/core/utilities/playlists.py +++ b/redbot/cogs/audio/core/utilities/playlists.py @@ -532,14 +532,16 @@ class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass): return False try: if ( - not ctx.author.voice.channel.permissions_for(ctx.me).connect + not self.can_join_and_speak(ctx.author.voice.channel) or not ctx.author.voice.channel.permissions_for(ctx.me).move_members and self.is_vc_full(ctx.author.voice.channel) ): await self.send_embed_msg( ctx, title=_("Unable To Get Playlists"), - description=_("I don't have permission to connect to your channel."), + description=_( + "I don't have permission to connect and speak in your channel." + ), ) return False await lavalink.connect( diff --git a/redbot/cogs/audio/core/utilities/validation.py b/redbot/cogs/audio/core/utilities/validation.py index f183b23a2..47d1c4c3a 100644 --- a/redbot/cogs/audio/core/utilities/validation.py +++ b/redbot/cogs/audio/core/utilities/validation.py @@ -53,6 +53,10 @@ class ValidationUtilities(MixinMeta, metaclass=CompositeMetaClass): def is_vc_full(self, channel: discord.VoiceChannel) -> bool: return not (channel.user_limit == 0 or channel.user_limit > len(channel.members)) + def can_join_and_speak(self, channel: discord.VoiceChannel) -> bool: + current_perms = channel.permissions_for(channel.guild.me) + return current_perms.speak and current_perms.connect + async def is_query_allowed( self, config: Config,