feat: reply to all html files with their content

main
mandlm 2022-11-29 16:58:54 +01:00
commit 27a29a604a
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
7 changed files with 112 additions and 0 deletions

9
.envrc Normal file
View File

@ -0,0 +1,9 @@
use flake .nix
dotenv_if_exists
if on_git_branch; then
echo
git status --short --branch
echo
git fetch
fi

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
maubot-htmlfile.zip

43
.nix/flake.lock Normal file
View File

@ -0,0 +1,43 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1669597967,
"narHash": "sha256-R+2NaDkXsYkOpFOhmVR8jBZ77Pq55Z6ilaqwFLLn000=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "be9e3762e719211368d186f547f847737baad720",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

20
.nix/flake.nix Normal file
View File

@ -0,0 +1,20 @@
{
description = "A basic flake with a shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShell = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
zip
];
};
}
);
}

7
Makefile Normal file
View File

@ -0,0 +1,7 @@
plugin: maubot.yaml htmlfile.py
zip -9r maubot-htmlfile.zip maubot.yaml htmlfile.py
clean:
rm maubot-htmlfile.zip
all: plugin

25
htmlfile.py Normal file
View File

@ -0,0 +1,25 @@
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)

7
maubot.yaml Normal file
View File

@ -0,0 +1,7 @@
maubot: 0.1.0
id: net.molez.maubot.htmlfile
version: 0.1.0
license: MIT
modules:
- htmlfile
main_class: HtmlFile