Added fortune command
+ clippy + fmt
This commit is contained in:
parent
13bacac0c7
commit
3c78ba5e0e
@ -21,6 +21,7 @@ pub struct AlbumConfig {
|
||||
pub struct BotConfig {
|
||||
pub bot_token: String,
|
||||
pub imgur_client_id: String,
|
||||
pub fortunes: Vec<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub albums: Vec<AlbumConfig>,
|
||||
|
||||
@ -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::<GlobalData>().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(())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user