dazgupta.com > posts.xml 2> journal.xml

Discord bot & the "Cult of done"

Last time I tried writing a Discord bot, it was a few years ago & it was a heck tonne of work. I was writing it in Elixir, which I was learning at that time. I was using the HTTP method of getting information from Discord's servers instead their WebSocker interface and I was reading and implementing code according to the documentation of Discord one by one. This was a lot of work, but I eventually made a hangman game for my friends. I did never fully learn how to deploy Erlang applications properly and the BEAM runtime installation on my cloud server was somewhat broken. Even though I had a lot of fun building the game, I never really ended up enjoying Elixir, neither did I learn how to use it correctly. And so, few months ago while migrating my websites etc. to a new cloud provider, I shut down the hangman game; I couldn't be bothered to figure out how to deploy the service again.

Fast forward to now, I now write quite a bit of Rust at work so I thought of writing a conversational bot built on my promptgen language, in Rust. I considered learning Go for this project, but I decided against it even though it's clearly a better fit. For weekend projects, learning multiple things at a time usually never goes well for me and go to bed on Sunday night frustrated.

ChatGPT

I sometimes tend ask to help me writing some code, but when I did that it failed to generate anything that compiles or easy to fix (like the last two times I tried). Specially given Rust's strict compiler, it was really hard to end up with working code. But I did manage to discover Rust libraries in the process.

So I started creating a Discord bot around my promptgen state machine. The borrow checker was a pain to deal with, but after fussing around Friday & Saturday I had something running and deployed to the cloud. The next morning, today, my friends started to abuse the bot to a point where I shut it down, and coded up another bot. This bot simply responds with a text when anyone is mentioned, depending on what they have chosen.

The second try

This time however, it was fair bit easier to write, I finished writing and deploying it within two hours or so and now I am writing this post. Although, the data structures involved in this bot's process is fair bit simpler I feel oddly at home with writing Discord bots with this set of libraries that I found. I learned quite a bit about async computing, tokio etc.

Learning about satifcation

It's oddly satisfying to get something out of the door and in production, even if it is a weekend project. I don't like to think learning an app platform like Discord is particularly useful or satisfying; but in the process, I also learned a lot about Rust's borrow checker and async programming. In the end, the libraries not only helped me focus on the but also the bot's behaviour and Rust itself to some extent, as any libraries do I suppose. But the true satisfaction cames from the fact that I was done with what I had set out to do for that day. And thinking about it afterwards, it goes with probably is the best bit of advice I got on the internet in recent years.

A word on cloud infrastructure

If whatever you toy project is, relies on running on a server it does help a lot to have a existing infrastructure to quickly deploy things on. I personally use podman and compose along with my own image registry to push images to, it all runs on a single machine in the cloud along with my other websites etc. It's secure enough & I have a nginx reverse proxy set up to deal with incoming traffic. This makes deploying things fair bit easier; otherwise figuring out deployment woes are usually never fun and can get very frustrating, ruining the joy of shipping.

25-08-2024