use diesel::{ result::Error as DieselError, NotFound, }; use log::info; use serenity::{ all::ReactionType, framework::standard::{ macros::command, Args, CommandResult, }, model::channel::Message, prelude::*, }; use crate::{ db::{ connection, delete_meme, }, util, }; #[command] #[aliases("delmem")] pub async fn delmeme(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let title = args.single_quoted::()?; let mut conn = connection()?; match delete_meme(&mut conn, &title, msg.author.id.get()) { Ok(_) => { msg.react(ctx, ReactionType::Unicode("💀".to_owned())).await?; Ok(()) }, Err(e) => { if let Some(NotFound) = e.downcast_ref::() { msg.react(&ctx, ReactionType::Unicode("❓".to_owned())).await?; info!("attempted to delete nonexistent meme: '{}'", title); util::send(ctx, msg.channel_id, "nice try", msg.tts).await?; return Ok(()); } Err(e)?; Ok(()) }, } }