Skip to content

Commit

Permalink
Use MSC2530 event format for inline message
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Groocock <[email protected]>
  • Loading branch information
frebib committed Mar 22, 2024
1 parent 4f16106 commit 3e5e19f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion maubot.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
maubot: 0.1.0
id: xyz.maubot.xkcd
version: 1.2.0
version: 1.2.1
license: AGPL-3.0-or-later
modules:
- xkcd
Expand Down
30 changes: 17 additions & 13 deletions xkcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
except ImportError:
Image = None


@dataclass
class XKCDInfo(SerializableAttrs):
year: str
Expand Down Expand Up @@ -246,21 +245,26 @@ async def _send_xkcd(self, room_id: RoomID, xkcd: XKCDInfo) -> None:
content["license_url"] = "https://xkcd.com/license.html"
await self.client.send_message(room_id, content)
else:
await self.client.send_text(room_id, text=f"{xkcd.num}: **{xkcd.title}**",
html=f"{xkcd.num}: <strong>{xkcd.safe_title}</strong>")
content = MediaMessageEventContent(url=info.mxc_uri, body=info.file_name,
msgtype=MessageType.IMAGE,
external_url=f"https://xkcd.com/{xkcd.num}",
info=ImageInfo(
mimetype=info.mime_type,
size=info.size,
width=info.width,
height=info.height,
),)
content = MediaMessageEventContent(
msgtype=MessageType.IMAGE,
format=Format.HTML,
external_url=f"https://xkcd.com/{xkcd.num}",
url=info.mxc_uri,
filename=info.file_name,
body=f"{xkcd.num}: **{xkcd.title}**\n{xkcd.alt}",
formatted_body=f"{xkcd.num}: <strong>{xkcd.safe_title}</strong>"
f"<br/><i>{xkcd.alt}</i>",
info=ImageInfo(
mimetype=info.mime_type,
size=info.size,
width=info.width,
height=info.height,
),
)
content["license"] = "CC-BY-NC-2.5"
content["license_url"] = "https://xkcd.com/license.html"

await self.client.send_message(room_id, content)
await self.client.send_text(room_id, text=xkcd.alt)

async def broadcast(self, xkcd: XKCDInfo) -> None:
self.log.debug(f"Broadcasting xkcd {xkcd.num}")
Expand Down

0 comments on commit 3e5e19f

Please sign in to comment.