From be1cd2e0b0da4f79110f35498b8f1ec5624be3ab Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 8 Apr 2020 19:28:05 +0200 Subject: [PATCH 1/3] Add of speak reaction command --- extensions/speak.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/extensions/speak.py b/extensions/speak.py index 36c1385..29f5443 100644 --- a/extensions/speak.py +++ b/extensions/speak.py @@ -16,6 +16,8 @@ class Speak(commands.Cog): self.voice_chan = None self.waiting = [] self.lastSpeaker = None + self.reaction = [] + self.lastReaction = None @commands.group("speak", pass_context=True) @commands.guild_only() @@ -33,6 +35,17 @@ class Speak(commands.Cog): self.waiting.append(ctx.author.id) await ctx.message.add_reaction("\U0001f44d") + @speak.group("react", pass_context=True) + @commands.guild_only() + async def speak_react(self, ctx: commands.Context): + if ctx.author.voice is None or ctx.author.voice.channel is None or self.voice_chan is None or \ + ctx.author.voice.channel.id != self.voice_chan or ctx.author.id in self.reaction or \ + self.lastSpeaker is None or self.lastSpeaker == ctx.author.id: + await ctx.message.add_reaction("\u274C") + else: + self.reaction.append(ctx.author.id) + await ctx.message.add_reaction("\U0001f44d") + @speak.group("remove", pass_context=True) @commands.guild_only() async def speak_remove(self, ctx: commands.Context): @@ -66,18 +79,30 @@ class Speak(commands.Cog): if not self.voice_chan or not ctx.guild.get_channel(self.voice_chan).permissions_for(ctx.author).mute_members: await ctx.message.add_reaction("\u274C") else: - if self.lastSpeaker: + if self.lastReaction: + self.reaction.remove(self.lastReaction) + if self.strict: + await ctx.guild.get_member(self.lastReaction).edit(mute=True) + if self.lastSpeaker and len(self.reaction) == 0: self.waiting.remove(self.lastSpeaker) if self.strict: await ctx.guild.get_member(self.lastSpeaker).edit(mute=True) - if len(self.waiting) != 0: - user : Member = ctx.guild.get_member(self.waiting[0]) + if len(self.reaction) != 0 and self.lastSpeaker is not None: + user: Member = ctx.guild.get_member(self.reaction[0]) + self.lastReaction = self.reaction[0] + await ctx.send(f"{user.mention} react on {ctx.guild.get_member(self.lastSpeaker).mention} speak !") + if self.strict: + await user.edit(mute=False) + elif len(self.waiting) != 0: + user: Member = ctx.guild.get_member(self.waiting[0]) self.lastSpeaker = self.waiting[0] + self.lastReaction = None await ctx.send(f"It's {user.mention} turn") if self.strict: await user.edit(mute=False) else: self.lastSpeaker = None + self.lastReaction = None await ctx.send("Nobody left !") @speak.group("help", pass_context=True) @@ -123,6 +148,8 @@ class Speak(commands.Cog): else: self.waiting = [] self.lastSpeaker = None + self.reaction = [] + self.lastReaction = None for client in speak_channel.members: if client != ctx.author and not client.bot: await client.edit(mute=False) From 967d6ad111c83486f54a995c830b893dbaf5bf0f Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 8 Apr 2020 19:32:30 +0200 Subject: [PATCH 2/3] Show reaction list on waiting list --- extensions/speak.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/speak.py b/extensions/speak.py index 29f5443..fd51639 100644 --- a/extensions/speak.py +++ b/extensions/speak.py @@ -69,8 +69,12 @@ class Speak(commands.Cog): await ctx.message.add_reaction("\u274C") else: embed = Embed(title="Waiting list") + if len(self.reaction) != 0: + for i, reaction in enumerate(self.reaction): + embed.add_field(name=f"Reaction N°{i+1}", value=ctx.guild.get_member(reaction).display_name, + inline=False) for i, speaker in enumerate(self.waiting): - embed.add_field(name=f"N°{i+1}", value=ctx.guild.get_member(speaker).display_name, inline=True) + embed.add_field(name=f"N°{i+1}", value=ctx.guild.get_member(speaker).display_name, inline=False) await ctx.send(embed=embed) @speak.group("next", pass_context=True) From 156b7e5c82638486646e5eca032bca059f894ded Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 8 Apr 2020 19:33:52 +0200 Subject: [PATCH 3/3] Add speak react on the help --- extensions/speak.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/speak.py b/extensions/speak.py index fd51639..360d61a 100644 --- a/extensions/speak.py +++ b/extensions/speak.py @@ -114,6 +114,8 @@ class Speak(commands.Cog): async def speak_help(self, ctx: commands.Context): embed = Embed(title="Speak help") embed.add_field(name="speak", value="Join the waiting list", inline=False) + embed.add_field(name="speak react", value="Be the next to speak to react and debate with the current speaker", + inline=False) embed.add_field(name="speak remove [@pepole, @...]", value="Remove yourself or mentioned person from the waiting list", inline=False) embed.add_field(name="speak list", value="Show the waiting list", inline=False)