From 73be6b1d9f450bb29b0c7438c249e125998d0c66 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 10 Dec 2022 16:50:32 -0700 Subject: [PATCH] Added roll command + clippy + fmt --- src/discord/joke.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) 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(()) +}