4
4
import datetime
5
5
import dateutil .parser
6
6
from core .decorators import trigger_typing
7
+ from core .paginator import PaginatorSession
7
8
8
9
class Modmail :
9
10
'''Commands directly related to Modmail functionality.'''
@@ -32,10 +33,13 @@ async def setup(self, ctx):
32
33
33
34
await ctx .send ('Successfully set up server.' )
34
35
35
- @commands .command (name = 'snippets' )
36
+ @commands .group (name = 'snippets' )
36
37
@commands .has_permissions (manage_messages = True )
37
- async def _snippets (self , ctx ):
38
+ async def snippets (self , ctx ):
38
39
'''Returns a list of snippets that are currently set.'''
40
+ if ctx .invoked_subcommand is not None :
41
+ return
42
+
39
43
embeds = []
40
44
41
45
em = discord .Embed (color = discord .Color .green ())
@@ -47,7 +51,8 @@ async def _snippets(self, ctx):
47
51
48
52
if not self .bot .snippets :
49
53
em .color = discord .Color .red ()
50
- em .description = 'You dont have any snippets at the moment.'
54
+ em .description = f'You dont have any snippets at the moment.'
55
+ em .set_footer (text = f'Do { self .bot .prefix } help snippets for more commands.' )
51
56
52
57
for name , value in self .bot .snippets .items ():
53
58
if len (em .fields ) == 5 :
@@ -58,6 +63,46 @@ async def _snippets(self, ctx):
58
63
59
64
session = PaginatorSession (ctx , * embeds )
60
65
await session .run ()
66
+
67
+ @snippets .command (name = 'add' )
68
+ async def _add (self , ctx , name : str .lower , * , value ):
69
+ '''Add a snippet to the bot config.'''
70
+ if 'snippets' not in self .bot .config .cache :
71
+ self .bot .config ['snippets' ] = {}
72
+
73
+ self .bot .config .snippets [name ] = value
74
+ await self .bot .config .update ()
75
+
76
+ em = discord .Embed (
77
+ title = 'Added snippet' ,
78
+ color = discord .Color .green (),
79
+ description = f'`{ name } ` points to: { value } '
80
+ )
81
+
82
+ await ctx .send (embed = em )
83
+
84
+ @snippets .command (name = 'del' )
85
+ async def __del (self , ctx , * , name : str .lower ):
86
+ '''Removes a snippet from bot config.'''
87
+
88
+ if 'snippets' not in self .bot .config .cache :
89
+ self .bot .config ['snippets' ] = {}
90
+
91
+ em = discord .Embed (
92
+ title = 'Removed snippet' ,
93
+ color = discord .Color .green (),
94
+ description = f'`{ name } ` no longer exists.'
95
+ )
96
+
97
+ if not self .bot .config .snippets .get (name ):
98
+ em .title = 'Error'
99
+ em .color = discord .Color .red ()
100
+ em .description = f'Snippet `{ name } ` does not exist.'
101
+ else :
102
+ self .bot .config ['snippets' ][name ] = None
103
+ await self .bot .config .update ()
104
+
105
+ await ctx .send (embed = em )
61
106
62
107
@commands .command (name = 'close' )
63
108
@commands .has_permissions (manage_channels = True )
0 commit comments