use std::vec; use reqwest::Client; use songbird::input::Input; use songbird::input::HttpRequest; use crate::commands::util::connect; use crate::util::poise_context_extension::ContextExt; use crate::types::{Context, Error}; use crate::commands::voice::util::autocomplete_channel; // TODO: autocomplete radio stream URLs #[poise::command( slash_command, description_localized("en-US", "Plays music from URL source") )] pub async fn radio(ctx: Context<'_>, #[autocomplete = "autocomplete_channel"] #[description = "Voice channel name: "] channel: Option, #[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(()) }; if manager.get(guild_id).is_none() { match connect(&ctx, guild_id, channel).await { Ok(_) => (), Err(e) => { ctx.reply_ephemeral(&e.to_string()).await?; return Ok(()) } } } if let Some(handler_lock) = manager.get(guild_id) { let mut handler = handler_lock.lock().await; let client = Client::new(); let request = HttpRequest::new(client, url); let input = Input::from(request); handler.play_only_input(input); } else { ctx.reply_ephemeral("Not in a voice channel").await?; return Ok(()) } ctx.reply_ephemeral("Done!").await?; Ok(()) }