2024-12-17 14:28:52 +00:00
|
|
|
use std::vec;
|
|
|
|
|
|
|
|
use songbird::input::{File, Input};
|
|
|
|
|
|
|
|
use crate::util::debug::send_error;
|
|
|
|
use crate::util::poise_context_extension::ContextExt;
|
|
|
|
use crate::util::utilities::get_local_songs;
|
2025-01-06 11:51:57 +00:00
|
|
|
use crate::types::{Context, Error};
|
2024-12-17 14:28:52 +00:00
|
|
|
|
2025-01-06 11:51:57 +00:00
|
|
|
use super::util::{connect, autocomplete_channel};
|
2024-12-17 14:28:52 +00:00
|
|
|
|
2025-01-09 17:57:42 +00:00
|
|
|
/**
|
|
|
|
* Common commands that are the same for every implementation
|
|
|
|
*/
|
2024-12-17 14:28:52 +00:00
|
|
|
|
|
|
|
#[poise::command(
|
|
|
|
slash_command,
|
|
|
|
description_localized("en-US", "Disconnect from voice channel")
|
|
|
|
)]
|
|
|
|
pub async fn disconnect(
|
|
|
|
ctx: Context<'_>
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let Some(guild_id) = ctx.guild_id() else {
|
2025-01-09 17:57:42 +00:00
|
|
|
ctx.reply_ephemeral("Can't use this outside of guild").await?;
|
2024-12-17 14:28:52 +00:00
|
|
|
return Ok(());
|
|
|
|
};
|
|
|
|
|
|
|
|
let manager = songbird::get(ctx.serenity_context())
|
|
|
|
.await
|
|
|
|
.expect("Songbird Voice client placed in at initialisation.")
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
let has_handler = manager.get(guild_id).is_some();
|
|
|
|
|
|
|
|
if ! has_handler {
|
|
|
|
ctx.reply("I am not connected to a channel!").await?;
|
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
match manager.remove(guild_id).await {
|
|
|
|
Ok(()) => {
|
2025-01-09 17:57:42 +00:00
|
|
|
ctx.reply_ephemeral("Disconnected").await?;
|
2024-12-17 14:28:52 +00:00
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
let _ = send_error(ctx.serenity_context().http.clone(), e.to_string()).await;
|
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn autocomplete_song(
|
|
|
|
_ctx: Context<'_>,
|
|
|
|
partial: &str,
|
|
|
|
) -> Vec<String> {
|
|
|
|
|
|
|
|
match get_local_songs(partial) {
|
|
|
|
Ok(names) => names,
|
|
|
|
Err(_) => vec![]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[poise::command(
|
|
|
|
slash_command,
|
2025-01-06 11:51:57 +00:00
|
|
|
description_localized("en-US", "Play song from server storage")
|
2024-12-17 14:28:52 +00:00
|
|
|
)]
|
|
|
|
pub async fn play_local(ctx: Context<'_>,
|
|
|
|
#[autocomplete = "autocomplete_channel"]
|
|
|
|
#[description = "Voice channel name: "]
|
2025-01-06 11:51:57 +00:00
|
|
|
channel: Option<String>,
|
2024-12-17 14:28:52 +00:00
|
|
|
#[autocomplete = "autocomplete_song"]
|
|
|
|
#[description = "Filename of local song: "]
|
|
|
|
file_name: 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(())
|
|
|
|
};
|
|
|
|
|
2025-01-06 11:51:57 +00:00
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-17 14:28:52 +00:00
|
|
|
|
|
|
|
if let Some(handler_lock) = manager.get(guild_id) {
|
|
|
|
let mut handler = handler_lock.lock().await;
|
|
|
|
|
|
|
|
let input_file = File::new(format!("/home/emil/Music/{file_name}"));
|
|
|
|
let input = Input::Lazy(Box::new(input_file));
|
2025-01-06 11:51:57 +00:00
|
|
|
let _ = handler.play_only_input(input);
|
2024-12-17 14:28:52 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ctx.reply_ephemeral("Not in a voice channel").await?;
|
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.reply_ephemeral("Done!").await?;
|
|
|
|
Ok(())
|
|
|
|
}
|