made bot in four hours

can run roll and random
This commit is contained in:
2025-04-19 20:22:08 -04:00
commit a98f2498a3
20 changed files with 3394 additions and 0 deletions

46
src/commands/roll.rs Normal file
View File

@@ -0,0 +1,46 @@
use crate::{
types::dietype,
util::{junk, random, validate},
};
use rand::Rng;
use serenity::builder::{CreateCommand, CreateCommandOption};
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
pub async fn run(options: &[ResolvedOption<'_>]) -> String {
if let Some(ResolvedOption {
value: ResolvedValue::String(input),
..
}) = options.first()
{
println!("got to the roll command! input: {}", input);
let split = input.split("d").nth(1).unwrap();
let die_num = match validate::parse_str_into_num::<i32>(split.trim()) {
Some(d) => d,
None => return junk::get_random_insult(),
};
let _die_type = match dietype::DieType::from_sides(die_num) {
Some(d) => d.to_sides(),
None => return junk::get_random_insult(),
};
let mut rng = random::RandomGen::new();
let result = rng.rng.gen_range(1..die_num).to_string();
return format!("{result}");
} else {
junk::get_random_insult()
}
}
pub fn register() -> CreateCommand {
CreateCommand::new("roll")
.description("Roll dice")
.add_option(
CreateCommandOption::new(
CommandOptionType::String,
"input",
"The number sides for the dice roll, typically starts with \'d\' then a number",
)
.required(true),
)
}