From c9e6b2e681088687f5a714c3324d4d0731b8393e Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Fri, 16 Aug 2024 02:53:45 -0400 Subject: better unrecognized handling, more expressive react/unreact indicators --- src/commands/meme/create.rs | 9 +++++++-- src/commands/meme/invoke.rs | 7 ++++--- src/commands/meme/mod.rs | 2 +- src/commands/mod.rs | 8 +------- src/commands/playback.rs | 10 +++++----- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/commands') diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index c28f583..185e1f6 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -68,7 +68,7 @@ pub async fn addmeme( use diesel::result::DatabaseErrorKind; match save_result { Ok(_) => { - util::react(ctx, ReactionType::Unicode("👌".to_string())).await?; + util::react(ctx, '👌').await?; }, Err(e) => { if let Some(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) = @@ -76,7 +76,7 @@ pub async fn addmeme( { error!("tried to create meme that already exists"); - util::react(ctx, ReactionType::Unicode("❌".to_owned())).await?; + util::react(ctx, '❌').await?; util::reply(ctx, "that meme already exists").await?; return Ok(()); @@ -110,6 +110,8 @@ pub async fn addaudiomeme( let opts = elems[1..].join(" "); let (start, end) = parse_times(opts); + util::react(ctx, '🔃').await?; + let youtube_url = util::ytdl_url(audio_link.as_str()).await?; debug!("got download url: {youtube_url}"); @@ -169,6 +171,7 @@ pub async fn addaudiomeme( if bytes == 0 { debug!("read 0 bytes from audio reader"); + util::unreact(ctx, '🔃').await?; util::reply(ctx, "🔇🔇🔇🔕🔕🔕🔕🔕🔇🔕🔕🔇🔕🔕📣📢📣📢📣").await?; return Ok(()); } @@ -186,6 +189,8 @@ pub async fn addaudiomeme( .await .map(|_| {}); + util::unreact(ctx, '🔃').await?; + use diesel::result::DatabaseErrorKind; match save_result { Ok(_) => { diff --git a/src/commands/meme/invoke.rs b/src/commands/meme/invoke.rs index 31b0085..1d9040d 100644 --- a/src/commands/meme/invoke.rs +++ b/src/commands/meme/invoke.rs @@ -60,14 +60,15 @@ pub async fn silent_meme(ctx: PoiseContext<'_>) -> anyhow::Result<()> { _meme(ctx, "", AudioPlayback::Prohibited).await } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -enum AudioPlayback { +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)] +pub(crate) enum AudioPlayback { Required, + #[default] Optional, Prohibited, } -async fn _meme( +pub(crate) async fn _meme( ctx: PoiseContext<'_>, args: impl AsRef, audio_playback: AudioPlayback, diff --git a/src/commands/meme/mod.rs b/src/commands/meme/mod.rs index 9495ec7..ca7714a 100644 --- a/src/commands/meme/mod.rs +++ b/src/commands/meme/mod.rs @@ -40,7 +40,7 @@ use crate::{ mod create; mod delete; mod history; -mod invoke; +pub(crate) mod invoke; pub fn commands() -> Vec> { vec![ diff --git a/src/commands/mod.rs b/src/commands/mod.rs index b7a8378..2729580 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2,7 +2,6 @@ use poise::builtins::PrettyHelpConfiguration; use crate::{ commands::playback::_play, - util, PoiseContext, }; @@ -49,12 +48,7 @@ pub async fn help(ctx: PoiseContext<'_>, command: Option) -> anyhow::Res Ok(()) } -pub async fn unrecognized(ctx: PoiseContext<'_>, u: url::Url) -> anyhow::Result<()> { - if !u.scheme().starts_with("http") { - util::reply(ctx, "format your commands right. fuck you.").await?; - return Ok(()); - } - +pub async fn link_unrecognized(ctx: PoiseContext<'_>, u: url::Url) -> anyhow::Result<()> { let _ = _play(ctx, &u).await?; Ok(()) diff --git a/src/commands/playback.rs b/src/commands/playback.rs index 70dd704..9b74c02 100644 --- a/src/commands/playback.rs +++ b/src/commands/playback.rs @@ -5,10 +5,7 @@ use log::{ info, warn, }; -use serenity::{ - all::ReactionType, - prelude::*, -}; +use serenity::prelude::*; use songbird::{ input::YoutubeDl, Call, @@ -66,6 +63,8 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> return Ok(()); } + util::react(ctx, '🔃').await?; + let (_sb, call) = songbird(ctx).await?; let mut call = call.lock().await; @@ -82,7 +81,8 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> YoutubeDl::new_ytdl_like(&crate::config::YTDL_COMMAND, client.clone(), url.to_string()); call.enqueue_input(input.into()).await; - util::react(ctx, ReactionType::Unicode("📣".to_owned())).await?; + util::react(ctx, '📣').await?; + util::unreact(ctx, '🔃').await?; Ok(()) } -- cgit v1.3.1