use diesel::{ result::Error as DieselError, NotFound, }; use grate::tracing; use serenity::all::ReactionType; use crate::{ db::{ connection, delete_meme, }, util, PoiseContext, }; /// Delete a meme by name. #[poise::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(), util::guild_id(ctx)?.get()).await { Ok(_) => { util::react(ctx, ReactionType::Unicode("💀".to_owned())).await?; Ok(()) }, Err(e) => { if let Some(NotFound) = e.downcast_ref::() { tracing::info!(title, "attempted to delete nonexistent meme"); util::react(ctx, ReactionType::Unicode("❓".to_owned())).await?; util::reply(ctx, "nice try").await?; return Ok(()); } Err(e)?; Ok(()) }, } }