From 224d3866c886354966ed8325cec0fec0559326f4 Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Tue, 29 Apr 2025 10:45:02 +0200 Subject: [PATCH] perish command, misc --- src/discordbot/commands/mod.rs | 1 + src/discordbot/commands/perish.rs | 34 +++++++++++++++++++++++++++++++ src/discordbot/mod.rs | 30 +++++++++++++++------------ 3 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 src/discordbot/commands/perish.rs diff --git a/src/discordbot/commands/mod.rs b/src/discordbot/commands/mod.rs index 3f822b3..fb8d046 100644 --- a/src/discordbot/commands/mod.rs +++ b/src/discordbot/commands/mod.rs @@ -1,2 +1,3 @@ pub mod kiss; +pub mod perish; pub mod ping; diff --git a/src/discordbot/commands/perish.rs b/src/discordbot/commands/perish.rs new file mode 100644 index 0000000..f7aa90d --- /dev/null +++ b/src/discordbot/commands/perish.rs @@ -0,0 +1,34 @@ +use serenity::all::{ + CommandInteraction, Context, CreateEmbed, CreateInteractionResponse, + CreateInteractionResponseMessage, +}; +use serenity::builder::CreateCommand; + +const PERISH_GIF_LINK: &str = "https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExbGM3NDRtaXQ0ZWk3enlybmwydHZmc3VwcWlzbXN1N2Zyc3Jpc2lmYSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/4kkOaBEy84jzD5ijGV/giphy.gif"; + +pub async fn run(ctx: &Context, interaction: &CommandInteraction) -> Result<(), serenity::Error> { + let caller_name = interaction + .member + .as_ref() + .map(|m| m.nick.clone().unwrap_or_else(|| m.user.name.clone())) + .unwrap_or_else(|| interaction.user.name.clone()); + + let embed = CreateEmbed::new() + .thumbnail(PERISH_GIF_LINK) + .title(format!("{caller_name} has perished!")) + .description("Oh the misery...") + .color(0xFF89B4); + + interaction + .create_response( + &ctx.http, + CreateInteractionResponse::Message( + CreateInteractionResponseMessage::new().add_embed(embed), + ), + ) + .await +} + +pub fn register() -> CreateCommand { + CreateCommand::new("perish").description("w proch się obróć.") +} diff --git a/src/discordbot/mod.rs b/src/discordbot/mod.rs index 4a93ae3..438081a 100644 --- a/src/discordbot/mod.rs +++ b/src/discordbot/mod.rs @@ -17,7 +17,11 @@ impl EventHandler for Handler { async fn ready(&self, ctx: Context, ready: Ready) { info!("{} is connected!", ready.user.name); - let cmds = vec![commands::ping::register(), commands::kiss::register()]; + let cmds = vec![ + commands::ping::register(), + commands::kiss::register(), + commands::perish::register(), + ]; let guild_id = serenity::model::id::GuildId::from( std::env::var(GUILD_ID).unwrap().parse::().unwrap(), @@ -30,19 +34,19 @@ impl EventHandler for Handler { } async fn interaction_create(&self, ctx: Context, interaction: Interaction) { - if let Interaction::Command(command) = interaction { - let result = match command.data.name.as_str() { - "ping" => commands::ping::run(&ctx, &command).await, - "kiss" => commands::kiss::run(&ctx, &command).await, + if let Interaction::Command(cmd) = interaction { + let result = match cmd.data.name.as_str() { + "ping" => commands::ping::run(&ctx, &cmd).await, + "kiss" => commands::kiss::run(&ctx, &cmd).await, + "perish" => commands::perish::run(&ctx, &cmd).await, _ => { - command - .create_response( - &ctx.http, - CreateInteractionResponse::Message( - CreateInteractionResponseMessage::new().content("Not implemented"), - ), - ) - .await + cmd.create_response( + &ctx.http, + CreateInteractionResponse::Message( + CreateInteractionResponseMessage::new().content("Not implemented"), + ), + ) + .await } };