aboutsummaryrefslogtreecommitdiff
path: root/src/commands/meme/delete.rs
blob: 5c6eb131fe67290fc82eac58f17e9e2fdf4d1f53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use diesel::{
    NotFound,
    result::Error as DieselError,
};
use serenity::{
    framework::standard::Args,
    model::channel::Message,
    prelude::*,
};

use crate::{
    commands::send,
    db::{
        connection,
        delete_meme,
    },
    Result,
};

pub fn delmeme(_: &mut Context, msg: &Message, mut args: Args) -> Result<()> {
    let title = args.single_quoted::<String>()?;

    let conn = connection()?;
    match delete_meme(&conn, &title, msg.author.id.0) {
        Ok(_) => msg.react("💀"),
        Err(e) => {
            if let Some(NotFound) = e.downcast_ref::<DieselError>() {
                msg.react("❓")?;
                info!("attempted to delete nonexistent meme: '{}'", title);
                send(msg.channel_id, "nice try", msg.tts)?;
                return Ok(());
            }

            Err(e)
        }
    }
}