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

/// 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) => {
            log::debug!("got calc result '{}'", result);
            util::reply(ctx, result.to_string()).await?;
        },
        Err(e) => {
            log::error!("error encountered reading calc '{}': {}", rest, e);
            util::reply(ctx, "I COULDN'T READ THAT YOU FUCK").await?;
        },
    }

    Ok(())
}