astrbot_plugin_imagestudio/adapters/astrbot_media_adapter.py

20 行
782 B
Python

"""Extract image references from AstrBot message components."""
from __future__ import annotations
from typing import Any
def image_references_from_event(event: Any) -> list[str]:
message_obj = getattr(event, "message_obj", None)
chain = getattr(message_obj, "message", None) or getattr(event, "message_chain", None) or []
references: list[str] = []
for component in chain if isinstance(chain, (list, tuple)) else []:
if "image" not in component.__class__.__name__.lower():
continue
for name in ("url", "file", "path", "image_url"):
text = str(getattr(component, name, None) or "").strip()
if text and text not in references:
references.append(text)
break
return references