This is a fun weekend project where I've written a new generic Matrix bot framework. It is written in Rust from scratch using the fantastic matrix-rust-sdk crate.
Bot commands can be implemented as WebAssembly modules, using Wasmtime as the WebAssembly virtual machine, and wit-bindgen for conveniently implementing interfaces between the host and wasm modules.
See for instance the uuid
and horsejs
modules.
Modules can be hot-reloaded, making it trivial to deploy new modules, or replace existing modules already running on a server. It is also nice during development iterations on modules. Basically one can do the following to see changes in close to real-time:
- run trinity with
cargo run
cd modules/ && cargo watch -x "build --release"
in another terminal
The overall generic design is inspired from my previous bot, botzilla, that was written in JavaScript and was very specialized for Mozilla needs.
At this point I expect this to be more of a weekend project, so I won't commit to any of those, but here's my ideas of things to implement in the future. If you feel like implementing some of these ideas, please go ahead :)
- fetch and cache user names
- make it possible to answer privately / to the full room / as a reply to the original message / as a thread reply.
- admin / ACL module that allows to dynamically enable which commands are enabled in which matrix rooms
- add ability to set emojis on specific messages (? this was useful for the admin module in botzilla)
- key/value store + wit API so modules can remember things across loads, using redb on the host.
- moonshot: JS host so one can test the chat modules on a Web browser, without requiring a matrix
account
- marsshot: existing modules built from CI and pushed to a simple Web app on github-pages that allows selecting an individual module and trying it.
- seek other
TODO
in code :p
- post something on mastodon. Example:
!toot Something nice and full of care for the community out there
- this assumes a preconfigured room attached to a Mastodon account (via token), maybe ACLs to define who can post
- post on twitter. Example:
!tweet Inflammatory take that will receive millions of likes and quote-tweets
- same requirements as mastodon, likely
- gitlab auto-link to issues/merge requests: e.g. if someone types
!123
, post a link tohttps://{GITLAB_REPO_URL}/-/issues/123
.- would require the room to be configured with a gitlab repository
- same for github would be sweet
- ask what's the weather in some city, is it going to rain in the next hour, etc.
- YOUR BILLION DOLLARS IDEA HERE
Yes.
We welcome community contributions to this project.
This is a Matrix bot, coded in Rust and WebAssembly, forming a holy trinity of technologies I love. And, Trinity is also a bad-ass character from the Matrix movie franchise.