Added roll command
+ clippy + fmt
This commit is contained in:
parent
a9b5eb43d0
commit
73be6b1d9f
@ -10,6 +10,10 @@ use serenity::framework::standard::{Args, CommandResult};
|
|||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[group]
|
||||||
|
#[commands(dad_joke, fortune, roll)]
|
||||||
|
pub struct Joke;
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
struct DadJoke {
|
struct DadJoke {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
@ -17,10 +21,6 @@ struct DadJoke {
|
|||||||
pub status: i32,
|
pub status: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[group]
|
|
||||||
#[commands(dad_joke, fortune)]
|
|
||||||
pub struct Joke;
|
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
#[aliases("dad")]
|
#[aliases("dad")]
|
||||||
@ -104,3 +104,20 @@ async fn fortune(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
|||||||
|
|
||||||
Ok(())
|
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::<ndm::Dice>();
|
||||||
|
|
||||||
|
let reply = match roll {
|
||||||
|
Ok(roll) => format!("You rolled: **{}**", roll),
|
||||||
|
Err(_) => "Error parsing dice roll".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
msg.reply(&ctx.http, reply).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user