diff options
Diffstat (limited to 'src/commands/playback.rs')
| -rw-r--r-- | src/commands/playback.rs | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/commands/playback.rs b/src/commands/playback.rs index 98ae613..48f3286 100644 --- a/src/commands/playback.rs +++ b/src/commands/playback.rs @@ -5,7 +5,10 @@ use log::{ info, warn, }; -use serenity::prelude::*; +use serenity::{ + all::ReactionType, + prelude::*, +}; use songbird::{ input::YoutubeDl, Call, @@ -16,9 +19,14 @@ use crate::{ bot::HttpKey, util, PoiseContext, + PoiseData, CONFIG, }; +pub fn commands() -> impl IntoIterator<Item = poise::Command<PoiseData, anyhow::Error>> { + vec![play(), pause(), resume(), die(), list(), skip()] +} + pub async fn songbird(ctx: PoiseContext<'_>) -> anyhow::Result<(Arc<Songbird>, Arc<Mutex<Call>>)> { let Some(gid) = ctx.guild_id() else { return Err(anyhow::anyhow!("no guild id").into()); @@ -46,7 +54,7 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> _ => None, }); - if host.map(|h| h.to_lowercase().contains("imgur")).unwrap_or(false) { + if host.is_some_and(|h| h.to_lowercase().contains("imgur")) { info!("detected imgur link"); if ctx.author().id == 106160362109272064 { @@ -73,10 +81,13 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> let input = YoutubeDl::new_ytdl_like("yt-dlp", client.clone(), url.to_string()); call.enqueue_input(input.into()).await; + util::react(ctx, ReactionType::Unicode("📣".to_owned())).await?; + Ok(()) } -#[poise::command(slash_command, prefix_command, guild_only, category = "playback")] +/// Play a link. +#[poise::command(prefix_command, guild_only, category = "playback")] pub async fn play( ctx: PoiseContext<'_>, #[description = "link to play (if absent, resumes playback)"] u: Option<url::Url>, @@ -88,7 +99,8 @@ pub async fn play( _play(ctx, &u).await } -#[poise::command(slash_command, prefix_command, guild_only, category = "playback")] +/// Pause audio playback. +#[poise::command(prefix_command, guild_only, category = "playback")] pub async fn pause(ctx: PoiseContext<'_>) -> anyhow::Result<()> { let (_sb, call) = songbird(ctx).await?; @@ -98,13 +110,8 @@ pub async fn pause(ctx: PoiseContext<'_>) -> anyhow::Result<()> { Ok(()) } -#[poise::command( - slash_command, - prefix_command, - guild_only, - aliases("continue"), - category = "playback" -)] +/// Resume audio playback. +#[poise::command(prefix_command, guild_only, aliases("continue"), category = "playback")] pub async fn resume(ctx: PoiseContext<'_>) -> anyhow::Result<()> { _resume(ctx).await } @@ -118,7 +125,8 @@ async fn _resume(ctx: PoiseContext<'_>) -> anyhow::Result<()> { Ok(()) } -#[poise::command(slash_command, prefix_command, guild_only, category = "playback", aliases("next"))] +/// Skip the current track in the queue. +#[poise::command(prefix_command, guild_only, category = "playback", aliases("next"))] pub async fn skip(ctx: PoiseContext<'_>) -> anyhow::Result<()> { let (_sb, call) = songbird(ctx).await?; @@ -128,12 +136,12 @@ pub async fn skip(ctx: PoiseContext<'_>) -> anyhow::Result<()> { Ok(()) } +/// Stop playing audio and delete the queue. #[poise::command( - slash_command, prefix_command, guild_only, category = "playback", - aliases("sudoku", "fuckoff", "stop") + aliases("sudoku", "fuckoff", "stop", "kill") )] pub async fn die(ctx: PoiseContext<'_>) -> anyhow::Result<()> { let (_sb, call) = songbird(ctx).await?; @@ -146,13 +154,8 @@ pub async fn die(ctx: PoiseContext<'_>) -> anyhow::Result<()> { Ok(()) } -#[poise::command( - slash_command, - prefix_command, - guild_only, - category = "playback", - aliases("queue") -)] +/// List queued audio. +#[poise::command(prefix_command, guild_only, category = "playback", aliases("queue"))] pub async fn list(ctx: PoiseContext<'_>) -> anyhow::Result<()> { let (_sb, call) = songbird(ctx).await?; |
