From c5a99be4054160d7d74b7345b2a73b08f59ae110 Mon Sep 17 00:00:00 2001 From: Supakorn 'Jamie' Rassameemasmuang Date: Sat, 16 Mar 2024 22:43:22 -0600 Subject: [PATCH] SNIPPETS: Add base functionality for snippet remove. --- bot/cogs/snippets.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snippets.py b/bot/cogs/snippets.py index c1af66d..61c441e 100644 --- a/bot/cogs/snippets.py +++ b/bot/cogs/snippets.py @@ -20,8 +20,32 @@ async def snippet_cmd(self, ctx: GuildContext): @commands.guild_only() @snippet_cmd.command() - async def remove(self, ctx, *args): - await ctx.send("placeholder for snippet remove") + async def remove(self, ctx: GuildContext, name: str): + query = """ + DELETE FROM snippets + WHERE guild_id = $1 AND name = $2 + RETURNING name + """ + result = await self._bot.pool.fetchrow(query, ctx.guild.id, name) + if result is None: + await ctx.reply( + embed=discord.Embed( + title="Deletion failed", + colour=discord.Colour.red(), + description=f"Snippet `{name}` was not found and " + + "hence was not deleted.", + ), + ephemeral=True, + ) + else: + await ctx.reply( + embed=discord.Embed( + title="Deletion successful", + colour=discord.Colour.green(), + description=f"Snippet `{name}` was deleted successfully", + ), + ephemeral=True, + ) @commands.guild_only() @snippet_cmd.command()