Update template with changes

This commit is contained in:
toast 2024-10-25 04:06:10 +11:00
parent 217c6df9f8
commit ec2b4d5814
5 changed files with 118 additions and 21 deletions

View File

@ -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<String> = components
.iter()
.filter(|&&(value, _)| value > 0)
.map(|&(value, suffix)| format!("{}{}", value, suffix))
.collect();
formatted_string
formatted_string.join(", ")
}

View File

@ -19,7 +19,7 @@ macro_rules! collect {
// Utility commands
commands::ping(),
commands::uptime(),
// Unsorted mess
commands::eightball(),
]

View File

@ -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<ChannelId>
) -> 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(())
}

View File

@ -16,7 +16,7 @@ pub async fn eightball(
ctx: PoiseContext<'_>,
#[description = "Your yes/no question"] question: String
) -> Result<(), RustbotError> {
if question.to_ascii_lowercase().contains("rustbot, show list") {
if question.to_ascii_lowercase().contains("niko, show list") {
if ctx.author().id == UserId::new(BINARY_PROPERTIES.developers[0]) {
let chunks: Vec<String> = RESPONSES.chunks(10).map(|chunk| chunk.join("\n\n")).collect();
let pages: Vec<&str> = chunks.iter().map(|s| s.as_str()).collect();
@ -29,11 +29,26 @@ pub async fn eightball(
}
}
ctx.reply(format!(
"> {}\n{}",
question,
if question.to_ascii_lowercase().contains("niko, show chicken list") {
if ctx.author().id == UserId::new(BINARY_PROPERTIES.developers[0]) {
let chunks: Vec<String> = 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 dont 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? Its 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 dont know, try flapping your wings and ask again?", // no
"The answer is a big ol' yes! *flaps happily*", // yes
"Yes... wait, actually... no. Cluck, Im 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
"Dont 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! Thats a definite yes.", // yes
];
fn get_random_response() -> &'static str {
RESPONSES[rand::random::<usize>() % RESPONSES.len()]
}
fn get_random_chicken_response() -> &'static str {
CHICKEN_RESPONSES[rand::random::<usize>() % CHICKEN_RESPONSES.len()]
}

View File

@ -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");