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.rs149
1 files changed, 68 insertions, 81 deletions
diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs
index 1400452..e399e82 100644
--- a/src/commands/meme/invoke.rs
+++ b/src/commands/meme/invoke.rs
@@ -2,19 +2,7 @@ use diesel::{
result::Error as DieselError,
NotFound,
};
-use itertools::Itertools;
use log::info;
-use serenity::{
- framework::standard::{
- macros::command,
- Args,
- CommandError,
- CommandResult,
- },
- futures::TryFutureExt,
- model::channel::Message,
- prelude::*,
-};
use crate::{
commands::meme::send_meme,
@@ -25,42 +13,49 @@ use crate::{
InvocationRecord,
},
util,
+ PoiseContext,
};
-#[command]
-#[aliases("mem")]
-pub async fn meme(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
- _meme(ctx, msg, args, AudioPlayback::Optional).await
+#[poise::command(slash_command, prefix_command, guild_only, category = "memes", aliases("mem"))]
+pub async fn meme(ctx: PoiseContext<'_>, #[rest] rest: String) -> anyhow::Result<()> {
+ _meme(ctx, rest, AudioPlayback::Optional).await
}
-#[command]
-pub async fn omen(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
- let args = Args::new("", &[]);
- _meme(ctx, msg, args, AudioPlayback::Optional).await
+#[poise::command(slash_command, prefix_command, guild_only, category = "memes")]
+pub async fn omen(ctx: PoiseContext<'_>) -> anyhow::Result<()> {
+ _meme(ctx, "", AudioPlayback::Optional).await
}
-#[command]
-pub async fn silentomen(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
- let args = Args::new("", &[]);
- _meme(ctx, msg, args, AudioPlayback::Prohibited).await
+#[poise::command(slash_command, prefix_command, guild_only, category = "memes")]
+pub async fn silentomen(ctx: PoiseContext<'_>) -> anyhow::Result<()> {
+ _meme(ctx, "", AudioPlayback::Prohibited).await
}
-#[command]
-pub async fn audioomen(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
- let args = Args::new("", &[]);
- _meme(ctx, msg, args, AudioPlayback::Required).await
+#[poise::command(slash_command, prefix_command, guild_only, category = "memes")]
+pub async fn audioomen(ctx: PoiseContext<'_>) -> anyhow::Result<()> {
+ _meme(ctx, "", AudioPlayback::Required).await
}
-#[command]
-#[aliases("audiomeme", "audiomem")]
-pub async fn audio_meme(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
- _meme(ctx, msg, args, AudioPlayback::Required).await
+#[poise::command(
+ slash_command,
+ prefix_command,
+ guild_only,
+ category = "memes",
+ aliases("audiomeme", "audiomem")
+)]
+pub async fn audio_meme(ctx: PoiseContext<'_>, #[rest] rest: String) -> anyhow::Result<()> {
+ _meme(ctx, rest, AudioPlayback::Required).await
}
-#[command]
-#[aliases("silentmeme", "silentmem")]
-pub async fn silent_meme(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
- _meme(ctx, msg, args, AudioPlayback::Prohibited).await
+#[poise::command(
+ slash_command,
+ prefix_command,
+ guild_only,
+ category = "memes",
+ aliases("silentmeme", "silentmem")
+)]
+pub async fn silent_meme(ctx: PoiseContext<'_>, #[rest] rest: String) -> anyhow::Result<()> {
+ _meme(ctx, rest, AudioPlayback::Prohibited).await
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -71,21 +66,20 @@ enum AudioPlayback {
}
async fn _meme(
- ctx: &Context,
- msg: &Message,
- args: Args,
+ ctx: PoiseContext<'_>,
+ args: impl AsRef<str>,
audio_playback: AudioPlayback,
-) -> CommandResult {
+) -> anyhow::Result<()> {
+ let args = args.as_ref().trim();
+
if args.is_empty() || audio_playback != AudioPlayback::Optional {
- return rand_meme(ctx, msg, audio_playback).await;
+ return rand_meme(ctx, audio_playback).await;
}
- let search = args.raw().join(" ");
-
let mut conn = connection().await?;
- let mem = match find_meme(&mut conn, search).await {
+ let mem = match find_meme(&mut conn, args).await {
Ok(x) => {
- InvocationRecord::create(&mut conn, msg.author.id.get(), msg.id.get(), x.id, false)
+ InvocationRecord::create(&mut conn, ctx.author().id.get(), ctx.id(), x.id, false)
.await?;
x
@@ -93,27 +87,23 @@ async fn _meme(
Err(e) => {
return if let Some(NotFound) = e.downcast_ref::<DieselError>() {
info!("requested meme not found in database");
- util::send(ctx, msg.channel_id, "c'mon baby, guesstimate", msg.tts)
- .await
- .map_err(CommandError::from)
+
+ util::reply(ctx, "c'mon baby, guesstimate").await?;
+ Ok(())
} else {
- util::send(ctx, msg.channel_id, "what in ryan's name", msg.tts).await?;
+ util::reply(ctx, "what in ryan's name").await?;
Err(e.into())
};
},
};
- send_meme(ctx, &mem, &mut conn, msg).await
+ send_meme(ctx, &mem, &mut conn).await
}
-async fn rand_meme(
- ctx: &Context,
- message: &Message,
- audio_playback: AudioPlayback,
-) -> CommandResult {
+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 should_audio = util::users_listening(ctx.serenity_context()).await?;
let mem = match audio_playback {
AudioPlayback::Required => db::rand_audio_meme(&mut conn).await,
@@ -123,56 +113,53 @@ async fn rand_meme(
match mem {
Ok(mem) => {
- InvocationRecord::create(
- &mut conn,
- message.author.id.get(),
- message.id.get(),
- mem.id,
- true,
- )
- .await?;
- send_meme(ctx, &mem, &mut conn, message).await?;
+ InvocationRecord::create(&mut conn, ctx.author().id.get(), ctx.id(), mem.id, true)
+ .await?;
+ send_meme(ctx, &mem, &mut conn).await?;
Ok(())
},
Err(e) => {
if let Some(NotFound) = e.downcast_ref::<DieselError>() {
info!("random meme not found");
- return util::send(ctx, message.channel_id, "i don't know any :(", message.tts)
- .map_err(CommandError::from)
- .await;
+
+ util::reply(ctx, "i don't know any :(").await?;
+ return Ok(());
}
- util::send(ctx, message.channel_id, "HELP", message.tts).await?;
+ util::reply(ctx, "HELP").await?;
Err(e.into())
},
}
}
-#[command]
-#[aliases("rarememe", "raremem")]
-pub async fn rare_meme(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
- let should_audio = util::users_listening(ctx).await?;
+#[poise::command(
+ slash_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 mut conn = connection().await?;
let meme = db::rare_meme(&mut conn, should_audio).await;
match meme {
Ok(meme) => {
- InvocationRecord::create(&mut conn, msg.author.id.get(), msg.id.get(), meme.id, true)
+ InvocationRecord::create(&mut conn, ctx.author().id.get(), ctx.id(), meme.id, true)
.await?;
- send_meme(ctx, &meme, &mut conn, msg).await
+ send_meme(ctx, &meme, &mut conn).await
},
Err(e) => {
if let Some(NotFound) = e.downcast_ref::<DieselError>() {
info!("rare meme not found");
- return util::send(ctx, msg.channel_id, "i don't know any :(", msg.tts)
- .map_err(CommandError::from)
- .await;
+ util::reply(ctx, "i don't know any :(").await?;
+
+ return Ok(());
}
- util::send(ctx, msg.channel_id, "THE MEME MARKET IS IN FREEFALL", msg.tts)
- .map_err(CommandError::from)
- .await?;
+ util::reply(ctx, "THE MEME MARKET IS IN FREEFALL").await?;
Err(e.into())
},