made bot in four hours
can run roll and random
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
use serenity::builder::CreateCommand;
|
||||
use serenity::model::application::ResolvedOption;
|
||||
|
||||
pub async fn run(options: &[ResolvedOption<'_>]) -> String {
|
||||
r#"
|
||||
A Discord bot that rolls limitless dice, randomly!
|
||||
Designed, developed, and maintained by Arnkell Warner of Maduin
|
||||
Copyright 2025, all rights reserved
|
||||
"#
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("about").description("Get information about this bot")
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod about;
|
||||
pub mod random;
|
||||
pub mod roll;
|
||||
@@ -0,0 +1,42 @@
|
||||
use crate::util::{junk, random::RandomGen, validate};
|
||||
|
||||
use rand::Rng;
|
||||
use serenity::builder::{CreateCommand, CreateCommandOption};
|
||||
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
|
||||
|
||||
pub async fn run(options: &[ResolvedOption<'_>]) -> String {
|
||||
// check if options array is empty first
|
||||
if options.is_empty() {
|
||||
let mut rng = RandomGen::new();
|
||||
return rng.rng.gen_range(1..999).to_string();
|
||||
}
|
||||
|
||||
// options exist, process first option
|
||||
if let Some(ResolvedOption {
|
||||
value: ResolvedValue::String(input),
|
||||
..
|
||||
}) = options.first()
|
||||
{
|
||||
println!("input: {}", input);
|
||||
let mut rng = RandomGen::new();
|
||||
return match validate::parse_str_into_num::<i32>(input.trim()) {
|
||||
Some(n) => rng.rng.gen_range(1..n).to_string(),
|
||||
None => return junk::get_random_insult(),
|
||||
};
|
||||
} else {
|
||||
junk::get_random_insult()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("random")
|
||||
.description("Start a random dice roll, commonly used for deathrolls!")
|
||||
.add_option(
|
||||
CreateCommandOption::new(
|
||||
CommandOptionType::String,
|
||||
"limit",
|
||||
"Set an upper limit to display a random number between 1 and the specified number.",
|
||||
)
|
||||
.required(false),
|
||||
)
|
||||
}
|
||||
@@ -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),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user