diff --git a/src/config.rs b/src/config.rs index a5b301a..7a46f45 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,6 +21,7 @@ pub struct AlbumConfig { pub struct BotConfig { pub bot_token: String, pub imgur_client_id: String, + pub fortunes: Vec, #[serde(default)] pub albums: Vec, diff --git a/src/discord/joke.rs b/src/discord/joke.rs index 0c046fd..434d92a 100644 --- a/src/discord/joke.rs +++ b/src/discord/joke.rs @@ -1,4 +1,6 @@ -use crate::{command, group}; +use crate::{command, group, GlobalData}; +use rand::prelude::SliceRandom; +use rand::thread_rng; use reqwest::Client; use serde::{Deserialize, Serialize}; use serenity::client::Context; @@ -13,7 +15,7 @@ struct DadJoke { } #[group] -#[commands(dad_joke)] +#[commands(dad_joke, fortune)] pub struct Joke; #[command] @@ -35,3 +37,27 @@ async fn dad_joke(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { Ok(()) } + +#[command] +#[only_in(guilds)] +#[aliases("8ball")] +#[description("Ask your dad")] +async fn fortune(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { + let data = ctx.data.read().await; + let global_data = data.get::().unwrap(); + + let fortune = { + let mut rng = thread_rng(); + + global_data.cfg.fortunes.choose(&mut rng) + }; + + let reply = match fortune { + None => "Sorry kid, all out of fortunes.".to_string(), + Some(msg) => msg.clone(), + }; + + msg.reply(&ctx.http, reply).await?; + + Ok(()) +}