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
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue