64 lines
1.7 KiB
Rust
64 lines
1.7 KiB
Rust
|
use std::vec;
|
||
|
|
||
|
use songbird::input::YoutubeDl;
|
||
|
|
||
|
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: search, queue
|
||
|
#[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() {
|
||
|
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 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(())
|
||
|
}
|