diff --git a/src/discord/joke.rs b/src/discord/joke.rs index 34ba432..b0c5d12 100644 --- a/src/discord/joke.rs +++ b/src/discord/joke.rs @@ -10,6 +10,10 @@ use serenity::framework::standard::{Args, CommandResult}; use serenity::model::channel::Message; use std::collections::HashMap; +#[group] +#[commands(dad_joke, fortune, roll)] +pub struct Joke; + #[derive(Clone, Serialize, Deserialize)] struct DadJoke { pub id: String, @@ -17,10 +21,6 @@ struct DadJoke { pub status: i32, } -#[group] -#[commands(dad_joke, fortune)] -pub struct Joke; - #[command] #[only_in(guilds)] #[aliases("dad")] @@ -104,3 +104,20 @@ async fn fortune(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { Ok(()) } + +#[command] +#[only_in(guilds)] +#[aliases("roll")] +#[description("Roll a die!")] +async fn roll(ctx: &Context, msg: &Message, args: Args) -> CommandResult { + let roll = args.rest().parse::(); + + let reply = match roll { + Ok(roll) => format!("You rolled: **{}**", roll), + Err(_) => "Error parsing dice roll".to_string(), + }; + + msg.reply(&ctx.http, reply).await?; + + Ok(()) +}