aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2020-11-10 04:03:23 +0100
committerGravatar Numerlor <[email protected]>2020-11-10 04:03:23 +0100
commitfaaa85d2d00a2bc7496965fad3f5f53f56718e9c (patch)
treed6ce9f8559939fbb34c4b7b6316bd160ec03907e
parentSimplify duplicate symbol name handling code (diff)
Move InventoryURL converer to the converters file
-rw-r--r--bot/converters.py20
-rw-r--r--bot/exts/info/doc/_cog.py23
2 files changed, 22 insertions, 21 deletions
diff --git a/bot/converters.py b/bot/converters.py
index 6c87a50fe..3066eaabb 100644
--- a/bot/converters.py
+++ b/bot/converters.py
@@ -15,6 +15,7 @@ from discord.utils import DISCORD_EPOCH, snowflake_time
from bot.api import ResponseCodeError
from bot.constants import URLs
+from bot.exts.info.doc import _inventory_parser
from bot.utils.regex import INVITE_RE
log = logging.getLogger(__name__)
@@ -175,6 +176,25 @@ class ValidURL(Converter):
return url
+class InventoryURL(Converter):
+ """
+ Represents an Intersphinx inventory URL.
+
+ This converter checks whether intersphinx accepts the given inventory URL, and raises
+ `BadArgument` if that is not the case.
+
+ Otherwise, it simply passes through the given URL.
+ """
+
+ @staticmethod
+ async def convert(ctx: Context, url: str) -> str:
+ """Convert url to Intersphinx inventory URL."""
+ await ctx.trigger_typing()
+ if await _inventory_parser.fetch_inventory(ctx.bot.http_session, url) is None:
+ raise BadArgument(f"Failed to fetch inventory file after {_inventory_parser.FAILED_REQUEST_ATTEMPTS}.")
+ return url
+
+
class Snowflake(IDConverter):
"""
Converts to an int if the argument is a valid Discord snowflake.
diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py
index ee89f5384..25477fe07 100644
--- a/bot/exts/info/doc/_cog.py
+++ b/bot/exts/info/doc/_cog.py
@@ -16,11 +16,11 @@ from discord.ext import commands
from bot.bot import Bot
from bot.constants import MODERATION_ROLES, RedirectOutput
-from bot.converters import PackageName, ValidURL
+from bot.converters import InventoryURL, PackageName, ValidURL
from bot.pagination import LinePaginator
from bot.utils.messages import wait_for_deletion
from bot.utils.scheduling import Scheduler
-from ._inventory_parser import FAILED_REQUEST_ATTEMPTS, fetch_inventory
+from ._inventory_parser import fetch_inventory
from ._parsing import get_symbol_markdown
from ._redis_cache import DocRedisCache
@@ -159,25 +159,6 @@ class CachedParser:
self._item_events.clear()
-class InventoryURL(commands.Converter):
- """
- Represents an Intersphinx inventory URL.
-
- This converter checks whether intersphinx accepts the given inventory URL, and raises
- `BadArgument` if that is not the case.
-
- Otherwise, it simply passes through the given URL.
- """
-
- @staticmethod
- async def convert(ctx: commands.Context, url: str) -> str:
- """Convert url to Intersphinx inventory URL."""
- await ctx.trigger_typing()
- if await fetch_inventory(ctx.bot.http_session, url) is None:
- raise commands.BadArgument(f"Failed to fetch inventory file after {FAILED_REQUEST_ATTEMPTS}.")
- return url
-
-
class DocCog(commands.Cog):
"""A set of commands for querying & displaying documentation."""