aboutsummaryrefslogtreecommitdiff
path: root/src/commands/playback.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/playback.rs')
-rw-r--r--src/commands/playback.rs61
1 files changed, 50 insertions, 11 deletions
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<Item = poise::Command<PoiseData, anyhow::Error>> {
- vec![play(), pause(), resume(), die(), list(), skip()]
+ vec![play(), pause(), resume(), die(), list(), skip(), move_()]
}
pub async fn songbird(ctx: PoiseContext<'_>) -> anyhow::Result<(Arc<Songbird>, Arc<Mutex<Call>>)> {
@@ -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::<HttpKey>().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::<songbird::tracks::Track>();
+ // 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(