This commit is contained in:
+21
-13
@@ -6,25 +6,33 @@ use crate::{
|
||||
use serenity::builder::{CreateCommand, CreateCommandOption};
|
||||
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
|
||||
|
||||
pub fn run_core(input: Option<&str>) -> String {
|
||||
let Some(input) = input else {
|
||||
return junk::get_random_insult();
|
||||
};
|
||||
let split = match input.split('d').nth(1) {
|
||||
Some(s) => s,
|
||||
None => return junk::get_random_insult(),
|
||||
};
|
||||
let die_num = match validate::parse_str_into_num::<i32>(split.trim()) {
|
||||
Some(d) => d,
|
||||
None => return junk::get_random_insult(),
|
||||
};
|
||||
match dietype::DieType::from_sides(die_num) {
|
||||
Some(_) => {}
|
||||
None => return junk::get_random_insult(),
|
||||
};
|
||||
let mut rng = random::RandomGen::new();
|
||||
rng.range_random_from_one(die_num).to_string()
|
||||
}
|
||||
|
||||
pub async fn run(options: &[ResolvedOption<'_>]) -> String {
|
||||
if let Some(ResolvedOption {
|
||||
value: ResolvedValue::String(input),
|
||||
..
|
||||
}) = options.first()
|
||||
{
|
||||
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.range_random_from_one(die_num).to_string();
|
||||
return format!("{result}");
|
||||
run_core(Some(input))
|
||||
} else {
|
||||
junk::get_random_insult()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user