diff --git a/hotdog/command/urlinfo.py b/hotdog/command/urlinfo.py index 2d329de..feaf10d 100644 --- a/hotdog/command/urlinfo.py +++ b/hotdog/command/urlinfo.py @@ -215,6 +215,11 @@ def full_url(ref: str) -> str: return f"http://{ref}" if ref.startswith("www") else ref +class GenericHandler: + extractor = generic_extractor + handle = generic_handler + + async def handle(message: Message): if message.command and message.command not in {"u", "url"}: return @@ -229,18 +234,15 @@ async def handle(message: Message): for url in urls: for handler in handlers: if handler.can_handle(url): - handler = handler.handle - extractor = handler.extractor break else: - if not ( - message.command - ): # We only want the generic handler if we were called explicitly - continue - handler = generic_handler - extractor = generic_extractor + # We only want the generic handler if we were called explicitly + handler = GenericHandler if message.command else None - info = await load_info(url, extractor, cachetoken()) + if handler is None: + continue + + info = await load_info(url, handler.extractor, cachetoken()) if not info: continue - await handler(message, url, info) + await handler.handle(message, url, info)