diff options
Diffstat (limited to 'src/commands/meme/create.rs')
| -rw-r--r-- | src/commands/meme/create.rs | 84 |
1 files changed, 41 insertions, 43 deletions
diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index 97c5276..1c12f2a 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -1,50 +1,41 @@ -use std::{ - io::Read, - process::{ - Command, - Stdio, - }, -}; +use std::process::Stdio; +use anyhow::anyhow; use diesel::result::Error as DieselError; +use lazy_static::lazy_static; use log::{ debug, error, warn, }; use serenity::{ + all::ReactionType, framework::standard::{ macros::command, Args, + CommandError, + CommandResult, Delimiter, }, + futures::TryFutureExt, model::channel::Message, prelude::*, }; -use url::Url; - -use anyhow::anyhow; -use lazy_static::lazy_static; -use serenity::{ - all::ReactionType, - framework::standard::{ - CommandError, - CommandResult, - }, - futures::TryFutureExt, +use tap::Pipe; +use tokio::{ + io::AsyncReadExt, + process::Command, }; +use url::Url; use crate::{ - audio::{ - parse_times, - ytdl_url, - }, db::{ connection, Audio, Image, NewMeme, }, + parse_times, util, FFMPEG_COMMAND, }; @@ -77,12 +68,12 @@ pub async fn addmeme(ctx: &Context, msg: &Message, args: Args) -> CommandResult .await; } - let image_id = image - .map(|att| { - let data = att.download()?; - Image::create(&mut conn, &att.filename, data, msg.author.id.get()) - }) - .transpose()?; + let mut image_id = None; + + if let Some(att) = image { + let data = att.download().await?; + image_id = Some(Image::create(&mut conn, &att.filename, data, msg.author.id.get())?); + }; let save_result = NewMeme { title, @@ -96,7 +87,9 @@ pub async fn addmeme(ctx: &Context, msg: &Message, args: Args) -> CommandResult use diesel::result::DatabaseErrorKind; match save_result { - Ok(_) => msg.react(&ctx, "👌"), + Ok(_) => { + msg.react(&ctx, ReactionType::Unicode("👌".to_string())).await?; + }, Err(e) => { if let Some(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) = e.downcast_ref::<DieselError>() @@ -111,6 +104,8 @@ pub async fn addmeme(ctx: &Context, msg: &Message, args: Args) -> CommandResult return Err(e.into()); }, } + + Ok(()) } #[command] @@ -131,7 +126,7 @@ pub async fn addaudiomeme(ctx: &Context, msg: &Message, args: Args) -> CommandRe let opts = elems[1..].join(" "); let (start, end) = parse_times(opts); - let youtube_url = ytdl_url(audio_link.as_str())?; + let youtube_url = util::ytdl_url(audio_link.as_str()).await?; let duration_opts = if let Some(e) = end { vec