diff options
| author | Nathan Perry <np@nathanperry.dev> | 2024-05-11 17:43:58 -0400 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2024-05-11 17:43:58 -0400 |
| commit | 332eff26a0a358eef52c307b02b7e1ac080dd15f (patch) | |
| tree | b0c9dd25ff325a8f11f79383295af1a5a05f323b /src/commands/meme | |
| parent | 833f2bed24ab49f1c6242762b6d1e0be9192e870 (diff) | |
db: fixup build, async-await
Diffstat (limited to 'src/commands/meme')
| -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 |
5 files changed, 35 insertions, 29 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); |
