aboutsummaryrefslogtreecommitdiff
path: root/src/commands/meme/invoke.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/meme/invoke.rs')
-rw-r--r--src/commands/meme/invoke.rs77
1 files changed, 58 insertions, 19 deletions
diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs
index 37a78f5..aff5c23 100644
--- a/src/commands/meme/invoke.rs
+++ b/src/commands/meme/invoke.rs
@@ -1,5 +1,6 @@
use diesel::{
result::Error as DieselError,
+ row::NamedRow,
NotFound,
};
use grate::tracing;
@@ -79,14 +80,23 @@ pub(crate) async fn _meme(
return rand_meme(ctx, audio_playback).await;
}
+ let guild_id = util::guild_id(ctx)?;
+
let mut conn = connection().await?;
- let mem = match find_meme(&mut conn, args).await {
+ let mem = match find_meme(&mut conn, args, guild_id.get()).await {
Ok(x) => {
- InvocationRecord::create(&mut conn, ctx.author().id.get(), ctx.id(), x.id, false)
+ InvocationRecord::create(
+ &mut conn,
+ ctx.author().id.get(),
+ ctx.id(),
+ guild_id.get(),
+ x.id,
+ false,
+ )
.await?;
x
- },
+ }
Err(e) => {
return if let Some(NotFound) = e.downcast_ref::<DieselError>() {
tracing::info!("requested meme not found in database");
@@ -97,30 +107,43 @@ pub(crate) async fn _meme(
util::reply(ctx, "what in ryan's name").await?;
Err(e.into())
};
- },
+ }
};
send_meme(ctx, &mem, &mut conn).await
}
async fn rand_meme(ctx: PoiseContext<'_>, audio_playback: AudioPlayback) -> anyhow::Result<()> {
- let mut conn = connection().await?;
+ let should_audio = util::users_listening(ctx).await?;
+ let guild_id = util::guild_id(ctx)?;
- let should_audio = util::users_listening(ctx.serenity_context()).await?;
+ let mut conn = connection().await?;
let mem = match audio_playback {
- 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,
+ AudioPlayback::Required => db::rand_audio_meme(&mut conn, guild_id.get()).await,
+ AudioPlayback::Optional => db::rand_meme(&mut conn, should_audio, guild_id.get()).await,
+ AudioPlayback::Prohibited => db::rand_silent_meme(&mut conn, guild_id.get()).await,
};
match mem {
- Ok(mem) => {
- InvocationRecord::create(&mut conn, ctx.author().id.get(), ctx.id(), mem.id, true)
+ Ok(Some(mem)) => {
+ InvocationRecord::create(
+ &mut conn,
+ ctx.author().id.get(),
+ util::guild_id(ctx)?.get(),
+ ctx.id(),
+ mem.id,
+ true,
+ )
.await?;
send_meme(ctx, &mem, &mut conn).await?;
Ok(())
- },
+ }
+ Ok(None) => {
+ tracing::info!("random meme not found");
+ util::reply(ctx, "i don't know any :(").await?;
+ Ok(())
+ }
Err(e) => {
if let Some(NotFound) = e.downcast_ref::<DieselError>() {
tracing::info!("random meme not found");
@@ -131,24 +154,40 @@ async fn rand_meme(ctx: PoiseContext<'_>, audio_playback: AudioPlayback) -> anyh
util::reply(ctx, "HELP").await?;
Err(e.into())
- },
+ }
}
}
/// Post a rare meme.
#[poise::command(prefix_command, guild_only, category = "memes", aliases("raremem", "rarememe"))]
pub async fn rare_meme(ctx: PoiseContext<'_>) -> anyhow::Result<()> {
- let should_audio = util::users_listening(ctx.serenity_context()).await?;
+ let guild = util::guild_id(ctx)?;
+ let should_audio = util::users_listening(ctx).await?;
let mut conn = connection().await?;
- let meme = db::rare_meme(&mut conn, should_audio).await;
+ let meme = db::rare_meme(&mut conn, should_audio, guild.get()).await;
match meme {
- Ok(meme) => {
- InvocationRecord::create(&mut conn, ctx.author().id.get(), ctx.id(), meme.id, true)
+ Ok(Some(meme)) => {
+ InvocationRecord::create(
+ &mut conn,
+ ctx.author().id.get(),
+ util::guild_id(ctx)?.get(),
+ ctx.id(),
+ meme.id,
+ true,
+ )
.await?;
send_meme(ctx, &meme, &mut conn).await
- },
+ }
+
+ Ok(None) => {
+ tracing::info!("rare meme not found");
+ util::reply(ctx, "i don't know any :(").await?;
+
+ Ok(())
+ }
+
Err(e) => {
if let Some(NotFound) = e.downcast_ref::<DieselError>() {
tracing::info!("rare meme not found");
@@ -160,6 +199,6 @@ pub async fn rare_meme(ctx: PoiseContext<'_>) -> anyhow::Result<()> {
util::reply(ctx, "THE MEME MARKET IS IN FREEFALL").await?;
Err(e.into())
- },
+ }
}
}