@@ -41,7 +41,7 @@ def __init__(self, bot):
41
41
self .registry = {}
42
42
self .bot .loop .create_task (self .download_initial_plugins ())
43
43
self .bot .loop .create_task (self .populate_registry ())
44
-
44
+
45
45
async def populate_registry (self ):
46
46
url = 'https://raw.githubusercontent.com/kyb3r/modmail/master/plugins/registry.json'
47
47
async with self .bot .session .get (url ) as resp :
@@ -146,42 +146,71 @@ async def plugin_add(self, ctx, *, plugin_name: str):
146
146
plugin_name = info ['repository' ] + '/' + plugin_name
147
147
required_version = info ['bot_version' ]
148
148
if parse_version (self .bot .version ) < parse_version (required_version ):
149
- return await ctx .send (f"Bot version too low, plugin requires version `{ required_version } `" )
149
+ em = discord .Embed (
150
+ description = f'Your bot\' s version is too low. This plugin requires version `{ required_version } `.' ,
151
+ color = self .bot .main_color
152
+ )
153
+ return await ctx .send (embed = em )
150
154
if plugin_name in self .bot .config .plugins :
151
- return await ctx .send ('Plugin already installed.' )
155
+ em = discord .Embed (
156
+ description = 'This plugin is already installed.' ,
157
+ color = self .bot .main_color
158
+ )
159
+ return await ctx .send (embed = em )
152
160
if plugin_name in self .bot .cogs .keys ():
153
161
# another class with the same name
154
- return await ctx .send ('Another cog exists with the same name.' )
162
+ em = discord .Embed (
163
+ description = 'There\' s another cog installed with the same name.' ,
164
+ color = self .bot .main_color
165
+ )
166
+ return await ctx .send (embed = em )
155
167
156
- message = await ctx .send ('Downloading plugin...' )
168
+ em = discord .Embed (
169
+ description = 'Downloading this plugin...' ,
170
+ color = self .bot .main_color
171
+ )
172
+ message = await ctx .send (embed = em )
157
173
async with ctx .typing ():
158
174
if len (plugin_name .split ('/' )) >= 3 :
159
175
parsed_plugin = self .parse_plugin (plugin_name )
160
176
161
177
try :
162
178
await self .download_plugin_repo (* parsed_plugin [:- 1 ])
163
179
except DownloadError as exc :
164
- return await ctx .send (
165
- f'Unable to fetch plugin from Github: { exc } .'
180
+ em = discord .Embed (
181
+ description = f'Unable to fetch this plugin from Github: { exc } .' ,
182
+ color = self .bot .main_color
166
183
)
184
+ return await ctx .send (embed = em )
167
185
168
186
importlib .invalidate_caches ()
169
187
try :
170
188
await self .load_plugin (* parsed_plugin )
171
189
except DownloadError as exc :
172
- return await ctx .send (f'Unable to load plugin: `{ exc } `.' )
190
+ em = discord .Embed (
191
+ description = f'Unable to load this plugin: { exc } .' ,
192
+ color = self .bot .main_color
193
+ )
194
+ return await ctx .send (embed = em )
173
195
174
196
# if it makes it here, it has passed all checks and should
175
197
# be entered into the config
176
198
177
199
self .bot .config .plugins .append (plugin_name )
178
200
await self .bot .config .update ()
179
201
180
- await message .edit (content = 'Plugin installed. Any plugin that '
181
- 'you install is of your OWN RISK.' )
202
+ em = discord .Embed (
203
+ description = 'The plugin is installed.\n '
204
+ '*Please note: any plugin that you install is of your OWN RISK*' ,
205
+ color = self .bot .main_color
206
+ )
207
+ await self .bot .edit_message (message , embed = em )
182
208
else :
183
- await message .edit (content = 'Invalid plugin name format. '
184
- 'Use username/repo/plugin.' )
209
+ em = discord .Embed (
210
+ description = 'Invalid plugin name format: use username/repo/plugin.' ,
211
+ color = self .bot .main_color
212
+ )
213
+ await self .bot .edit_message (message , embed = em )
185
214
186
215
@plugin .command (name = 'remove' , aliases = ['del' , 'delete' , 'rm' ])
187
216
@checks .has_permissions (PermissionLevel .OWNER )
@@ -196,7 +225,7 @@ async def plugin_remove(self, ctx, *, plugin_name: str):
196
225
self .bot .unload_extension (
197
226
f'plugins.{ username } -{ repo } .{ name } .{ name } '
198
227
)
199
- except :
228
+ except Exception :
200
229
pass
201
230
202
231
self .bot .config .plugins .remove (plugin_name )
@@ -219,10 +248,17 @@ def onerror(func, path, exc_info): # pylint: disable=W0613
219
248
raise exc
220
249
221
250
await self .bot .config .update ()
222
- await ctx .send ('Plugin uninstalled and '
223
- 'all related data is erased.' )
251
+ em = discord .Embed (
252
+ description = 'The plugin is uninstalled and all it\' s data is erased.' ,
253
+ color = self .bot .main_color
254
+ )
255
+ await ctx .send (embed = em )
224
256
else :
225
- await ctx .send ('Plugin not installed.' )
257
+ em = discord .Embed (
258
+ description = 'That plugin is not installed.' ,
259
+ color = self .bot .main_color
260
+ )
261
+ await ctx .send (embed = em )
226
262
227
263
@plugin .command (name = 'update' )
228
264
@checks .has_permissions (PermissionLevel .OWNER )
@@ -232,7 +268,11 @@ async def plugin_update(self, ctx, *, plugin_name: str):
232
268
info = self .registry [plugin_name ]
233
269
plugin_name = info ['repository' ] + '/' + plugin_name
234
270
if plugin_name not in self .bot .config .plugins :
235
- return await ctx .send ('Plugin not installed.' )
271
+ em = discord .Embed (
272
+ description = 'That plugin is not installed.' ,
273
+ color = self .bot .main_color
274
+ )
275
+ return await ctx .send (embed = em )
236
276
237
277
async with ctx .typing ():
238
278
username , repo , name = self .parse_plugin (plugin_name )
@@ -245,10 +285,18 @@ async def plugin_update(self, ctx, *, plugin_name: str):
245
285
)
246
286
except subprocess .CalledProcessError as exc :
247
287
err = exc .stderr .decode ('utf8' ).strip ()
248
- await ctx .send (f'Error while updating: { err } .' )
288
+ em = discord .Embed (
289
+ description = f'An error occured while updating: { err } .' ,
290
+ color = self .bot .main_color
291
+ )
292
+ await ctx .send (embed = em )
249
293
else :
250
294
output = cmd .stdout .decode ('utf8' ).strip ()
251
- await ctx .send (f'```\n { output } \n ```' )
295
+ em = discord .Embed (
296
+ description = '```\n {output}\n ```' ,
297
+ color = self .bot .main_color
298
+ )
299
+ await ctx .send (embed = em )
252
300
253
301
if output != 'Already up to date.' :
254
302
# repo was updated locally, now perform the cog reload
@@ -257,21 +305,33 @@ async def plugin_update(self, ctx, *, plugin_name: str):
257
305
try :
258
306
await self .load_plugin (username , repo , name )
259
307
except DownloadError as exc :
260
- await ctx .send (f'Unable to start plugin: `{ exc } `.' )
308
+ em = discord .Embed (
309
+ description = f'Unable to start the plugin: `{ exc } `.' ,
310
+ color = self .bot .main_color
311
+ )
312
+ await ctx .send (embed = em )
261
313
262
314
@plugin .command (name = 'enabled' , aliases = ['installed' ])
263
315
@checks .has_permissions (PermissionLevel .OWNER )
264
316
async def plugin_enabled (self , ctx ):
265
317
"""Shows a list of currently enabled plugins."""
266
318
if self .bot .config .plugins :
267
319
msg = '```\n ' + '\n ' .join (self .bot .config .plugins ) + '\n ```'
268
- await ctx .send (msg )
320
+ em = discord .Embed (
321
+ description = msg ,
322
+ color = self .bot .main_color
323
+ )
324
+ await ctx .send (embed = em )
269
325
else :
270
- await ctx .send ('No plugins installed.' )
326
+ em = discord .Embed (
327
+ description = 'There are no plugins installed.' ,
328
+ color = self .bot .main_color
329
+ )
330
+ await ctx .send (embed = em )
271
331
272
332
@plugin .command (name = 'registry' , aliases = ['list' ])
273
333
@checks .has_permissions (PermissionLevel .OWNER )
274
- async def plugin_registry (self , ctx , * , plugin_name :str = None ):
334
+ async def plugin_registry (self , ctx , * , plugin_name : str = None ):
275
335
"""Shows a list of all approved plugins."""
276
336
277
337
await self .populate_registry ()
@@ -293,9 +353,9 @@ def find_index(name):
293
353
index = find_index (plugin_name )
294
354
elif plugin_name is not None :
295
355
em = discord .Embed (
296
- color = discord .Color .red (),
297
- description = f'Could not find a plugin with name "{ plugin_name } " within the registry.'
298
- )
356
+ color = discord .Color .red (),
357
+ description = f'Could not find a plugin with name "{ plugin_name } " within the registry.'
358
+ )
299
359
300
360
matches = get_close_matches (plugin_name , self .registry .keys ())
301
361
if matches :
@@ -311,11 +371,11 @@ def find_index(name):
311
371
url = repo ,
312
372
title = info ['repository' ]
313
373
)
314
-
374
+
315
375
em .add_field (
316
- name = 'Installation' ,
376
+ name = 'Installation' ,
317
377
value = f'```{ self .bot .prefix } plugins add { name } ```' )
318
-
378
+
319
379
em .set_author (name = info ['title' ], icon_url = info .get ('icon_url' ))
320
380
if info .get ('thumbnail_url' ):
321
381
em .set_thumbnail (url = info .get ('thumbnail_url' ))
@@ -327,6 +387,5 @@ def find_index(name):
327
387
await paginator .run ()
328
388
329
389
330
-
331
390
def setup (bot ):
332
391
bot .add_cog (Plugins (bot ))
0 commit comments