Skip to content

Commit 7aef457

Browse files
committed
Use embeds instead of normal messages
1 parent 5c1280b commit 7aef457

File tree

1 file changed

+89
-30
lines changed

1 file changed

+89
-30
lines changed

cogs/plugins.py

Lines changed: 89 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, bot):
4141
self.registry = {}
4242
self.bot.loop.create_task(self.download_initial_plugins())
4343
self.bot.loop.create_task(self.populate_registry())
44-
44+
4545
async def populate_registry(self):
4646
url = 'https://raw.githubusercontent.com/kyb3r/modmail/master/plugins/registry.json'
4747
async with self.bot.session.get(url) as resp:
@@ -146,42 +146,71 @@ async def plugin_add(self, ctx, *, plugin_name: str):
146146
plugin_name = info['repository'] + '/' + plugin_name
147147
required_version = info['bot_version']
148148
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)
150154
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)
152160
if plugin_name in self.bot.cogs.keys():
153161
# 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)
155167

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)
157173
async with ctx.typing():
158174
if len(plugin_name.split('/')) >= 3:
159175
parsed_plugin = self.parse_plugin(plugin_name)
160176

161177
try:
162178
await self.download_plugin_repo(*parsed_plugin[:-1])
163179
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
166183
)
184+
return await ctx.send(embed=em)
167185

168186
importlib.invalidate_caches()
169187
try:
170188
await self.load_plugin(*parsed_plugin)
171189
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)
173195

174196
# if it makes it here, it has passed all checks and should
175197
# be entered into the config
176198

177199
self.bot.config.plugins.append(plugin_name)
178200
await self.bot.config.update()
179201

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)
182208
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)
185214

186215
@plugin.command(name='remove', aliases=['del', 'delete', 'rm'])
187216
@checks.has_permissions(PermissionLevel.OWNER)
@@ -196,7 +225,7 @@ async def plugin_remove(self, ctx, *, plugin_name: str):
196225
self.bot.unload_extension(
197226
f'plugins.{username}-{repo}.{name}.{name}'
198227
)
199-
except:
228+
except Exception:
200229
pass
201230

202231
self.bot.config.plugins.remove(plugin_name)
@@ -219,10 +248,17 @@ def onerror(func, path, exc_info): # pylint: disable=W0613
219248
raise exc
220249

221250
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)
224256
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)
226262

227263
@plugin.command(name='update')
228264
@checks.has_permissions(PermissionLevel.OWNER)
@@ -232,7 +268,11 @@ async def plugin_update(self, ctx, *, plugin_name: str):
232268
info = self.registry[plugin_name]
233269
plugin_name = info['repository'] + '/' + plugin_name
234270
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)
236276

237277
async with ctx.typing():
238278
username, repo, name = self.parse_plugin(plugin_name)
@@ -245,10 +285,18 @@ async def plugin_update(self, ctx, *, plugin_name: str):
245285
)
246286
except subprocess.CalledProcessError as exc:
247287
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)
249293
else:
250294
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)
252300

253301
if output != 'Already up to date.':
254302
# repo was updated locally, now perform the cog reload
@@ -257,21 +305,33 @@ async def plugin_update(self, ctx, *, plugin_name: str):
257305
try:
258306
await self.load_plugin(username, repo, name)
259307
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)
261313

262314
@plugin.command(name='enabled', aliases=['installed'])
263315
@checks.has_permissions(PermissionLevel.OWNER)
264316
async def plugin_enabled(self, ctx):
265317
"""Shows a list of currently enabled plugins."""
266318
if self.bot.config.plugins:
267319
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)
269325
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)
271331

272332
@plugin.command(name='registry', aliases=['list'])
273333
@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):
275335
"""Shows a list of all approved plugins."""
276336

277337
await self.populate_registry()
@@ -293,9 +353,9 @@ def find_index(name):
293353
index = find_index(plugin_name)
294354
elif plugin_name is not None:
295355
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+
)
299359

300360
matches = get_close_matches(plugin_name, self.registry.keys())
301361
if matches:
@@ -311,11 +371,11 @@ def find_index(name):
311371
url=repo,
312372
title=info['repository']
313373
)
314-
374+
315375
em.add_field(
316-
name='Installation',
376+
name='Installation',
317377
value=f'```{self.bot.prefix}plugins add {name}```')
318-
378+
319379
em.set_author(name=info['title'], icon_url=info.get('icon_url'))
320380
if info.get('thumbnail_url'):
321381
em.set_thumbnail(url=info.get('thumbnail_url'))
@@ -327,6 +387,5 @@ def find_index(name):
327387
await paginator.run()
328388

329389

330-
331390
def setup(bot):
332391
bot.add_cog(Plugins(bot))

0 commit comments

Comments
 (0)