From b477b066b972248e080ff7f432ccab2c5e520b43 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Tue, 28 Jan 2020 18:02:50 -0500 Subject: fix error handling for addmeme --- src/commands/meme/create.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/commands/meme') diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index 047c556..9a89dbe 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -56,23 +56,24 @@ pub fn addmeme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> { let conn = connection()?; - let image = msg.attachments.first() - .ok_or(anyhow!("no attachment")) - .and_then(|att| { - let data = att.download()?; - Image::create(&conn, &att.filename, data, msg.author.id.0) - }) - .ok(); + let image = msg.attachments.first(); if image.is_none() && text.is_none() { warn!("tried to create non-audio meme with no image or text"); return ctx.send(msg.channel_id, "hahAA it's empty xdddd", msg.tts); } + let image_id = image + .ok_or(anyhow!("no attachment")) + .and_then(|att| { + let data = att.download()?; + Image::create(&conn, &att.filename, data, msg.author.id.0) + })?; + let save_result = NewMeme { title, content: text, - image_id: image, + image_id: Some(image_id), audio_id: None, metadata_id: 0, }.save(&conn, msg.author.id.0).map(|_| {}); -- cgit v1.3.1