feat: reply to all html files with their content
This commit is contained in:
commit
27a29a604a
9
.envrc
Normal file
9
.envrc
Normal 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
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
maubot-htmlfile.zip
|
43
.nix/flake.lock
Normal file
43
.nix/flake.lock
Normal 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
20
.nix/flake.nix
Normal 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
7
Makefile
Normal 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
25
htmlfile.py
Normal 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
7
maubot.yaml
Normal 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
|
Reference in New Issue
Block a user