From 98cea4a4e6d65e769f838d7c5890b3016be64ee2 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Wed, 2 Feb 2022 14:31:29 -0700 Subject: [PATCH 1/4] Fix rolegiver --- jarvis/cogs/rolegiver.py | 64 +++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/jarvis/cogs/rolegiver.py b/jarvis/cogs/rolegiver.py index 4047ac0..08daa8d 100644 --- a/jarvis/cogs/rolegiver.py +++ b/jarvis/cogs/rolegiver.py @@ -230,42 +230,58 @@ class RolegiverCog(commands.Cog): select = create_select( options=options, custom_id="to_delete", - placeholder="Select roles to remove", + placeholder="Select roles to add", min_values=1, max_values=len(options), ) components = [create_actionrow(select)] - _ = await ctx.send(content="\u200b", components=components) + message = await ctx.send(content="\u200b", components=components) - await ctx.author.add_roles(role, reason="Rolegiver") + try: - roles = ctx.author.roles - if roles: - roles.sort(key=lambda x: -x.position) - _ = roles.pop(-1) + context = await wait_for_component( + self.bot, + check=lambda x: ctx.author.id == x.author.id, + message=message, + timeout=60 * 5, + ) - value = "\n".join([r.mention for r in roles]) if roles else "None" - fields = [ - Field(name="Added Role", value=f"{role.mention}"), - Field(name="Prior Role(s)", value=value), - ] + role = ctx.guild.get_role(context.selected_options[0]) - embed = build_embed( - title="User Given Role", - description=f"{role.mention} given to {ctx.author.mention}", - fields=fields, - ) + await ctx.author.add_roles(role, reason="Rolegiver") - embed.set_thumbnail(url=ctx.guild.icon_url) - embed.set_author( - name=ctx.author.nick if ctx.author.nick else ctx.author.name, - icon_url=ctx.author.avatar_url, - ) + roles = ctx.author.roles + if roles: + roles.sort(key=lambda x: -x.position) + _ = roles.pop(-1) - embed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}") + value = "\n".join([r.mention for r in roles]) if roles else "None" + fields = [ + Field(name="Added Role", value=f"{role.mention}"), + Field(name="Prior Role(s)", value=value), + ] - await ctx.send(embed=embed) + embed = build_embed( + title="User Given Role", + description=f"{role.mention} given to {ctx.author.mention}", + fields=fields, + ) + + embed.set_thumbnail(url=ctx.guild.icon_url) + embed.set_author( + name=ctx.author.nick if ctx.author.nick else ctx.author.name, + icon_url=ctx.author.avatar_url, + ) + + embed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}") + + await ctx.send(embed=embed) + except asyncio.TimeoutError: + for row in components: + for component in row["components"]: + component["disabled"] = True + await message.edit(components=components) @cog_ext.cog_subcommand( base="role", From 748bda1c73964766930be61fab3903b943bdfcbb Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Wed, 2 Feb 2022 14:32:57 -0700 Subject: [PATCH 2/4] Fix typo --- jarvis/cogs/rolegiver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jarvis/cogs/rolegiver.py b/jarvis/cogs/rolegiver.py index 08daa8d..7ff0f4a 100644 --- a/jarvis/cogs/rolegiver.py +++ b/jarvis/cogs/rolegiver.py @@ -243,7 +243,7 @@ class RolegiverCog(commands.Cog): context = await wait_for_component( self.bot, check=lambda x: ctx.author.id == x.author.id, - message=message, + messages=message, timeout=60 * 5, ) From 43f6a90d0161263d403e21a5829c86da49d404ac Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Wed, 2 Feb 2022 14:34:59 -0700 Subject: [PATCH 3/4] Loop through roles to append to user --- jarvis/cogs/rolegiver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jarvis/cogs/rolegiver.py b/jarvis/cogs/rolegiver.py index 7ff0f4a..4568594 100644 --- a/jarvis/cogs/rolegiver.py +++ b/jarvis/cogs/rolegiver.py @@ -247,9 +247,9 @@ class RolegiverCog(commands.Cog): timeout=60 * 5, ) - role = ctx.guild.get_role(context.selected_options[0]) - - await ctx.author.add_roles(role, reason="Rolegiver") + for role in context.selected_options: + role = ctx.guild.get_role(int(role)) + await ctx.author.add_roles(role, reason="Rolegiver") roles = ctx.author.roles if roles: From 2fe3f5c9d06a1eea249b6cd7f0f5ffeae58ada22 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Wed, 2 Feb 2022 14:39:43 -0700 Subject: [PATCH 4/4] Fix display of role add to include all added roles --- jarvis/cogs/rolegiver.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jarvis/cogs/rolegiver.py b/jarvis/cogs/rolegiver.py index 4568594..ac27d14 100644 --- a/jarvis/cogs/rolegiver.py +++ b/jarvis/cogs/rolegiver.py @@ -247,8 +247,10 @@ class RolegiverCog(commands.Cog): timeout=60 * 5, ) + added_roles = [] for role in context.selected_options: role = ctx.guild.get_role(int(role)) + added_roles.append(role) await ctx.author.add_roles(role, reason="Rolegiver") roles = ctx.author.roles @@ -256,9 +258,10 @@ class RolegiverCog(commands.Cog): roles.sort(key=lambda x: -x.position) _ = roles.pop(-1) + avalue = "\n".join([r.mention for r in added_roles]) if added_roles else "None" value = "\n".join([r.mention for r in roles]) if roles else "None" fields = [ - Field(name="Added Role", value=f"{role.mention}"), + Field(name="Added Role(s)", value=avalue), Field(name="Prior Role(s)", value=value), ] @@ -275,8 +278,11 @@ class RolegiverCog(commands.Cog): ) embed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}") + for row in components: + for component in row["components"]: + component["disabled"] = True - await ctx.send(embed=embed) + await message.edit_origin(embed=embed, content="\u200b", components=components) except asyncio.TimeoutError: for row in components: for component in row["components"]: