diff --git a/library/src/utils.rs b/library/src/utils.rs index 7f91900..e12051a 100755 --- a/library/src/utils.rs +++ b/library/src/utils.rs @@ -53,18 +53,18 @@ pub fn format_duration(secs: u64) -> String { let minutes = (secs % 3600) / 60; let seconds = secs % 60; - let mut formatted_string = String::new(); - match (days, hours, minutes, seconds) { - (d, _, _, _) if d > 0 => formatted_string.push_str(&format!("{d}d, ")), - (_, h, _, _) if h > 0 => formatted_string.push_str(&format!("{h}h, ")), - (_, _, m, _) if m > 0 => formatted_string.push_str(&format!("{m}m, ")), - (_, _, _, s) if s > 0 => formatted_string.push_str(&format!("{s}s")), - _ => {} - } + let components = [ + (days, "d"), + (hours, "h"), + (minutes, "m"), + (seconds, "s"), + ]; - if formatted_string.ends_with(", ") { - formatted_string.truncate(formatted_string.len() - 2); - } + let formatted_string: Vec = components + .iter() + .filter(|&&(value, _)| value > 0) + .map(|&(value, suffix)| format!("{}{}", value, suffix)) + .collect(); - formatted_string + formatted_string.join(", ") } diff --git a/src/commands.rs b/src/commands.rs index 5dd6a8a..be2a5fc 100755 --- a/src/commands.rs +++ b/src/commands.rs @@ -19,7 +19,7 @@ macro_rules! collect { // Utility commands commands::ping(), commands::uptime(), - + // Unsorted mess commands::eightball(), ] diff --git a/src/commands/dev.rs b/src/commands/dev.rs index ec0546e..4a90fb6 100755 --- a/src/commands/dev.rs +++ b/src/commands/dev.rs @@ -1,11 +1,16 @@ use crate::RustbotError; use super::PoiseContext; +use poise::{ + CreateReply, + serenity_prelude::ChannelId +}; + /// Developer commands #[poise::command( prefix_command, owners_only, - subcommands("deploy", "servers", "shards") + subcommands("deploy", "servers", "shards", "echo") )] pub async fn dev(_: PoiseContext<'_>) -> Result<(), RustbotError> { Ok(()) @@ -48,3 +53,39 @@ async fn shards(ctx: PoiseContext<'_>) -> Result<(), RustbotError> { Ok(()) } + +/// Turn your message into a bot message +#[poise::command(slash_command)] +async fn echo( + ctx: super::PoiseContext<'_>, + #[description = "Message to be echoed as a bot"] message: String, + #[description = "Channel to send this to"] + #[channel_types("Text", "PublicThread", "PrivateThread")] channel: Option +) -> Result<(), RustbotError> { + ctx.defer_ephemeral().await?; + + let channel = match channel { + Some(c) => c, + None => ctx.channel_id() + }; + + match ChannelId::new(channel.get()).say(ctx.http(), message).await { + Ok(_) => { + ctx.send( + CreateReply::new() + .content("Sent!") + .ephemeral(true) + ).await?; + }, + Err(y) => { + ctx.send( + CreateReply::new() + .content(format!("Failed... `{y}`")) + .ephemeral(true) + ).await?; + return Ok(()); + } + } + + Ok(()) +} diff --git a/src/commands/eightball.rs b/src/commands/eightball.rs index d8d9370..b4810d8 100755 --- a/src/commands/eightball.rs +++ b/src/commands/eightball.rs @@ -29,11 +29,26 @@ pub async fn eightball( } } - ctx.reply(format!( - "> {}\n{}", - question, + if question.to_ascii_lowercase().contains("rustbot, show chicken list") { + if ctx.author().id == UserId::new(BINARY_PROPERTIES.developers[0]) { + let chunks: Vec = CHICKEN_RESPONSES.chunks(10).map(|chunk| chunk.join("\n\n")).collect(); + let pages: Vec<&str> = chunks.iter().map(|s| s.as_str()).collect(); + paginate(ctx, &pages).await?; + + return Ok(()); + } else { + ctx.reply("No.").await?; + return Ok(()); + } + } + + let rand_resp = if question.to_ascii_lowercase().contains("chicken") { + get_random_chicken_response() + } else { get_random_response() - )).await?; + }; + + ctx.reply(format!("> {question}\n{rand_resp}")).await?; Ok(()) } @@ -75,6 +90,48 @@ const RESPONSES: [&str; 30] = [ "Try asking this to a chicken. Probably knows it better than I do!", // no ]; +const CHICKEN_RESPONSES: [&str; 35] = [ + "Cluck cluck... Reply hazy, try pecking Google.", // no + "Meh... Figure it out yourself, or scratch around a bit.", // no + "I don’t know... what do you think? *pecks at ground*", // no + "BAWK! YES!", // yes + "Cluck... no.", // no + "It is decidedly so! *flaps wings*", // yes + "Signs point to... maybe... hold on, let me fluff my feathers... depends on whether you'd get to know your Magic Chicken a bit better.", // no + "Signs point to... ~~yes~~ cluck no.", // no + "Why do you want to know? It’s a big cluckin’ yes!", // yes + "Outlook not so clucking good.", // no + "Outlook cluckin' hazy.", // no + "What are you, a lost chick? Cluck!", // no + "How the cluck do you not know that?", // no + "Really? Asking a chicken to decide your fate? *clucks judgmentally*", // no + "Peck back later, I'm nesting...", // no + "I don’t know, try flapping your wings and ask again?", // no + "The answer is a big ol' yes! *flaps happily*", // yes + "Yes... wait, actually... no. Cluck, I’m confused.", // no + "Maaaaybe... *chicken waddle*?", // yes + "Definitely! *struts confidently*", // yes + "It is decidedly so. *struts with pride*", // yes + "My reply is a solid *cluck* no.", // no + "My sources confirm it's a cluckin' no.\nSource: 🐔 *I made it up* 🐔", // no + "As I see it, yes! *pecks approvingly*", // yes + "Don’t count on it. *cluck cluck*", // no + "Whoa, why do I have to answer this? *fluffs feathers*", // no + "Highly unlikely. *chicken stare*", // no + "Sure, but with extreme cluckin' caution.", // yes + "What kind of stupid question is that?? No! *angry clucks*", // no + "Try asking this to a fellow chicken. They probably know better than I do!", // no + "Cluck yes! *does a happy chicken dance*", // yes + "No way, not even for a big bag of feed.", // no + "Yes! *lays egg of approval*", // yes + "It's a no, better go scratch somewhere else.", // no + "Cluck-tastic! That’s a definite yes.", // yes +]; + fn get_random_response() -> &'static str { RESPONSES[rand::random::() % RESPONSES.len()] } + +fn get_random_chicken_response() -> &'static str { + CHICKEN_RESPONSES[rand::random::() % CHICKEN_RESPONSES.len()] +} diff --git a/src/main.rs b/src/main.rs index 185b35a..5e89589 100755 --- a/src/main.rs +++ b/src/main.rs @@ -121,11 +121,10 @@ async fn main() { &token_path().await.main, GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES - | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT ) .framework(framework) - .data(Arc::new(RustbotData {})) + .data(Arc::new(RustbotData {})) .activity(ActivityData::custom("nep nep!")) .await.expect("Error creating client");