diff options
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/meme/create.rs | 7 | ||||
| -rw-r--r-- | src/commands/meme/delete.rs | 4 | ||||
| -rw-r--r-- | src/commands/meme/history.rs | 24 | ||||
| -rw-r--r-- | src/commands/meme/invoke.rs | 25 | ||||
| -rw-r--r-- | src/commands/meme/mod.rs | 4 | ||||
| -rw-r--r-- | src/commands/mod.rs | 9 |
6 files changed, 39 insertions, 34 deletions
diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index 160de7b..9aff370 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -57,7 +57,7 @@ pub async fn addmeme(ctx: &Context, msg: &Message, args: Args) -> CommandResult Some(text) }; - let mut conn = connection()?; + let mut conn = connection().await?; let image = msg.attachments.first(); @@ -175,7 +175,7 @@ pub async fn addaudiomeme(ctx: &Context, msg: &Message, args: Args) -> CommandRe Some(text) }; - let mut conn = connection()?; + let mut conn = connection().await?; let image_att = msg.attachments.first().ok_or(anyhow!("no attachment")); @@ -183,7 +183,8 @@ pub async fn addaudiomeme(ctx: &Context, msg: &Message, args: Args) -> CommandRe if let Ok(att) = image_att { let data = att.download().await?; - image_id = Image::create(&mut conn, &att.filename, data, msg.author.id.get())?.await.pipe(Some); + image_id = + Image::create(&mut conn, &att.filename, data, msg.author.id.get()).await?.pipe(Some); } let mut audio_data = Vec::new(); diff --git a/src/commands/meme/delete.rs b/src/commands/meme/delete.rs index c06e9d0..6af1b6b 100644 --- a/src/commands/meme/delete.rs +++ b/src/commands/meme/delete.rs @@ -27,9 +27,9 @@ use crate::{ pub async fn delmeme(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let title = args.single_quoted::<String>()?; - let mut conn = connection()?; + let mut conn = connection().await?; - match delete_meme(&mut conn, &title, msg.author.id.get()) { + match delete_meme(&mut conn, &title, msg.author.id.get()).await { Ok(_) => { msg.react(ctx, ReactionType::Unicode("💀".to_owned())).await?; Ok(()) diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs index e5b3d33..fc95e2d 100644 --- a/src/commands/meme/history.rs +++ b/src/commands/meme/history.rs @@ -58,7 +58,7 @@ static CLEAN_DATE_FORMAT: &str = "%b %-e %Y"; #[command] #[aliases("what", "hwaet", "hwæt")] pub async fn wat(ctx: &Context, msg: &Message, _: Args) -> CommandResult { - let mut conn = connection()?; + let mut conn = connection().await?; let record = match InvocationRecord::last(&mut conn).await { Ok(x) => x, @@ -124,7 +124,7 @@ pub async fn history(ctx: &Context, msg: &Message, mut args: Args) -> CommandRes let n = n.min(CONFIG.max_hist); let records = { - let mut conn = connection()?; + let mut conn = connection().await?; InvocationRecord::last_n(&mut conn, n).await? }; @@ -139,7 +139,7 @@ pub async fn history(ctx: &Context, msg: &Message, mut args: Args) -> CommandRes let resp = serenity::futures::stream::iter(records.into_iter().enumerate().rev()) .then(|(i, rec)| async move { - let mut conn = connection()?; + let mut conn = connection().await?; let dt = chrono::DateTime::from_utc(rec.time, chrono::Utc {}); let ago = TIME_FORMATTER.convert((chrono::Utc::now() - dt).to_std().unwrap()); @@ -150,11 +150,12 @@ pub async fn history(ctx: &Context, msg: &Message, mut args: Args) -> CommandRes "" }; - let meme = Meme::find(&mut conn, rec.meme_id).await; - - .and_then(|meme| { - Metadata::find(&mut conn, meme.metadata_id).map(|metadata| (metadata, meme)) - }); + let meme = match Meme::find(&mut conn, rec.meme_id).await { + Ok(meme) => Metadata::find(&mut conn, meme.metadata_id) + .await + .map(|metadata| (metadata, meme)), + Err(e) => Err(e), + }; let invoker_name = CONFIG .discord @@ -215,7 +216,7 @@ pub async fn stats(ctx: &Context, msg: &Message, _: Args) -> CommandResult { user::User, }; - let mut conn = connection()?; + let mut conn = connection().await?; let stats = db::stats(&mut conn).await?; debug!("reporting stats"); @@ -282,7 +283,8 @@ and *{}* was the most-memed overall ({})"#, pub async fn memers(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { use serenity::model::id::UserId; - let s = db::memers()? + let s = db::memers() + .await? .into_iter() .pipe(serenity::futures::stream::iter) .then(|info| async move { @@ -361,7 +363,7 @@ pub async fn query(ctx: &Context, msg: &Message, mut args: Args) -> CommandResul } }; - let iter = db::query_meme(args.rest(), creator, order)?.into_iter(); + let iter = db::query_meme(args.rest(), creator, order).await?.into_iter(); let result = iter .pipe(serenity::futures::stream::iter) diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs index 2db9e83..1400452 100644 --- a/src/commands/meme/invoke.rs +++ b/src/commands/meme/invoke.rs @@ -82,10 +82,11 @@ async fn _meme( let search = args.raw().join(" "); - let mut conn = connection()?; - let mem = match find_meme(&mut conn, search) { + let mut conn = connection().await?; + let mem = match find_meme(&mut conn, search).await { Ok(x) => { - InvocationRecord::create(&mut conn, msg.author.id.get(), msg.id.get(), x.id, false)?; + InvocationRecord::create(&mut conn, msg.author.id.get(), msg.id.get(), x.id, false) + .await?; x }, @@ -110,14 +111,14 @@ async fn rand_meme( message: &Message, audio_playback: AudioPlayback, ) -> CommandResult { - let mut conn = connection()?; + let mut conn = connection().await?; let should_audio = util::users_listening(ctx).await?; let mem = match audio_playback { - AudioPlayback::Required => db::rand_audio_meme(&mut conn), - AudioPlayback::Optional => db::rand_meme(&mut conn, should_audio), - AudioPlayback::Prohibited => db::rand_silent_meme(&mut conn), + AudioPlayback::Required => db::rand_audio_meme(&mut conn).await, + AudioPlayback::Optional => db::rand_meme(&mut conn, should_audio).await, + AudioPlayback::Prohibited => db::rand_silent_meme(&mut conn).await, }; match mem { @@ -128,7 +129,8 @@ async fn rand_meme( message.id.get(), mem.id, true, - )?; + ) + .await?; send_meme(ctx, &mem, &mut conn, message).await?; Ok(()) }, @@ -151,12 +153,13 @@ async fn rand_meme( pub async fn rare_meme(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { let should_audio = util::users_listening(ctx).await?; - let mut conn = connection()?; + let mut conn = connection().await?; + let meme = db::rare_meme(&mut conn, should_audio).await; - let meme = db::rare_meme(&mut conn, should_audio); match meme { Ok(meme) => { - InvocationRecord::create(&mut conn, msg.author.id.get(), msg.id.get(), meme.id, true)?; + InvocationRecord::create(&mut conn, msg.author.id.get(), msg.id.get(), meme.id, true) + .await?; send_meme(ctx, &meme, &mut conn, msg).await }, Err(e) => { diff --git a/src/commands/meme/mod.rs b/src/commands/meme/mod.rs index b5a3c98..cfe02ee 100644 --- a/src/commands/meme/mod.rs +++ b/src/commands/meme/mod.rs @@ -78,8 +78,8 @@ async fn send_meme( debug!("sending meme (tts: {}): {:?}", should_tts, t); - let image = t.image(conn); - let audio = t.audio(conn); + let image = t.image(conn).await; + let audio = t.audio(conn).await; let cmsg = { let ret = CreateMessage::default().tts(should_tts); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 8eac09c..69c9185 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -5,7 +5,7 @@ use serenity::framework::{ StandardFramework, }; -#[cfg(feature = "diesel")] +#[cfg(feature = "db")] pub use self::meme::*; pub use self::{ playback::*, @@ -13,6 +13,8 @@ pub use self::{ today::TODAY_COMMAND, }; +#[cfg(feature = "db")] +pub(crate) mod meme; pub(crate) mod playback; pub(crate) mod roll; pub(crate) mod sound_levels; @@ -28,7 +30,7 @@ struct General; pub fn register_commands(f: StandardFramework) -> StandardFramework { let result = f.group(&PLAYBACK_GROUP).group(&GENERAL_GROUP); - #[cfg(feature = "diesel")] + #[cfg(feature = "db")] let result = result.group(&MEMES_GROUP); #[cfg(feature = "games")] @@ -55,6 +57,3 @@ pub fn register_commands(f: StandardFramework) -> StandardFramework { }) }) } - -#[cfg(feature = "diesel")] -mod meme; |
