Exemplo n.º 1
0
    async def plugin_registry(self, ctx, *, plugin_name: str = None):
        """Shows a list of all approved plugins."""

        await self.populate_registry()

        embeds = []

        registry = list(self.registry.items())
        random.shuffle(registry)

        def find_index(name):
            index = 0
            for n, info in registry:
                if name == n:
                    return index
                index += 1

        index = 0
        if plugin_name in self.registry:
            index = find_index(plugin_name)
        elif plugin_name is not None:
            em = discord.Embed(
                color=discord.Color.red(),
                description=
                f'Could not find a plugin with name "{plugin_name}" within the registry.'
            )

            matches = get_close_matches(plugin_name, self.registry.keys())
            if matches:
                em.add_field(name='Perhaps you meant',
                             value='\n'.join(f'`{m}`' for m in matches))
            return await ctx.send(embed=em)

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

            em = discord.Embed(color=self.bot.main_color,
                               description=info['description'],
                               url=repo,
                               title=info['repository'])

            em.add_field(name='Installation',
                         value=f'```{self.bot.prefix}plugins add {name}```')

            em.set_author(name=info['title'],
                          icon_url=info.get('icon_url'),
                          url=url)
            if info.get('thumbnail_url'):
                em.set_thumbnail(url=info.get('thumbnail_url'))
            if info.get('image_url'):
                em.set_image(url=info.get('image_url'))

            embeds.append(em)

        paginator = PaginatorSession(ctx, *embeds)
        paginator.current = index
        await paginator.run()
Exemplo n.º 2
0
    async def plugin_registry(self, ctx, *, plugin_name: str = None):
        """Shows a list of all approved plugins."""

        await self.populate_registry()

        embeds = []

        registry = list(self.registry.items())
        random.shuffle(registry)

        def find_index(find_name):
            for i, (n, _) in enumerate(registry):
                if find_name == n:
                    return i

        index = 0
        if plugin_name in self.registry:
            index = find_index(plugin_name)
        elif plugin_name is not None:
            embed = discord.Embed(
                color=discord.Color.red(),
                description=
                f'Could not find a plugin with name "{plugin_name}" within the registry.',
            )

            matches = get_close_matches(plugin_name, self.registry.keys())

            if matches:
                embed.add_field(
                    name="Perhaps you meant:",
                    value="\n".join(f"`{m}`" for m in matches),
                )

            return await ctx.send(embed=embed)

        for name, details in registry:
            repo = f"https://github.com/{details['repository']}"
            url = f"{repo}/tree/master/{name}"

            embed = discord.Embed(
                color=self.bot.main_color,
                description=details["description"],
                url=repo,
                title=details["repository"],
            )

            embed.add_field(name="Installation",
                            value=f"```{self.bot.prefix}plugins add {name}```")

            embed.set_author(name=details["title"],
                             icon_url=details.get("icon_url"),
                             url=url)
            if details.get("thumbnail_url"):
                embed.set_thumbnail(url=details.get("thumbnail_url"))
            if details.get("image_url"):
                embed.set_image(url=details.get("image_url"))

            embeds.append(embed)

        paginator = PaginatorSession(ctx, *embeds)
        paginator.current = index
        await paginator.run()