From 4343b67abd9e9aa4378022f5381f8e8951e288b2 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sun, 27 Aug 2023 15:04:21 -0600 Subject: [PATCH] Fix autoreact delete bug --- jarvis/cogs/core/admin/autoreact.py | 75 ++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/jarvis/cogs/core/admin/autoreact.py b/jarvis/cogs/core/admin/autoreact.py index 7ce43c2..2fe4e59 100644 --- a/jarvis/cogs/core/admin/autoreact.py +++ b/jarvis/cogs/core/admin/autoreact.py @@ -40,7 +40,9 @@ class AutoReactCog(Extension): Returns: Tuple of success? and error message """ - exists = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id) + exists = await Autoreact.find_one( + Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id + ) if exists: return False, f"Autoreact already exists for {channel.mention}." @@ -54,7 +56,9 @@ class AutoReactCog(Extension): return True, None - async def delete_autoreact(self, ctx: InteractionContext, channel: GuildText) -> bool: + async def delete_autoreact( + self, ctx: InteractionContext, channel: GuildText + ) -> bool: """ Remove an autoreact monitor on a channel. @@ -65,7 +69,9 @@ class AutoReactCog(Extension): Returns: Success? """ - ar = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id) + ar = await Autoreact.find_one( + Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id + ) if ar: await ar.delete() return True @@ -83,11 +89,25 @@ class AutoReactCog(Extension): opt_type=OptionType.CHANNEL, required=True, ) - @slash_option(name="thread", description="Create a thread?", opt_type=OptionType.BOOLEAN, required=False) - @slash_option(name="emote", description="Emote to add", opt_type=OptionType.STRING, required=False) + @slash_option( + name="thread", + description="Create a thread?", + opt_type=OptionType.BOOLEAN, + required=False, + ) + @slash_option( + name="emote", + description="Emote to add", + opt_type=OptionType.STRING, + required=False, + ) @check(admin_or_permissions(Permissions.MANAGE_GUILD)) async def _autoreact_add( - self, ctx: InteractionContext, channel: GuildText, thread: bool = True, emote: str = None + self, + ctx: InteractionContext, + channel: GuildText, + thread: bool = True, + emote: str = None, ) -> None: await ctx.defer() if emote: @@ -101,13 +121,22 @@ class AutoReactCog(Extension): return if custom_emoji: emoji_id = int(custom_emoji.group(1)) - if not find(lambda x: x.id == emoji_id, await ctx.guild.fetch_all_custom_emojis()): - await ctx.send("Please use a custom emote from this server.", ephemeral=True) + if not find( + lambda x: x.id == emoji_id, + await ctx.guild.fetch_all_custom_emojis(), + ): + await ctx.send( + "Please use a custom emote from this server.", ephemeral=True + ) return - autoreact = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id) + autoreact = await Autoreact.find_one( + Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id + ) if not autoreact: await self.create_autoreact(ctx, channel, thread) - autoreact = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id) + autoreact = await Autoreact.find_one( + Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id + ) if emote and emote in autoreact.reactions: await ctx.send( f"Emote already added to {channel.mention} autoreactions.", @@ -147,8 +176,12 @@ class AutoReactCog(Extension): required=True, ) @check(admin_or_permissions(Permissions.MANAGE_GUILD)) - async def _autoreact_remove(self, ctx: InteractionContext, channel: GuildText, emote: str) -> None: - autoreact = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id) + async def _autoreact_remove( + self, ctx: InteractionContext, channel: GuildText, emote: str + ) -> None: + autoreact = await Autoreact.find_one( + Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id + ) if not autoreact: await ctx.send( f"Please create autoreact first with /autoreact add {channel.mention} {emote}", @@ -182,8 +215,10 @@ class AutoReactCog(Extension): required=True, ) @check(admin_or_permissions(Permissions.MANAGE_GUILD)) - async def _autoreact_delete(self, ctx: InteractionContext, channel: GuildText) -> None: - result = self.delete_autoreact(ctx, channel) + async def _autoreact_delete( + self, ctx: InteractionContext, channel: GuildText + ) -> None: + result = await self.delete_autoreact(ctx, channel) if not result: await ctx.send(f"No autoreact found in {channel.mention}", ephemeral=True) else: @@ -199,8 +234,12 @@ class AutoReactCog(Extension): opt_type=OptionType.CHANNEL, required=True, ) - async def _autoreact_list(self, ctx: InteractionContext, channel: GuildText) -> None: - exists = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id) + async def _autoreact_list( + self, ctx: InteractionContext, channel: GuildText + ) -> None: + exists = await Autoreact.find_one( + Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id + ) if not exists: await ctx.send( f"Please create autoreact first with /autoreact add {channel.mention} ", @@ -209,7 +248,9 @@ class AutoReactCog(Extension): return message = "" if len(exists.reactions) > 0: - message = f"Current active autoreacts on {channel.mention}:\n" + "\n".join(exists.reactions) + message = f"Current active autoreacts on {channel.mention}:\n" + "\n".join( + exists.reactions + ) else: message = f"No reactions set on {channel.mention}" await ctx.send(message)