Skip to content

Commit

Permalink
SNIPPETS: Add base functionality for snippet remove.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Apr 13, 2024
1 parent 2a702a7 commit 685687e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions bot/cogs/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 685687e

Please sign in to comment.