Skip to content

Commit 2a702a7

Browse files
committed
SNIPPETS: Add base functionality for snippet show.
1 parent 2c72f23 commit 2a702a7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

bot/cogs/snippets.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import discord
12
from discord.ext import commands
23
from libs.utils import GuildContext
34
from rodhaj import Rodhaj
@@ -29,8 +30,28 @@ async def new(self, ctx, *args):
2930

3031
@commands.guild_only()
3132
@snippet_cmd.command()
32-
async def show(self, ctx, *args):
33-
await ctx.send("placeholder for snippet show")
33+
async def show(self, ctx: GuildContext, name: str):
34+
query = """
35+
SELECT content FROM snippets
36+
WHERE guild_id = $1 AND name = $2
37+
"""
38+
data = await self._bot.pool.fetchrow(query, ctx.guild.id, name)
39+
if data is None:
40+
ret_embed = discord.Embed(
41+
title="Oops...",
42+
colour=discord.Colour.red(),
43+
description=f"The snippet `{name}` was not found. "
44+
+ "To create a new snippet with this name, "
45+
+ f"please run `snippet create {name} <content>`",
46+
)
47+
await ctx.reply(embed=ret_embed, ephemeral=True)
48+
else:
49+
ret_data = discord.Embed(
50+
title=f"Snippet information for `{name}`",
51+
colour=discord.Colour.green(),
52+
description=data[0],
53+
)
54+
await ctx.reply(embed=ret_data, ephemeral=True)
3455

3556
@commands.guild_only()
3657
@snippet_cmd.command()

0 commit comments

Comments
 (0)