diff options
| author | seth <[email protected]> | 2023-04-07 19:59:19 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2023-04-07 20:00:57 -0400 |
| commit | bb3df7e6ab9de4c52fbe81b589ac5d1add6d281d (patch) | |
| tree | d0642d24fe96e8ea6d98969a20975b611ec11d53 /src | |
| parent | 83f885ee8d762551a6c5d8ea5ab3719cde76464a (diff) | |
add random lore command
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/mod.rs | 1 | ||||
| -rw-r--r-- | src/commands/random_lore.rs | 13 | ||||
| -rw-r--r-- | src/main.rs | 16 | ||||
| -rw-r--r-- | src/utils.rs | 19 |
4 files changed, 44 insertions, 5 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 7005ae2..afe1e39 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2,4 +2,5 @@ pub mod ask; pub mod bottom_decode; pub mod bottom_encode; pub mod copypasta; +pub mod random_lore; pub mod random_teawie; diff --git a/src/commands/random_lore.rs b/src/commands/random_lore.rs new file mode 100644 index 0000000..345f753 --- /dev/null +++ b/src/commands/random_lore.rs @@ -0,0 +1,13 @@ +use crate::utils::get_random_lore; +use serenity::builder::CreateApplicationCommand; +use serenity::model::prelude::interaction::application_command::CommandDataOption; + +pub async fn run(_: &[CommandDataOption]) -> String { + get_random_lore().await +} + +pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { + command + .name("random_lore") + .description("get a random piece of teawie lore!") +} diff --git a/src/main.rs b/src/main.rs index 1d39fa5..927e0e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ const GUILD: u64 = 1055663552679137310; const BOT: u64 = 1056467120986271764; #[group] -#[commands(bing, ask, random_teawie, teawiespam)] +#[commands(bing, ask, random_lore, random_teawie, teawiespam)] struct General; struct Handler; @@ -62,6 +62,7 @@ impl EventHandler for Handler { commands::copypasta::run(&command.data.options, command.channel_id, &ctx.http) .await } + "random_lore" => commands::random_lore::run(&command.data.options).await, "random_teawie" => commands::random_teawie::run(&command.data.options).await, _ => "not implemented :(".to_string(), }; @@ -89,8 +90,9 @@ impl EventHandler for Handler { .create_application_command(|command| commands::ask::register(command)) .create_application_command(|command| commands::bottom_decode::register(command)) .create_application_command(|command| commands::bottom_encode::register(command)) - .create_application_command(|command| commands::random_teawie::register(command)) .create_application_command(|command| commands::copypasta::register(command)) + .create_application_command(|command| commands::random_lore::register(command)) + .create_application_command(|command| commands::random_teawie::register(command)) }) .await; @@ -138,6 +140,16 @@ async fn ask(ctx: &Context, msg: &Message) -> CommandResult { } #[command] +async fn random_lore(ctx: &Context, msg: &Message) -> CommandResult { + let resp = utils::get_random_lore().await; + msg.channel_id + .send_message(&ctx.http, |m| m.content(resp)) + .await?; + + Ok(()) +} + +#[command] async fn random_teawie(ctx: &Context, msg: &Message) -> CommandResult { let resp = api::guzzle::get_random_teawie().await; msg.channel_id diff --git a/src/utils.rs b/src/utils.rs index 4157e3b..bb57521 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -9,17 +9,30 @@ const CHAR_LIMIT: usize = 2000; const FILES: Dir = include_dir!("src/include"); /* - * chooses a random response out of our options + * chooses a random element from an array */ -pub async fn get_random_response() -> String { +async fn random_choice<const N: usize>(arr: [&str; N]) -> String { let mut rng = rand::thread_rng(); - let resp = RESPONSES + let resp = arr .choose(&mut rng) .expect("couldn't choose random value!"); resp.to_string() } /* + * pub functions to get random elements + * from our consts + */ + +pub async fn get_random_response() -> String { + random_choice(RESPONSES).await +} + +pub async fn get_random_lore() -> String { + random_choice(LORE).await +} + +/* * splits a message into multiple parts so that * it can fit discord's character limit */ |
