aboutsummaryrefslogtreecommitdiff
path: root/src/commands/roll.rs
blob: 16fe15f34555e9aa7cbf985bca3839d70188405b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::util;
use grate::tracing;

/// Roll some number of dice or perform a calculation.
#[poise::command(prefix_command, guild_only, aliases("calc", "calculate"))]
pub async fn roll<U: Send + Sync>(
    ctx: poise::Context<'_, U, anyhow::Error>,
    #[rest] rest: String,
) -> anyhow::Result<()> {
    match thulani_calc::Calc::eval(&rest) {
        Ok(result) => {
            tracing::debug!("got calc result '{}'", result);
            util::reply(ctx, result.to_string()).await?;
        },
        Err(e) => {
            tracing::error!("error encountered reading calc '{}': {}", rest, e);
            util::reply(ctx, "I COULDN'T READ THAT YOU FUCK").await?;
        },
    }

    Ok(())
}