Better permissions check and fix mute/unmute command
This commit is contained in:
parent
3755a34ee7
commit
33c6f9db01
1 changed files with 23 additions and 41 deletions
|
@ -26,12 +26,12 @@ class Speak(commands.Cog):
|
||||||
|
|
||||||
@commands.group("speak", pass_context=True)
|
@commands.group("speak", pass_context=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
@commands.has_guild_permissions(mute_members=True)
|
||||||
async def speak(self, ctx: commands.Context):
|
async def speak(self, ctx: commands.Context):
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
raise CommandNotFound
|
raise CommandNotFound
|
||||||
|
|
||||||
@speak.group("help", pass_context=True)
|
@speak.group("help", pass_context=True)
|
||||||
@commands.guild_only()
|
|
||||||
async def speak_help(self, ctx: commands.Context):
|
async def speak_help(self, ctx: commands.Context):
|
||||||
embed = Embed(title="Speak help")
|
embed = Embed(title="Speak help")
|
||||||
embed.add_field(name="speak setup [strict]",
|
embed.add_field(name="speak setup [strict]",
|
||||||
|
@ -41,41 +41,35 @@ class Speak(commands.Cog):
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@speak.group("setup", pass_context=True)
|
@speak.group("setup", pass_context=True)
|
||||||
@commands.guild_only()
|
|
||||||
async def speak_setup(self, ctx: commands.Context, *args):
|
async def speak_setup(self, ctx: commands.Context, *args):
|
||||||
if not ctx.author.voice.channel.permissions_for(ctx.author).mute_members:
|
self.voice_chan = ctx.author.voice.channel.id
|
||||||
await ctx.message.add_reaction("\u274C")
|
embed = Embed(title="Speak \U0001f508")
|
||||||
else:
|
embed.add_field(name="Waiting list \u23f3", value="Nobody", inline=False)
|
||||||
self.voice_chan = ctx.author.voice.channel.id
|
embed.add_field(name="Reactions",
|
||||||
embed = Embed(title="Speak \U0001f508")
|
value="\U0001f5e3 Speak !\n"
|
||||||
embed.add_field(name="Waiting list \u23f3", value="Nobody", inline=False)
|
"\u2757 React to speaker\n"
|
||||||
embed.add_field(name="Reactions",
|
"\u27A1 Next\n"
|
||||||
value="\U0001f5e3 Speak !\n"
|
"\U0001F513 Strict\n"
|
||||||
"\u2757 React to speaker\n"
|
"\U0001F507 Mute\n"
|
||||||
"\u27A1 Next\n"
|
"\U0001F50A Unmute\n"
|
||||||
"\U0001F513 Strict\n"
|
"\u274C Clear the speak\n"
|
||||||
"\U0001F507 Mute\n"
|
"Remove your reaction to remove from list",
|
||||||
"\U0001F50A Unmute\n"
|
inline=False)
|
||||||
"\u274C Clear the speak\n"
|
self.voice_message = await ctx.send(embed=embed)
|
||||||
"Remove your reaction to remove from list",
|
for reaction in ["\U0001f5e3", "\u2757", "\u27A1", "\U0001F512", "\U0001F507", "\U0001F50A", "\u274C"]:
|
||||||
inline=False)
|
await self.voice_message.add_reaction(reaction)
|
||||||
self.voice_message = await ctx.send(embed=embed)
|
self.voice_message = await self.voice_message.channel.fetch_message(self.voice_message.id)
|
||||||
for reaction in ["\U0001f5e3", "\u2757", "\u27A1", "\U0001F512", "\U0001F507", "\U0001F50A", "\u274C"]:
|
|
||||||
await self.voice_message.add_reaction(reaction)
|
|
||||||
self.voice_message = await self.voice_message.channel.fetch_message(self.voice_message.id)
|
|
||||||
|
|
||||||
@speak.group("mute", pass_context=True)
|
@speak.group("mute", pass_context=True)
|
||||||
@commands.guild_only()
|
|
||||||
async def speak_mute(self, ctx: commands.Context):
|
async def speak_mute(self, ctx: commands.Context):
|
||||||
if not self.mute(True, ctx.author):
|
if not await self.mute(True, ctx.author):
|
||||||
await ctx.message.add_reaction("\u274C")
|
await ctx.message.add_reaction("\u274C")
|
||||||
else:
|
else:
|
||||||
await ctx.message.add_reaction("\U0001f44d")
|
await ctx.message.add_reaction("\U0001f44d")
|
||||||
|
|
||||||
@speak.group("unmute", pass_context=True)
|
@speak.group("unmute", pass_context=True)
|
||||||
@commands.guild_only()
|
|
||||||
async def speak_unmute(self, ctx: commands.Context):
|
async def speak_unmute(self, ctx: commands.Context):
|
||||||
if not self.mute(False, ctx.author):
|
if not await self.mute(False, ctx.author):
|
||||||
await ctx.message.add_reaction("\u274C")
|
await ctx.message.add_reaction("\u274C")
|
||||||
else:
|
else:
|
||||||
await ctx.message.add_reaction("\U0001f44d")
|
await ctx.message.add_reaction("\U0001f44d")
|
||||||
|
@ -83,13 +77,13 @@ class Speak(commands.Cog):
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState):
|
async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState):
|
||||||
if self.voice_chan and self.strict and \
|
if self.voice_chan and self.strict and \
|
||||||
(before is None or before.channel is None or before.channel.id != self.voice_chan) and\
|
(before is None or before.channel is None or before.channel.id != self.voice_chan) and \
|
||||||
(after is not None and after.channel is not None and after.channel.id == self.voice_chan) and \
|
(after is not None and after.channel is not None and after.channel.id == self.voice_chan) and \
|
||||||
not (self.last_speaker and member.id == self.last_speaker) and \
|
not (self.last_speaker and member.id == self.last_speaker) and \
|
||||||
not (self.reaction and member.id == self.last_reaction):
|
not (self.reaction and member.id == self.last_reaction):
|
||||||
await member.edit(mute=True)
|
await member.edit(mute=True)
|
||||||
elif self.voice_chan and \
|
elif self.voice_chan and \
|
||||||
(before is not None and before.channel is not None and before.channel.id == self.voice_chan) and\
|
(before is not None and before.channel is not None and before.channel.id == self.voice_chan) and \
|
||||||
(after is not None and after.channel is not None and after.channel.id != self.voice_chan):
|
(after is not None and after.channel is not None and after.channel.id != self.voice_chan):
|
||||||
await member.edit(mute=False)
|
await member.edit(mute=False)
|
||||||
|
|
||||||
|
@ -244,8 +238,7 @@ class Speak(commands.Cog):
|
||||||
await self.voice_message.edit(embed=embed)
|
await self.voice_message.edit(embed=embed)
|
||||||
|
|
||||||
async def mute(self, state: bool, user: Member) -> bool:
|
async def mute(self, state: bool, user: Member) -> bool:
|
||||||
if user.voice is None or user.voice.channel is None or \
|
if user.voice is None or user.voice.channel is None:
|
||||||
not user.voice.channel.permissions_for(user).mute_members:
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
for client in user.voice.channel.members:
|
for client in user.voice.channel.members:
|
||||||
|
@ -253,17 +246,6 @@ class Speak(commands.Cog):
|
||||||
await client.edit(mute=state)
|
await client.edit(mute=state)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@commands.Cog.listener()
|
|
||||||
async def on_command_error(self, ctx: commands.Context, error):
|
|
||||||
if ctx.invoked_with == extension_name or \
|
|
||||||
(ctx.command.root_parent is not None and ctx.command.root_parent.name == extension_name):
|
|
||||||
if isinstance(error, CommandNotFound):
|
|
||||||
await ctx.message.add_reaction("\u2753")
|
|
||||||
await ctx.message.delete(delay=30)
|
|
||||||
else:
|
|
||||||
await ctx.send("An error occurred !")
|
|
||||||
raise error
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
logger.info(f"Loading...")
|
logger.info(f"Loading...")
|
||||||
|
|
Reference in a new issue