urlinfo: fix handler selection
This commit is contained in:
parent
15c3cb0221
commit
d84f82768d
1 changed files with 12 additions and 10 deletions
|
|
@ -215,6 +215,11 @@ def full_url(ref: str) -> str:
|
||||||
return f"http://{ref}" if ref.startswith("www") else ref
|
return f"http://{ref}" if ref.startswith("www") else ref
|
||||||
|
|
||||||
|
|
||||||
|
class GenericHandler:
|
||||||
|
extractor = generic_extractor
|
||||||
|
handle = generic_handler
|
||||||
|
|
||||||
|
|
||||||
async def handle(message: Message):
|
async def handle(message: Message):
|
||||||
if message.command and message.command not in {"u", "url"}:
|
if message.command and message.command not in {"u", "url"}:
|
||||||
return
|
return
|
||||||
|
|
@ -229,18 +234,15 @@ async def handle(message: Message):
|
||||||
for url in urls:
|
for url in urls:
|
||||||
for handler in handlers:
|
for handler in handlers:
|
||||||
if handler.can_handle(url):
|
if handler.can_handle(url):
|
||||||
handler = handler.handle
|
|
||||||
extractor = handler.extractor
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if not (
|
# We only want the generic handler if we were called explicitly
|
||||||
message.command
|
handler = GenericHandler if message.command else None
|
||||||
): # We only want the generic handler if we were called explicitly
|
|
||||||
continue
|
|
||||||
handler = generic_handler
|
|
||||||
extractor = generic_extractor
|
|
||||||
|
|
||||||
info = await load_info(url, extractor, cachetoken())
|
if handler is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
info = await load_info(url, handler.extractor, cachetoken())
|
||||||
if not info:
|
if not info:
|
||||||
continue
|
continue
|
||||||
await handler(message, url, info)
|
await handler.handle(message, url, info)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue