feat: parse matrix staged attachment commands
This commit is contained in:
parent
0eaf124e21
commit
83c9a1513b
2 changed files with 100 additions and 17 deletions
|
|
@ -14,42 +14,52 @@ PLATFORM = "matrix"
|
|||
|
||||
|
||||
def extract_attachments(event: Any) -> list[Attachment]:
|
||||
content = getattr(event, "content", {}) or {}
|
||||
msgtype = getattr(event, "msgtype", None)
|
||||
if msgtype is None:
|
||||
content = getattr(event, "content", {}) or {}
|
||||
msgtype = content.get("msgtype")
|
||||
url = content.get("url") or getattr(event, "url", None)
|
||||
filename = content.get("body") or getattr(event, "body", None)
|
||||
mime_type = content.get("mimetype") or getattr(event, "mimetype", None)
|
||||
if mime_type is None:
|
||||
info = content.get("info") or {}
|
||||
if isinstance(info, dict):
|
||||
mime_type = info.get("mimetype")
|
||||
|
||||
if msgtype == "m.image":
|
||||
return [
|
||||
Attachment(
|
||||
type="image",
|
||||
url=getattr(event, "url", None),
|
||||
mime_type=getattr(event, "mimetype", None),
|
||||
url=url,
|
||||
filename=filename,
|
||||
mime_type=mime_type,
|
||||
)
|
||||
]
|
||||
if msgtype == "m.file":
|
||||
return [
|
||||
Attachment(
|
||||
type="document",
|
||||
url=getattr(event, "url", None),
|
||||
filename=getattr(event, "body", None),
|
||||
mime_type=getattr(event, "mimetype", None),
|
||||
url=url,
|
||||
filename=filename,
|
||||
mime_type=mime_type,
|
||||
)
|
||||
]
|
||||
if msgtype == "m.audio":
|
||||
return [
|
||||
Attachment(
|
||||
type="audio",
|
||||
url=getattr(event, "url", None),
|
||||
mime_type=getattr(event, "mimetype", None),
|
||||
url=url,
|
||||
filename=filename,
|
||||
mime_type=mime_type,
|
||||
)
|
||||
]
|
||||
if msgtype == "m.video":
|
||||
return [
|
||||
Attachment(
|
||||
type="video",
|
||||
url=getattr(event, "url", None),
|
||||
mime_type=getattr(event, "mimetype", None),
|
||||
url=url,
|
||||
filename=filename,
|
||||
mime_type=mime_type,
|
||||
)
|
||||
]
|
||||
return []
|
||||
|
|
@ -75,6 +85,24 @@ def from_command(body: str, sender: str, chat_id: str, room_id: str | None = Non
|
|||
},
|
||||
)
|
||||
|
||||
if command == "list" and not args:
|
||||
return IncomingCommand(
|
||||
user_id=sender,
|
||||
platform=PLATFORM,
|
||||
chat_id=chat_id,
|
||||
command="matrix_list_attachments",
|
||||
args=[],
|
||||
)
|
||||
|
||||
if command == "remove" and len(args) == 1:
|
||||
return IncomingCommand(
|
||||
user_id=sender,
|
||||
platform=PLATFORM,
|
||||
chat_id=chat_id,
|
||||
command="matrix_remove_attachment",
|
||||
args=[args[0]],
|
||||
)
|
||||
|
||||
aliases = {
|
||||
"skills": "settings_skills",
|
||||
"connectors": "settings_connectors",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue