From ef056edf92b678265a4666e1f9405e3b0ce66a42 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Fri, 16 Aug 2024 21:14:30 -0400 Subject: repo: overhaul for multitenancy --- src/commands/playback.rs | 61 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'src/commands/playback.rs') diff --git a/src/commands/playback.rs b/src/commands/playback.rs index 50ac8bb..8121136 100644 --- a/src/commands/playback.rs +++ b/src/commands/playback.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use grate::tracing; use serenity::prelude::*; use songbird::{ @@ -5,7 +7,7 @@ use songbird::{ Call, Songbird, }; -use std::sync::Arc; +use tap::Conv; use crate::{ bot::HttpKey, @@ -16,7 +18,7 @@ use crate::{ }; pub fn commands() -> impl IntoIterator> { - vec![play(), pause(), resume(), die(), list(), skip()] + vec![play(), pause(), resume(), die(), list(), skip(), move_()] } pub async fn songbird(ctx: PoiseContext<'_>) -> anyhow::Result<(Arc, Arc>)> { @@ -58,23 +60,36 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> return Ok(()); } - util::react(ctx, '🔃').await?; + let Some(voice_channel) = util::best_voice_channel(ctx) else { + tracing::error!(?ctx, "couldn't find a relevant voice channel"); + util::react(ctx, '🔇').await?; - let (_sb, call) = songbird(ctx).await?; - let mut call = call.lock().await; + return Ok(()); + }; - if call.current_channel().is_none() { - call.join(CONFIG.discord.voice_channel()).await?; - } + util::react(ctx, '🔃').await?; let client = { let data = ctx.serenity_context().data.read().await; data.get::().unwrap().clone() }; - let input = - YoutubeDl::new_ytdl_like(&crate::config::YTDL_COMMAND, client.clone(), url.to_string()); - call.enqueue_input(input.into()).await; + { + let (_sb, call) = songbird(ctx).await?; + let mut call = call.lock().await; + + if call.current_channel().is_none() { + call.join(voice_channel).await?; + } + + let input = + YoutubeDl::new_ytdl_like(&crate::config::YTDL_COMMAND, client.clone(), url.to_string()); + + let track = input.conv::(); + // TODO: store enqueueing channel so songbird handler can switch channels + + call.enqueue(track).await; + } util::react(ctx, '📣').await?; util::unreact(ctx, '🔃').await?; @@ -82,6 +97,30 @@ pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> Ok(()) } +/// Move audio to the caller's voice channel. +#[poise::command(rename = "move", prefix_command, guild_only, category = "playback")] +pub async fn move_(ctx: PoiseContext<'_>) -> anyhow::Result<()> { + let (_sb, call) = songbird(ctx).await?; + let mut call = call.lock().await; + + if call.current_channel().is_none() { + tracing::debug!("no current channel"); + util::reply(ctx, "let's get yer head screwed on straight").await?; + + return Ok(()); + } + + let Some(voice_channel) = util::best_voice_channel(ctx) else { + tracing::error!(?ctx, "couldn't find a relevant voice channel"); + util::react(ctx, '🔇').await?; + + return Ok(()); + }; + + call.join(voice_channel).await?; + Ok(()) +} + /// Play a link. #[poise::command(prefix_command, guild_only, category = "playback")] pub async fn play( -- cgit v1.3.1