aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2021-11-03 01:56:36 -0400
committerNathan Perry <np@nathanperry.dev>2021-11-03 01:56:36 -0400
commit1cead5233b152a340aeaefdf58c1de3aebe5b62b (patch)
tree60fbf4ab2dc944608cf3a1529183268d17edf54f /src
parentf59c15906229d8458844003cedbb4aac78926def (diff)
update, add omen
Diffstat (limited to 'src')
-rw-r--r--src/commands/meme/invoke.rs8
-rw-r--r--src/db/mod.rs14
-rw-r--r--src/main.rs2
3 files changed, 12 insertions, 12 deletions
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
@@ -32,6 +32,12 @@ pub fn meme(ctx: &mut Context, msg: &Message, args: Args) -> Result<()> {
}
#[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<()> {
_meme(ctx, msg, args, AudioPlayback::Required)
@@ -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<Meme> {
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<Meme> {
pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result<Meme> {
use rand::{thread_rng, seq::SliceRandom};
- use std::ops::Try;
let ids: Vec<i32> = if audio {
memes::table
@@ -243,8 +242,7 @@ pub fn rand_meme(conn: &PgConnection, audio: bool) -> Result<Meme> {
};
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<Meme> {
pub fn rand_audio_meme(conn: &PgConnection) -> Result<Meme> {
use rand::{thread_rng, seq::SliceRandom};
- use std::ops::Try;
let ids: Vec<i32> = memes::table
.select(memes::id)
@@ -263,8 +260,7 @@ pub fn rand_audio_meme(conn: &PgConnection) -> Result<Meme> {
.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<Meme> {
pub fn rand_silent_meme(conn: &PgConnection) -> Result<Meme> {
use rand::{thread_rng, seq::SliceRandom};
- use std::ops::Try;
let ids: Vec<i32> = memes::table
.select(memes::id)
@@ -283,8 +278,7 @@ pub fn rand_silent_meme(conn: &PgConnection) -> Result<Meme> {
.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)]