From 1cead5233b152a340aeaefdf58c1de3aebe5b62b Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Wed, 3 Nov 2021 01:56:36 -0400 Subject: update, add omen --- src/commands/meme/invoke.rs | 8 +++++++- src/db/mod.rs | 14 ++++---------- src/main.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs index d0b7a19..d966d8c 100644 --- a/src/commands/meme/invoke.rs +++ b/src/commands/meme/invoke.rs @@ -31,6 +31,12 @@ pub fn meme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> { _meme(ctx, msg, args, AudioPlayback::Optional) } +#[command] +pub fn omen(ctx: &mut Context, msg: &Message, _args: Args) -> Result<()> { + let args = Args::new("", &[]); + _meme(ctx, msg, args, AudioPlayback::Optional) +} + #[command] #[aliases("audiomeme", "audiomem")] pub fn audio_meme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> { @@ -120,7 +126,7 @@ pub fn rare_meme(ctx: &mut Context, msg: &Message, _args: Args) -> Result<()> { match meme { Ok(meme) => { - InvocationRecord::create(&conn, msg.author.id.0, msg.id.0, meme.id, true)?; + r InvocationRecord::create(&conn, msg.author.id.0, msg.id.0, meme.id, true)?; send_meme(ctx, &meme, &conn, msg) }, Err(e) => { diff --git a/src/db/mod.rs b/src/db/mod.rs index db6cfb8..611526f 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -215,7 +215,7 @@ pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result { let meme_id = elems.into_iter() .find(|(_, x)| target_prob < *x) - .ok_or(anyhow!("couldn't locate meme satisfying target probability"))? + .ok_or_else(|| anyhow!("couldn't locate meme satisfying target probability"))? .0; Meme::find(conn, meme_id) @@ -223,7 +223,6 @@ pub fn rare_meme(conn: &PgConnection, audio: bool) -> Result { pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result { use rand::{thread_rng, seq::SliceRandom}; - use std::ops::Try; let ids: Vec = if audio { memes::table @@ -243,8 +242,7 @@ pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result { }; let id = ids.choose(&mut thread_rng()) - .into_result() - .map_err( |_| anyhow!("couldn't load meme"))?; + .ok_or_else(|| anyhow!("couldn't load meme"))?; memes::table .find(id) @@ -254,7 +252,6 @@ pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result { pub fn rand_audio_meme(conn: &PgConnection) -> Result { use rand::{thread_rng, seq::SliceRandom}; - use std::ops::Try; let ids: Vec = memes::table .select(memes::id) @@ -263,8 +260,7 @@ pub fn rand_audio_meme(conn: &PgConnection) -> Result { .map_err(Error::from)?; let id = ids.choose(&mut thread_rng()) - .into_result() - .map_err(|_| anyhow!("couldn't load audio meme"))?; + .ok_or_else(|| anyhow!("couldn't load audio meme"))?; memes::table .find(id) @@ -274,7 +270,6 @@ pub fn rand_audio_meme(conn: &PgConnection) -> Result { pub fn rand_silent_meme(conn: &PgConnection) -> Result { use rand::{thread_rng, seq::SliceRandom}; - use std::ops::Try; let ids: Vec = memes::table .select(memes::id) @@ -283,8 +278,7 @@ pub fn rand_silent_meme(conn: &PgConnection) -> Result { .map_err(Error::from)?; let id = ids.choose(&mut thread_rng()) - .into_result() - .map_err(|_| anyhow!("couldn't load audio meme"))?; + .ok_or_else(|| anyhow!("couldn't load audio meme"))?; memes::table .find(id) diff --git a/src/main.rs b/src/main.rs index 259a652..eebc726 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -#![feature(try_trait)] +#![feature(try_trait_v2)] #![feature(pattern)] #![feature(concat_idents)] #![feature(associated_type_defaults)] -- cgit v1.3.1