mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Audio] Check channel's user limit before joining it
This commit is contained in:
parent
c25c5629ea
commit
72bc7182b0
@ -83,6 +83,10 @@ class UnauthorizedSpeak(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ChannelUserLimit(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UnauthorizedSave(Exception):
|
class UnauthorizedSave(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -1260,6 +1264,9 @@ class Audio:
|
|||||||
await self.bot.say("I don't have permissions to speak in your"
|
await self.bot.say("I don't have permissions to speak in your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
return
|
return
|
||||||
|
except ChannelUserLimit:
|
||||||
|
await self.bot.say("Your voice channel is full.")
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
else: # We are connected but not to the right channel
|
else: # We are connected but not to the right channel
|
||||||
@ -1347,6 +1354,9 @@ class Audio:
|
|||||||
await self.bot.say("I don't have permissions to speak in your"
|
await self.bot.say("I don't have permissions to speak in your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
return
|
return
|
||||||
|
except ChannelUserLimit:
|
||||||
|
await self.bot.say("Your voice channel is full.")
|
||||||
|
return
|
||||||
|
|
||||||
if not self.voice_connected(server):
|
if not self.voice_connected(server):
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
@ -1586,6 +1596,9 @@ class Audio:
|
|||||||
await self.bot.say("I don't have permissions to speak in"
|
await self.bot.say("I don't have permissions to speak in"
|
||||||
" your voice channel.")
|
" your voice channel.")
|
||||||
return
|
return
|
||||||
|
except ChannelUserLimit:
|
||||||
|
await self.bot.say("Your voice channel is full.")
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
self._clear_queue(server)
|
self._clear_queue(server)
|
||||||
@ -1991,12 +2004,22 @@ class Audio:
|
|||||||
|
|
||||||
def has_connect_perm(self, author, server):
|
def has_connect_perm(self, author, server):
|
||||||
channel = author.voice_channel
|
channel = author.voice_channel
|
||||||
|
|
||||||
|
if channel:
|
||||||
|
is_admin = channel.permissions_for(server.me).administrator
|
||||||
|
if channel.user_limit == 0:
|
||||||
|
is_full = False
|
||||||
|
else:
|
||||||
|
is_full = len(channel.voice_members) >= channel.user_limit
|
||||||
|
|
||||||
if channel is None:
|
if channel is None:
|
||||||
raise AuthorNotConnected
|
raise AuthorNotConnected
|
||||||
elif channel.permissions_for(server.me).connect is False:
|
elif channel.permissions_for(server.me).connect is False:
|
||||||
raise UnauthorizedConnect
|
raise UnauthorizedConnect
|
||||||
elif channel.permissions_for(server.me).speak is False:
|
elif channel.permissions_for(server.me).speak is False:
|
||||||
raise UnauthorizedSpeak
|
raise UnauthorizedSpeak
|
||||||
|
elif is_full and not is_admin:
|
||||||
|
raise ChannelUserLimit
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user