1
- from typing import Optional
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING , Optional
2
4
3
5
import discord
4
6
from discord .ext import commands
5
- from libs .utils import GuildContext
6
- from rodhaj import Rodhaj
7
+
8
+ if TYPE_CHECKING :
9
+ from libs .utils .context import GuildContext
10
+
11
+ from rodhaj import Rodhaj
7
12
8
13
9
14
class Snippets (commands .Cog ):
10
- """
11
- Cog for snippet-related commands (#21)
12
- """
15
+ """Send or display pre-written text to users"""
13
16
14
17
def __init__ (self , bot : Rodhaj ):
15
- self ._bot = bot
18
+ self .bot = bot
19
+ self .pool = self .bot .pool
20
+
21
+ # Editing Utilities
22
+
23
+ async def edit_prompt_user (self , ctx : GuildContext , name : str ):
24
+ raise NotImplementedError ("TODO: Add prompt for editing snippet." )
16
25
17
26
@commands .guild_only ()
18
- @commands .group (name = "snippet" )
19
- async def snippet_cmd (self , ctx : GuildContext ):
20
- if ctx .invoked_subcommand is None :
21
- await ctx .send ("placeholder for base command" )
27
+ @commands .hybrid_group (name = "snippets" , alias = ["snippet" ], fallback = "get" )
28
+ async def snippet (self , ctx : GuildContext , * , name : str ):
29
+ """Allows for use snippets of text for later retrieval or for quicker responses
30
+
31
+ If an subcommand is not called, then this will search
32
+ the database for the requested snippet
33
+ """
34
+ await ctx .send ("Implement getting snippets here" )
22
35
23
36
@commands .guild_only ()
24
- @snippet_cmd .command ()
37
+ @snippet .command ()
25
38
async def remove (self , ctx : GuildContext , name : str ):
26
39
query = """
27
40
DELETE FROM snippets
28
41
WHERE guild_id = $1 AND name = $2
29
42
RETURNING name
30
43
"""
31
- result = await self ._bot . pool .fetchrow (query , ctx .guild .id , name )
44
+ result = await self .pool .fetchrow (query , ctx .guild .id , name )
32
45
if result is None :
33
46
await ctx .reply (
34
47
embed = discord .Embed (
@@ -49,19 +62,27 @@ async def remove(self, ctx: GuildContext, name: str):
49
62
ephemeral = True ,
50
63
)
51
64
65
+ # TODO: Run all str inputs through custom converters
52
66
@commands .guild_only ()
53
- @snippet_cmd .command ()
54
- async def new (self , ctx , * args ):
67
+ @snippet .command ()
68
+ async def new (self , ctx , name : str , * , content : Optional [ str ] = None ):
55
69
await ctx .send ("placeholder for snippet new" )
56
70
57
71
@commands .guild_only ()
58
- @snippet_cmd .command ()
72
+ @snippet .command (name = "list" )
73
+ async def snippets_list (
74
+ self , ctx : GuildContext , json : Optional [bool ] = False
75
+ ) -> None :
76
+ await ctx .send ("list snippets" )
77
+
78
+ @commands .guild_only ()
79
+ @snippet .command ()
59
80
async def show (self , ctx : GuildContext , name : str ):
60
81
query = """
61
82
SELECT content FROM snippets
62
83
WHERE guild_id = $1 AND name = $2
63
84
"""
64
- data = await self ._bot . pool .fetchrow (query , ctx .guild .id , name )
85
+ data = await self .pool .fetchrow (query , ctx .guild .id , name )
65
86
if data is None :
66
87
ret_embed = discord .Embed (
67
88
title = "Oops..." ,
@@ -80,15 +101,7 @@ async def show(self, ctx: GuildContext, name: str):
80
101
await ctx .reply (embed = ret_data , ephemeral = True )
81
102
82
103
@commands .guild_only ()
83
- @snippet_cmd .command ()
84
- async def list (self , ctx , * args ):
85
- await ctx .send ("placeholder for snippet list" )
86
-
87
- async def edit_prompt_user (self , ctx : GuildContext , name : str ):
88
- raise NotImplementedError ("TODO: Add prompt for editing snippet." )
89
-
90
- @commands .guild_only ()
91
- @snippet_cmd .command ()
104
+ @snippet .command ()
92
105
async def edit (self , ctx : GuildContext , name : str , content : Optional [str ]):
93
106
if content is None :
94
107
await self .edit_prompt_user (ctx , name )
@@ -100,7 +113,7 @@ async def edit(self, ctx: GuildContext, name: str, content: Optional[str]):
100
113
RETURNING name
101
114
"""
102
115
103
- result = await self ._bot . pool .fetchrow (query , ctx .guild .id , name , content )
116
+ result = await self .pool .fetchrow (query , ctx .guild .id , name , content )
104
117
if result is None :
105
118
await ctx .reply (
106
119
embed = discord .Embed (
0 commit comments