From 371f8d0f610aaaf3bcb58d1c003f4baa489247e6 Mon Sep 17 00:00:00 2001 From: Twentysix Date: Sat, 14 May 2016 18:30:06 +0200 Subject: [PATCH] Properly handle connect and speak permissions --- cogs/audio.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cogs/audio.py b/cogs/audio.py index 1251a18fd..ca5f1f614 100644 --- a/cogs/audio.py +++ b/cogs/audio.py @@ -70,6 +70,12 @@ class AuthorNotConnected(NotConnected): class VoiceNotConnected(NotConnected): pass +class UnauthorizedConnect(Exception): + pass + +class UnauthorizedSpeak(Exception): + pass + class ConnectTimeout(NotConnected): pass @@ -976,9 +982,12 @@ class Audio: await self.bot.say("You must join a voice channel before I can" " play anything.") return - if not can_connect: + except UnauthorizedConnect: await self.bot.say("I don't have permissions to join your" " voice channel.") + except UnauthorizedSpeak: + await self.bot.say("I don't have permissions to speak in your" + " voice channel.") else: await self._join_voice_channel(voice_channel) else: # We are connected but not to the right channel @@ -1049,9 +1058,12 @@ class Audio: await self.bot.say("You must join a voice channel before I can" " play anything.") return - if not can_connect: + except UnauthorizedConnect: await self.bot.say("I don't have permissions to join your" " voice channel.") + except UnauthorizedSpeak: + await self.bot.say("I don't have permissions to speak in your" + " voice channel.") else: await self._join_voice_channel(voice_channel) else: # We are connected but not to the right channel @@ -1472,7 +1484,11 @@ class Audio: channel = author.voice_channel if channel is None: raise AuthorNotConnected - if channel.permissions_for(server.me): + elif channel.permissions_for(server.me).connect is False: + raise UnauthorizedConnect + elif channel.permissions_for(server.me).speak is False: + raise UnauthorizedSpeak + else: return True return False