Skip to content

Commit 685687e

Browse files
committed
SNIPPETS: Add base functionality for snippet remove.
1 parent 2a702a7 commit 685687e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

bot/cogs/snippets.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,32 @@ async def snippet_cmd(self, ctx: GuildContext):
2020

2121
@commands.guild_only()
2222
@snippet_cmd.command()
23-
async def remove(self, ctx, *args):
24-
await ctx.send("placeholder for snippet remove")
23+
async def remove(self, ctx: GuildContext, name: str):
24+
query = """
25+
DELETE FROM snippets
26+
WHERE guild_id = $1 AND name = $2
27+
RETURNING name
28+
"""
29+
result = await self._bot.pool.fetchrow(query, ctx.guild.id, name)
30+
if result is None:
31+
await ctx.reply(
32+
embed=discord.Embed(
33+
title="Deletion failed",
34+
colour=discord.Colour.red(),
35+
description=f"Snippet `{name}` was not found and "
36+
+ "hence was not deleted.",
37+
),
38+
ephemeral=True,
39+
)
40+
else:
41+
await ctx.reply(
42+
embed=discord.Embed(
43+
title="Deletion successful",
44+
colour=discord.Colour.green(),
45+
description=f"Snippet `{name}` was deleted successfully",
46+
),
47+
ephemeral=True,
48+
)
2549

2650
@commands.guild_only()
2751
@snippet_cmd.command()

0 commit comments

Comments
 (0)