perish command, misc

This commit is contained in:
2025-04-29 10:45:02 +02:00
parent 30dee784f6
commit 224d3866c8
3 changed files with 52 additions and 13 deletions

View File

@@ -1,2 +1,3 @@
pub mod kiss; pub mod kiss;
pub mod perish;
pub mod ping; pub mod ping;

View File

@@ -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óć.")
}

View File

@@ -17,7 +17,11 @@ impl EventHandler for Handler {
async fn ready(&self, ctx: Context, ready: Ready) { async fn ready(&self, ctx: Context, ready: Ready) {
info!("{} is connected!", ready.user.name); 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( let guild_id = serenity::model::id::GuildId::from(
std::env::var(GUILD_ID).unwrap().parse::<u64>().unwrap(), std::env::var(GUILD_ID).unwrap().parse::<u64>().unwrap(),
@@ -30,13 +34,13 @@ impl EventHandler for Handler {
} }
async fn interaction_create(&self, ctx: Context, interaction: Interaction) { async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
if let Interaction::Command(command) = interaction { if let Interaction::Command(cmd) = interaction {
let result = match command.data.name.as_str() { let result = match cmd.data.name.as_str() {
"ping" => commands::ping::run(&ctx, &command).await, "ping" => commands::ping::run(&ctx, &cmd).await,
"kiss" => commands::kiss::run(&ctx, &command).await, "kiss" => commands::kiss::run(&ctx, &cmd).await,
"perish" => commands::perish::run(&ctx, &cmd).await,
_ => { _ => {
command cmd.create_response(
.create_response(
&ctx.http, &ctx.http,
CreateInteractionResponse::Message( CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new().content("Not implemented"), CreateInteractionResponseMessage::new().content("Not implemented"),