2025-01-09 17:57:42 +00:00
|
|
|
use std::vec;
|
|
|
|
|
|
|
|
use songbird::input::YoutubeDl;
|
|
|
|
|
2025-01-26 20:45:24 +00:00
|
|
|
use crate::types::{Context, ContextExt, Error};
|
2025-01-24 20:52:13 +00:00
|
|
|
use crate::commands::voice::voice_utils::autocomplete_channel;
|
|
|
|
|
|
|
|
use super::connect;
|
2025-01-09 17:57:42 +00:00
|
|
|
|
2025-01-26 22:47:57 +00:00
|
|
|
// For list of supported URLs visit https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md
|
2025-01-09 17:57:42 +00:00
|
|
|
#[poise::command(
|
|
|
|
slash_command,
|
|
|
|
description_localized("en-US", "Plays music from supported URL")
|
|
|
|
)]
|
|
|
|
pub async fn play(ctx: Context<'_>,
|
|
|
|
#[autocomplete = "autocomplete_channel"]
|
|
|
|
#[description = "Voice channel name: "]
|
|
|
|
channel: Option<String>,
|
|
|
|
#[description = "Source URL: "]
|
|
|
|
url: String,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
if ctx.guild().is_none() {
|
|
|
|
ctx.reply_ephemeral("Can't use this outside of guild").await?;
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
let manager = songbird::get(ctx.serenity_context())
|
|
|
|
.await
|
|
|
|
.expect("Songbird Voice client placed in at initialisation.")
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
let Some(guild_id) = ctx.guild_id() else {
|
|
|
|
ctx.reply_ephemeral("Guild id not found").await?;
|
|
|
|
return Ok(())
|
|
|
|
};
|
|
|
|
|
|
|
|
let http_client = &ctx.data().http_client;
|
|
|
|
|
|
|
|
if manager.get(guild_id).is_none() {
|
2025-01-24 20:52:13 +00:00
|
|
|
if let Err(e) = connect(&ctx, guild_id, channel).await {
|
|
|
|
ctx.reply_ephemeral(&e.to_string()).await?;
|
|
|
|
return Ok(())
|
2025-01-09 17:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(handler_lock) = manager.get(guild_id) {
|
|
|
|
let mut handler = handler_lock.lock().await;
|
|
|
|
|
|
|
|
let src = YoutubeDl::new(http_client.clone(), url);
|
|
|
|
handler.enqueue_input(src.into()).await;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ctx.reply_ephemeral("Not in a voice channel").await?;
|
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.reply_ephemeral("Done!").await?;
|
|
|
|
Ok(())
|
|
|
|
}
|