use diesel::{ result::Error as DieselError, NotFound, }; use log::info; use serenity::all::ReactionType; use crate::{ db::{ connection, delete_meme, }, msg, util, PoiseContext, }; #[poise::command(slash_command, prefix_command, guild_only, category = "memes", aliases("delmem"))] pub async fn delmeme(ctx: PoiseContext<'_>, title: String) -> anyhow::Result<()> { let mut conn = connection().await?; match delete_meme(&mut conn, &title, ctx.author().id.get()).await { Ok(_) => { util::react(ctx, ReactionType::Unicode("💀".to_owned())).await?; Ok(()) }, Err(e) => { if let Some(NotFound) = e.downcast_ref::() { info!("attempted to delete nonexistent meme: '{}'", title); util::react(ctx, ReactionType::Unicode("❓".to_owned())).await?; util::reply(ctx, "nice try").await?; return Ok(()); } Err(e)?; Ok(()) }, } }