Article Information
Tagged as tech, chat, communication, rust
Written on

Screenshot of Weeabot

So I've been having some fun recently trying to teach myself Rust. I'm not really a programmer by any stretch of the imagination (yet!) but was challenged to write a bot for a Matrix chatroom I frequent. Most of us have written bots already, so it was my time to try something.

Originally I had planned to use Python like I had done previously for my Mastodon bot, tsukumogami. However, I'd been hearing some interesting things about Rust and decided it would be a fun challenge to try and write something functional in the language.


Weeabot's current features include the following:

Of these the Yandex call was definitely the hardest to get right. I had originally hoped to use a crate for this, but the one I found unfortunately didn't compile due to depending on old crates which had an old OpenSSL version. After spending some time trying to write the call myself I realised it was easier to fix the crate and use it anyway. I've since presented this fix to the original maintainer, so hopefully it will be usable again soon.

Some Observations

Rust is a challenging language for a newcomer as it is very strict about getting things right before compilation. This is the right thing to do, and thankfully the compiler is excellent at giving instruction on what is wrong and possible ways to fix it. But unlike Python (which really is a pick-up-and-play language in many ways), Rust really does not want you to run something that is broken.

Rust is also probably the wrong language for this project. While there is a nice ready-made matrix_bot_api crate, it is clear that the language is designed for more complex stuff than this. I would probably have had an easier time using a more web-oriented language. Originally the challenge had been to use Dlang, but I was much more interested in Rust.

Some Fun Stuff

So far I've learned a lot not just about Rust but also about Matrix, APIs, and deployment pipelines. As a joke, this bot (which essentially just posts shitposts that pastiche typical weeaboo-esque responses) has been set up with a fully functional test environment and pipeline for test, build, and deployment to a live server. This was an interesting challenge as I have previously understood bits and pieces about the process from my interactions with Netlify and Funkwhale, but have never set it up for myself before.

Another fun thing has been getting to play with Crates. Crates are amazingly helpful in giving you a good starting point to build from and feel much more convenient to me than Python libs. Most of this bot is just different crates stuck together, although I have actually pushed a fix for the yandex translation crate I used. So I'm not just a leech!

Anyway, the source code for the bot can be found on my Git server. There are still some features I want to get working, but I'm pretty happy with its performance thus far as a translation bot alone.