26 lines
972 B
Python
26 lines
972 B
Python
|
from mautrix.types import EventType, MessageType
|
||
|
from mautrix.crypto import attachments
|
||
|
|
||
|
from maubot import Plugin, MessageEvent
|
||
|
from maubot.handlers import event
|
||
|
|
||
|
|
||
|
class HtmlFile(Plugin):
|
||
|
@event.on(EventType.ROOM_MESSAGE)
|
||
|
async def event_handler(self, event: MessageEvent) -> None:
|
||
|
|
||
|
# self.log.debug(f"received: {event}")
|
||
|
|
||
|
if not event.content.msgtype == MessageType.FILE:
|
||
|
return
|
||
|
|
||
|
if event.content.info.mimetype == "text/html":
|
||
|
if event.content.url:
|
||
|
file_content = (await self.client.download_media(url = event.content.url)).decode("utf-8")
|
||
|
else:
|
||
|
enc_file = event.content.file
|
||
|
ciphertext = await self.client.download_media(url = enc_file.url)
|
||
|
file_content = attachments.decrypt_attachment(ciphertext, enc_file.key.key, enc_file.hashes["sha256"], enc_file.iv).decode("utf-8")
|
||
|
|
||
|
await event.reply(file_content, allow_html = True)
|