diff options
| author | 2019-11-10 21:30:26 +0100 | |
|---|---|---|
| committer | 2019-11-10 21:30:26 +0100 | |
| commit | 219cde70f03476ac6ae4a7f84322757bebeec51e (patch) | |
| tree | 992c1ca18194006db7e3e805b002515550acf987 | |
| parent | Move paragraph search to not cut off long starting paragraphs (diff) | |
Add a command for refreshing inventories
| -rw-r--r-- | bot/cogs/doc.py | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/bot/cogs/doc.py b/bot/cogs/doc.py index 73895e3eb..8cf32fc7f 100644 --- a/bot/cogs/doc.py +++ b/bot/cogs/doc.py @@ -447,6 +447,28 @@ class Doc(commands.Cog):              await self.refresh_inventory()          await ctx.send(f"Successfully deleted `{package_name}` and refreshed inventory.") +    @docs_group.command(name="refresh", aliases=("rfsh", "r")) +    @with_role(*MODERATION_ROLES) +    async def refresh_command(self, ctx: commands.Context) -> None: +        """Refresh inventories and send differences to channel.""" +        old_inventories = set(self.base_urls) +        with ctx.typing(): +            await self.refresh_inventory() +        # Get differences of added and removed inventories +        added = ', '.join(inv for inv in self.base_urls if inv not in old_inventories) +        if added: +            added = f"`+ {added}`" + +        removed = ', '.join(inv for inv in old_inventories if inv not in self.base_urls) +        if removed: +            removed = f"`- {removed}`" + +        embed = discord.Embed( +            title="Inventories refreshed", +            description=f"{added}\n{removed}" if added or removed else "" +        ) +        await ctx.send(embed=embed) +      async def _fetch_inventory(self, inventory_url: str, config: SphinxConfiguration) -> Optional[dict]:          """Get and return inventory from `inventory_url`. If fetching fails, return None."""          fetch_func = functools.partial(intersphinx.fetch_inventory, config, '', inventory_url) | 
