My First Rust Crate!

3 years after my first contact with Rust, I finally published my first crate in the Rust ecosystem :D.

Caith

Without any more ceremony, here is caith, a dice expression parser and roller. For the record, I came into writing this because I manage to go back playing some RPG. Not the video game kind, the proper, tabletop one ;) But as I’m a migrant, in order to play with my friends over there in France, we have to use some kind of audio call software. And as we all are gamers, we were already using Discord to play video games together.

But to play a tabletop RPG, you need to roll dice. We could use roll20 but as our GM didn’t need any map, having everyone creating an account just to roll dice felt overkill. So I manage to install a dice roller bot on our Discord server. It was using /roll command to trigger but as it was not "verified" by Discord, I kept looking and found another one with the trustworthy "verified" label on it. It uses !roll as a trigger and one of the friend jokingly complained about the ! instead of /. I was like "Hold my drink" and here I was, typing cargo new….

I looked around crates.io to find a lib to parse dice roll expression and couldn’t find any that suit my needs, especially "exploding dice": caith was born! I basically reimplemented everything Dice Maiden provide, from exploded dice, to keep/drop high/low result. On top of that, I added Fudge/Fate dice support. The implementation was a blast thanks to pest, the parser generator crate. I discovered it was able to walk the AST while respecting operations’ priorities. Thanks to the crate rouler for teaching me that!

Dìsle

On top of caith, I built a Discord bot using the serenity crate and here again, it was straightforward. The only caveats was the lack of async support but it was work in progress on a branch which I chose to use. Since, the branch has been merged and an RC has been released :D

The bot’s main job is to gather the dice expression and pass it to caith. But I added a few functionalities to ease my gaming session:

  • /reroll or /rr to replay the last dice expression of the user
  • /reroll_dice or /rd to reroll the first found dice of the last expression (handy in games like Shadows of Esteren)

After that, one could think the bot is pretty complete but I had another itch to satisfy: aliases. I’m planning to master Feng Shui 2 and in this system, we launch 1d6 - 1d6 but if one of the dice is 6, we reroll it and add to the result (it explodes on 6) and if it’s a 6 again, we reroll etc… giving us this expression: 1d6ie6 - 1d6ie6 (ie = indefinite explode) which is quite lengthy to type every time. We can copy paste it, but I felt that an alias management system would be more efficient :D Giving it some though, the need of a permission system to manage who is allowed to tamper the aliases should be created to avoid "jokes" on setting the aliases.

After about twenty hours of cumulative work on it, I consider Dìsle feature complete :D I don’t provide a public instance as I don’t want to overwhelm my small VPS but instructions to create your own instance is provided.

The Names

Oh, if ever you’re wondering what’s about these names, they are Gaelic for "throw" and "dice" :D

Happy dice rolling!