Skip to content

Commit 7144ea0

Browse files
committed
Add a compact view command for registry
1 parent 0145c53 commit 7144ea0

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

cogs/plugins.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ async def plugin_enabled(self, ctx):
269269
else:
270270
await ctx.send('No plugins installed.')
271271

272-
@plugin.command(name='registry', aliases=['list'])
272+
@plugin.group(invoke_without_command=True, name='registry', aliases=['list'])
273273
@checks.has_permissions(PermissionLevel.OWNER)
274274
async def plugin_registry(self, ctx, *, plugin_name:str=None):
275275
"""Shows a list of all approved plugins."""
@@ -304,6 +304,7 @@ def find_index(name):
304304

305305
for name, info in registry:
306306
repo = f"https://github.com/{info['repository']}"
307+
url = f"{repo}/tree/master/name"
307308

308309
em = discord.Embed(
309310
color=self.bot.main_color,
@@ -316,16 +317,57 @@ def find_index(name):
316317
name='Installation',
317318
value=f'```{self.bot.prefix}plugins add {name}```')
318319

319-
em.set_author(name=info['title'], icon_url=info.get('icon_url'))
320+
em.set_author(name=info['title'], icon_url=info.get('icon_url'), url=url)
320321
if info.get('thumbnail_url'):
321322
em.set_thumbnail(url=info.get('thumbnail_url'))
323+
if info.get('image_url'):
324+
em.set_image(url=info.get('image_url'))
322325

323326
embeds.append(em)
324327

325328
paginator = PaginatorSession(ctx, *embeds)
326329
paginator.current = index
327330
await paginator.run()
328331

332+
@plugin_registry.command(name='compact')
333+
async def plugin_registry_compact(self, ctx):
334+
"""Shows a compact view of all plugins within the registry."""
335+
336+
await self.populate_registry()
337+
338+
registry = list(self.registry.items())
339+
registry.sort(key=lambda elem: elem[0])
340+
341+
pages = ['']
342+
343+
for name, info in registry:
344+
repo = f"https://github.com/{info['repository']}"
345+
url = f"{repo}/tree/master/{name}"
346+
desc = info['description'].replace('\n', '')
347+
fmt = f"[`{name}`]({url}) - {desc}"
348+
length = len(fmt) - len(url) - 4
349+
fmt = fmt[:75 + len(url)].strip() + '...' if length > 75 else fmt
350+
if len(fmt) + len(pages[-1]) >= 1024:
351+
pages.append(fmt+'\n')
352+
else:
353+
pages[-1] += fmt + '\n'
354+
355+
embeds = []
356+
357+
for page in pages:
358+
em = discord.Embed(
359+
color=self.bot.main_color,
360+
description=page,
361+
title='Plugin Registry (Compact View)',
362+
)
363+
embeds.append(em)
364+
365+
paginator = PaginatorSession(ctx, *embeds)
366+
await paginator.run()
367+
368+
369+
370+
329371

330372

331373
def setup(bot):

0 commit comments

Comments
 (0)