Skip to content

Commit

Permalink
SNIPPETS: Add base functionality for snippet show.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Apr 13, 2024
1 parent 2c72f23 commit 2a702a7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions bot/cogs/snippets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import discord
from discord.ext import commands
from libs.utils import GuildContext
from rodhaj import Rodhaj
Expand Down Expand Up @@ -29,8 +30,28 @@ async def new(self, ctx, *args):

@commands.guild_only()
@snippet_cmd.command()
async def show(self, ctx, *args):
await ctx.send("placeholder for snippet show")
async def show(self, ctx: GuildContext, name: str):
query = """
SELECT content FROM snippets
WHERE guild_id = $1 AND name = $2
"""
data = await self._bot.pool.fetchrow(query, ctx.guild.id, name)
if data is None:
ret_embed = discord.Embed(
title="Oops...",
colour=discord.Colour.red(),
description=f"The snippet `{name}` was not found. "
+ "To create a new snippet with this name, "
+ f"please run `snippet create {name} <content>`",
)
await ctx.reply(embed=ret_embed, ephemeral=True)
else:
ret_data = discord.Embed(
title=f"Snippet information for `{name}`",
colour=discord.Colour.green(),
description=data[0],
)
await ctx.reply(embed=ret_data, ephemeral=True)

@commands.guild_only()
@snippet_cmd.command()
Expand Down

0 comments on commit 2a702a7

Please sign in to comment.