diff options
| author | 2021-01-11 00:54:37 +0100 | |
|---|---|---|
| committer | 2021-01-11 02:21:31 +0100 | |
| commit | 760ca7e9a0996865ee4d9e127baef8f0246a9e25 (patch) | |
| tree | cb543f3c9e3b4823ab2f5167c30c1394bb2392cc | |
| parent | Resolve wrapped command callbacks in the source command (diff) | |
Send a message to devlog instead of logging a warning
| -rw-r--r-- | bot/exts/info/doc/_batch_parser.py | 30 | ||||
| -rw-r--r-- | bot/exts/info/doc/_parsing.py | 1 |
2 files changed, 30 insertions, 1 deletions
diff --git a/bot/exts/info/doc/_batch_parser.py b/bot/exts/info/doc/_batch_parser.py index edd6bb090..ebae6efb8 100644 --- a/bot/exts/info/doc/_batch_parser.py +++ b/bot/exts/info/doc/_batch_parser.py @@ -9,9 +9,11 @@ from functools import partial from operator import attrgetter from typing import Dict, List, NamedTuple, TYPE_CHECKING, Union +import discord from bs4 import BeautifulSoup import bot +from bot.constants import Channels from . import doc_cache from ._parsing import get_symbol_markdown if TYPE_CHECKING: @@ -20,6 +22,30 @@ if TYPE_CHECKING: log = logging.getLogger(__name__) +class StaleInventoryNotifier: + """Handle sending notifications about stale inventories through `DocItem`s to dev log.""" + + def __init__(self): + self._init_task = bot.instance.loop.create_task(self._init_channel()) + self._warned_urls = set() + + async def _init_channel(self) -> None: + """Wait for guild and get channel.""" + await bot.instance.wait_until_guild_available() + self._dev_log = bot.instance.get_channel(Channels.dev_log) + + async def send_warning(self, item: DocItem) -> None: + """Send a warning to dev log is one wasn't already sent for `item`'s url.""" + if item.url not in self._warned_urls: + self._warned_urls.add(item.url) + await self._init_task + embed = discord.Embed( + description=f"Doc item `{item.symbol_id=}` present in loaded documentation inventories " + f"not found on [site]({item.url}), inventories may need to be refreshed." + ) + await self._dev_log.send(embed=embed) + + class QueueItem(NamedTuple): """Contains a symbol and the BeautifulSoup object needed to parse it.""" @@ -71,6 +97,8 @@ class BatchParser: self.cleanup_futures_task = bot.instance.loop.create_task(self._cleanup_futures()) + self.stale_inventory_notifier = StaleInventoryNotifier() + async def get_markdown(self, doc_item: DocItem) -> str: """ Get the result Markdown of `doc_item`. @@ -120,6 +148,8 @@ class BatchParser: ) if markdown is not None: await doc_cache.set(item, markdown) + else: + asyncio.create_task(self.stale_inventory_notifier.send_warning(item)) except Exception as e: log.exception(f"Unexpected error when handling {item}") future.set_exception(e) diff --git a/bot/exts/info/doc/_parsing.py b/bot/exts/info/doc/_parsing.py index d68f7c8d7..257161dd5 100644 --- a/bot/exts/info/doc/_parsing.py +++ b/bot/exts/info/doc/_parsing.py @@ -231,7 +231,6 @@ def get_symbol_markdown(soup: BeautifulSoup, symbol_data: DocItem) -> Optional[s """ symbol_heading = soup.find(id=symbol_data.symbol_id) if symbol_heading is None: - log.warning("Symbol present in loaded inventories not found on site, consider refreshing inventories.") return None signature = None # Modules, doc pages and labels don't point to description list tags but to tags like divs, |