diff options
| author | seth <[email protected]> | 2023-07-10 00:18:36 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2023-11-16 00:35:07 +0000 |
| commit | a4a9353e1c8f902b7d7b3cf74e3e5b129c214330 (patch) | |
| tree | b58da1d30af52e97c0251e0d6882cd0ccdfeb20a /src/commands | |
| parent | 5e9ec7f008e01d25c0b7f782c5ae043bc9ca0933 (diff) | |
start using poise
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/ask.rs | 40 | ||||
| -rw-r--r-- | src/commands/bing.rs | 8 | ||||
| -rw-r--r-- | src/commands/bottom.rs | 98 | ||||
| -rw-r--r-- | src/commands/convert.rs | 88 | ||||
| -rw-r--r-- | src/commands/copypasta.rs | 115 | ||||
| -rw-r--r-- | src/commands/mod.rs | 2 | ||||
| -rw-r--r-- | src/commands/random_lore.rs | 25 | ||||
| -rw-r--r-- | src/commands/random_shiggy.rs | 24 | ||||
| -rw-r--r-- | src/commands/random_teawie.rs | 24 | ||||
| -rw-r--r-- | src/commands/teawiespam.rs | 17 |
10 files changed, 209 insertions, 232 deletions
diff --git a/src/commands/ask.rs b/src/commands/ask.rs index b0b24f3..5075b9d 100644 --- a/src/commands/ask.rs +++ b/src/commands/ask.rs @@ -1,21 +1,23 @@ -use crate::utils; -use serenity::builder::CreateApplicationCommand; -use serenity::model::prelude::command::CommandOptionType; -use serenity::model::prelude::interaction::application_command::CommandDataOption; +use crate::consts; +use crate::utils::random_choice; +use crate::{Context, Error}; -pub fn run(_: &[CommandDataOption]) -> String { - utils::get_random_response() -} - -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("ask") - .description("ask lord teawie a question and they shall respond") - .create_option(|option| { - option - .name("question") - .description("the question you want to ask teawie") - .kind(CommandOptionType::String) - .required(true) - }) +/// ask teawie a question! +#[poise::command(prefix_command, slash_command)] +pub async fn ask( + ctx: Context<'_>, + #[description = "the question you want to ask teawie"] + #[rename = "question"] + _question: String, +) -> Result<(), Error> { + match random_choice(consts::RESPONSES) { + Ok(resp) => { + ctx.say(resp).await?; + Ok(()) + } + Err(why) => { + ctx.say("idk").await?; + Err(why) + } + } } diff --git a/src/commands/bing.rs b/src/commands/bing.rs new file mode 100644 index 0000000..ed91bb3 --- /dev/null +++ b/src/commands/bing.rs @@ -0,0 +1,8 @@ +use crate::{Context, Error}; + +/// make sure the wie is alive +#[poise::command(prefix_command)] +pub async fn bing(ctx: Context<'_>) -> Result<(), Error> { + ctx.say("bong!").await?; + Ok(()) +} diff --git a/src/commands/bottom.rs b/src/commands/bottom.rs index dbe74b9..d38c4b8 100644 --- a/src/commands/bottom.rs +++ b/src/commands/bottom.rs @@ -1,70 +1,42 @@ -use crate::utils::{bottom_decode, bottom_encode}; -use serenity::builder::CreateApplicationCommand; -use serenity::model::prelude::command::CommandOptionType; -use serenity::model::prelude::interaction::application_command::{ - CommandDataOption, CommandDataOptionValue, -}; +use crate::{Context, Error}; +use bottomify::bottom::{decode_string, encode_string}; -pub fn run(options: &[CommandDataOption]) -> String { - let err = "failed to get nested option in"; - - let data = options - .get(0) - .unwrap_or_else(|| panic!("{} {:?}", err, options)); +fn decode_sync(s: &str) -> Result<String, bottomify::bottom::TranslationError> { + decode_string(&s) +} - // get subcommand to decide whether to encode/decode - let subcommand = data.name.as_str(); +#[poise::command(slash_command, subcommands("encode", "decode"))] +pub async fn bottom(_ctx: Context<'_>) -> Result<(), Error> { + Ok(()) +} - // TODO: this is horrendous - // get message content - let option = data - .options - .get(0) - .unwrap_or_else(|| panic!("{} {:?}", err, data)) - .resolved - .as_ref() - .expect("failed to resolve string!"); // this is annoying +/// teawie will translate to bottom 🥺 +#[poise::command(slash_command)] +pub async fn encode( + ctx: Context<'_>, + #[description = "what teawie will translate into bottom"] message: String, +) -> Result<(), Error> { + let encoded = encode_string(&message); + ctx.say(encoded).await?; + Ok(()) +} - if let CommandDataOptionValue::String(msg) = option { - match subcommand { - "encode" => bottom_encode(msg), - "decode" => bottom_decode(msg), - _ => "something went wrong :(".to_owned(), +/// teawie will translate from bottom 🥸 +#[poise::command(slash_command)] +pub async fn decode( + ctx: Context<'_>, + #[description = "what teawie will translate from bottom"] message: String, +) -> Result<(), Error> { + let d = decode_sync(&message); + match d { + Ok(decoded) => { + ctx.say(decoded).await?; + Ok(()) + } + Err(why) => { + ctx.say("couldn't decode that for you, i'm sowwy!! :((".to_string()) + .await?; + Err(Box::new(why)) } - } else { - "did you forget to enter a message?".to_owned() } } - -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("bottom") - .description("teawie will translate something to/from bottom for you 🥺") - // nesting...so much nesting - .create_option(|option| { - option - .name("encode") - .description("teawie will encode a message in bottom for you 🥺") - .kind(CommandOptionType::SubCommand) - .create_sub_option(|suboption| { - suboption - .name("content") - .description("what teawie will translate into bottom") - .kind(CommandOptionType::String) - .required(true) - }) - }) - .create_option(|option| { - option - .name("decode") - .description("teawie will decode a message in bottom for you 🥸") - .kind(CommandOptionType::SubCommand) - .create_sub_option(|suboption| { - suboption - .name("content") - .description("what teawie will translate from bottom") - .kind(CommandOptionType::String) - .required(true) - }) - }) -} diff --git a/src/commands/convert.rs b/src/commands/convert.rs index 8f8c424..c7e09c9 100644 --- a/src/commands/convert.rs +++ b/src/commands/convert.rs @@ -1,70 +1,28 @@ -use crate::utils; -use serenity::builder::CreateApplicationCommand; -use serenity::model::prelude::command::CommandOptionType; -use serenity::model::prelude::interaction::application_command::{ - CommandDataOption, CommandDataOptionValue, -}; +use crate::{Context, Error}; -pub fn run(options: &[CommandDataOption]) -> String { - let err = "couldn't get convert subcommand!"; - let data = options - .get(0) - .unwrap_or_else(|| panic!("{} {:?}", err, options)); - let subcommand = data.name.as_str(); - // get message content - let option = data - .options - .get(0) - .unwrap_or_else(|| panic!("{} {:?}", err, data)) - .resolved - .as_ref() - .expect("failed to resolve string!"); - - let temp = if let &CommandDataOptionValue::Number(number) = option { - match subcommand { - "fahrenheit" => Some(utils::celsius_to_fahrenheit(number)), - "celsius" => Some(utils::fahrenheit_to_celsius(number)), - _ => None, - } - } else { - None - }; +#[poise::command(slash_command, subcommands("to_fahrenheit", "to_celsius"))] +pub async fn convert(_ctx: Context<'_>) -> Result<(), Error> { + Ok(()) +} - if let Some(temp) = temp { - format!("{temp:.2}") - } else { - "couldn't figure it out oops".to_owned() - } +/// ask teawie to convert °F to °C +#[poise::command(slash_command)] +pub async fn to_celsius( + ctx: Context<'_>, + #[description = "what teawie will convert"] degrees_fahrenheit: f32, +) -> Result<(), Error> { + let temp = (degrees_fahrenheit - 32.0) * (5.0 / 9.0); + ctx.say(temp.to_string()).await?; + Ok(()) } -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("convertto") - .description("ask teawie to convert something for you") - .create_option(|option| { - option - .name("fahrenheit") - .description("ask teawie to convert celsius to fahrenheit") - .kind(CommandOptionType::SubCommand) - .create_sub_option(|suboption| { - suboption - .name("degrees_celsius") - .description("what teawie will convert") - .kind(CommandOptionType::Number) - .required(true) - }) - }) - .create_option(|option| { - option - .name("celsius") - .description("ask teawie to convert fahrenheit to celsius") - .kind(CommandOptionType::SubCommand) - .create_sub_option(|suboption| { - suboption - .name("degrees_fahrenheit") - .description("what teawie will convert") - .kind(CommandOptionType::Number) - .required(true) - }) - }) +/// ask teawie to convert °C to °F +#[poise::command(slash_command)] +pub async fn to_fahrenheit( + ctx: Context<'_>, + #[description = "what teawie will convert"] degrees_celsius: f32, +) -> Result<(), Error> { + let temp = (degrees_celsius * (9.0 / 5.0)) + 32.0; + ctx.say(temp.to_string()).await?; + Ok(()) } diff --git a/src/commands/copypasta.rs b/src/commands/copypasta.rs index 670a5df..dcff558 100644 --- a/src/commands/copypasta.rs +++ b/src/commands/copypasta.rs @@ -1,64 +1,71 @@ use crate::utils; -use serenity::builder::CreateApplicationCommand; -use serenity::http::client::Http; -use serenity::model::id::ChannelId; -use serenity::model::prelude::command::CommandOptionType; -use serenity::model::prelude::interaction::application_command::{ - CommandDataOption, CommandDataOptionValue, -}; -use std::sync::Arc; +use crate::{Context, Error}; +use include_dir::{include_dir, Dir}; +use log::*; +use std::collections::HashMap; -pub async fn run(options: &[CommandDataOption], channel_id: ChannelId, http: &Arc<Http>) -> String { - let err_msg = "expected a copypasta"; - let option = options - .get(0) - .expect(err_msg) - .resolved - .as_ref() - .expect(err_msg); +const FILES: Dir = include_dir!("src/copypastas"); - if let CommandDataOptionValue::String(copypasta) = option { - let replies = utils::get_copypasta(copypasta); - - if replies.len() > 1 { - for reply in replies { - let resp = channel_id.send_message(&http, |m| m.content(reply)).await; +#[allow(clippy::upper_case_acronyms)] +#[derive(Debug, poise::ChoiceParameter)] +pub enum Copypastas { + Astral, + DVD, + Egrill, + HappyMeal, + //Ismah, + Sus, + TickTock, + Twitter, +} - match resp { - Ok(_) => continue, - Err(why) => { - println!("couldn't send message: {:?}", why); - return "something went wrong!".to_string(); - } - } - } - return "here's your copypasta:".to_string(); // yes this causes the - // application to not respond. - // no i don't care. +impl Copypastas { + fn as_str(&self) -> &str { + match self { + Copypastas::Astral => "astral", + Copypastas::DVD => "dvd", + Copypastas::Egrill => "egrill", + Copypastas::HappyMeal => "happymeal", + //Copypastas::Ismah => "ismah", + Copypastas::Sus => "sus", + Copypastas::TickTock => "ticktock", + Copypastas::Twitter => "twitter", } - return replies[0].to_string(); + } +} + +fn get_copypasta(name: Copypastas) -> String { + let mut files: HashMap<&str, &str> = HashMap::new(); + + for file in FILES.files() { + let name = file.path().file_stem().unwrap().to_str().unwrap(); + + let contents = file.contents_utf8().unwrap(); + + // refer to files by their name w/o extension + files.insert(name, contents); } - "couldn't find a copypasta".to_string() + if files.contains_key(name.as_str()) { + files[name.as_str()].to_string() + } else { + format!("i don't have a copypasta named {name} :(") + } } -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("copypasta") - .description("send funni copypasta") - .create_option(|option| { - option - .name("copypasta") - .description("the copypasta you want to send") - .kind(CommandOptionType::String) - .required(true) - .add_string_choice("astral", "astral") - .add_string_choice("dvd", "dvd") - .add_string_choice("egrill", "egrill") - .add_string_choice("happymeal", "happymeal") - .add_string_choice("ismah", "ismah") - .add_string_choice("sus", "sus") - .add_string_choice("ticktock", "ticktock") - .add_string_choice("twitter", "twitter") - }) +/// ask teawie to send funni copypasta +#[poise::command(slash_command)] +pub async fn copypasta( + ctx: Context<'_>, + #[description = "the copypasta you want to send"] copypasta: Copypastas, +) -> Result<(), Error> { + let gid = ctx.guild_id().unwrap_or_default(); + if !utils::is_guild_allowed(gid) { + info!("not running copypasta command in {gid}"); + return Ok(()); + } + + ctx.say(get_copypasta(copypasta)).await?; + + Ok(()) } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 1640707..fe536c1 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,7 +1,9 @@ pub mod ask; +pub mod bing; pub mod bottom; pub mod convert; pub mod copypasta; pub mod random_lore; pub mod random_shiggy; pub mod random_teawie; +pub mod teawiespam; diff --git a/src/commands/random_lore.rs b/src/commands/random_lore.rs index b07660e..875a35e 100644 --- a/src/commands/random_lore.rs +++ b/src/commands/random_lore.rs @@ -1,13 +1,16 @@ -use crate::utils::get_random_lore; -use serenity::builder::CreateApplicationCommand; -use serenity::model::prelude::interaction::application_command::CommandDataOption; +use crate::{consts, utils, Context, Error}; -pub fn run(_: &[CommandDataOption]) -> String { - get_random_lore() -} - -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("random_lore") - .description("get a random piece of teawie lore!") +/// get a random piece of teawie lore! +#[poise::command(prefix_command, slash_command)] +pub async fn random_lore(ctx: Context<'_>) -> Result<(), Error> { + match utils::random_choice(consts::LORE) { + Ok(resp) => { + ctx.say(resp).await?; + Ok(()) + } + Err(why) => { + ctx.say("i can't think of any right now :(").await?; + Err(why) + } + } } diff --git a/src/commands/random_shiggy.rs b/src/commands/random_shiggy.rs index c6aa6de..e509a71 100644 --- a/src/commands/random_shiggy.rs +++ b/src/commands/random_shiggy.rs @@ -1,13 +1,17 @@ use crate::api::shiggy::get_random_shiggy; -use serenity::builder::CreateApplicationCommand; -use serenity::model::prelude::application_command::CommandDataOption; +use crate::{Context, Error}; -pub async fn run(_: &[CommandDataOption]) -> String { - get_random_shiggy().await -} - -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("random_shiggy") - .description("get a random shiggy!") +/// get a random shiggy +#[poise::command(prefix_command, slash_command)] +pub async fn random_shiggy(ctx: Context<'_>) -> Result<(), Error> { + match get_random_shiggy().await { + Ok(resp) => { + ctx.say(resp).await?; + Ok(()) + } + Err(why) => { + ctx.say("i can't get a shiggy right now :(").await?; + Err(why) + } + } } diff --git a/src/commands/random_teawie.rs b/src/commands/random_teawie.rs index b3c433d..8dcc76b 100644 --- a/src/commands/random_teawie.rs +++ b/src/commands/random_teawie.rs @@ -1,13 +1,17 @@ use crate::api::guzzle::get_random_teawie; -use serenity::builder::CreateApplicationCommand; -use serenity::model::prelude::interaction::application_command::CommandDataOption; +use crate::{Context, Error}; -pub async fn run(_: &[CommandDataOption]) -> String { - get_random_teawie().await -} - -pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { - command - .name("random_teawie") - .description("get a random teawie!") +/// get a random teawie +#[poise::command(prefix_command, slash_command)] +pub async fn random_teawie(ctx: Context<'_>) -> Result<(), Error> { + match get_random_teawie().await { + Ok(resp) => { + ctx.say(resp).await?; + Ok(()) + } + Err(why) => { + ctx.say("i'm too lazy to send a selfie").await?; + Err(why) + } + } } diff --git a/src/commands/teawiespam.rs b/src/commands/teawiespam.rs new file mode 100644 index 0000000..4964e90 --- /dev/null +++ b/src/commands/teawiespam.rs @@ -0,0 +1,17 @@ +use crate::utils; +use crate::{Context, Error}; +use log::*; + +/// teawie will spam you. +#[poise::command(slash_command, prefix_command)] +pub async fn teawiespam(ctx: Context<'_>) -> Result<(), Error> { + let gid = ctx.guild_id().unwrap_or_default(); + if !utils::is_guild_allowed(gid) { + info!("not running copypasta command in {gid}"); + return Ok(()); + } + + let wies = "<:teawiesmile:1056438046440042546>".repeat(50); + ctx.say(wies).await?; + Ok(()) +} |
