2024-12-17 14:28:52 +00:00
|
|
|
use std::vec;
|
|
|
|
|
2025-01-26 20:45:24 +00:00
|
|
|
use poise::CreateReply;
|
2024-12-17 14:28:52 +00:00
|
|
|
use songbird::input::{File, Input};
|
2025-01-31 22:24:33 +00:00
|
|
|
use songbird::TrackEvent;
|
2024-12-17 14:28:52 +00:00
|
|
|
|
2025-01-24 20:52:13 +00:00
|
|
|
use crate::utils::debug::send_error;
|
2025-01-26 20:45:24 +00:00
|
|
|
use crate::types::{Context, ContextExt, Error};
|
2025-01-24 20:52:13 +00:00
|
|
|
use crate::utils::utilities::get_local_songs;
|
2024-12-17 14:28:52 +00:00
|
|
|
|
2025-01-24 20:52:13 +00:00
|
|
|
use super::voice_utils::{connect, autocomplete_channel};
|
2024-12-17 14:28:52 +00:00
|
|
|
|
2025-01-26 22:47:57 +00:00
|
|
|
|
|
|
|
/************************************************************
|
2025-01-09 17:57:42 +00:00
|
|
|
* Common commands that are the same for every implementation
|
2025-01-26 22:47:57 +00:00
|
|
|
************************************************************/
|
2024-12-17 14:28:52 +00:00
|
|
|
|
2025-01-26 22:47:57 +00:00
|
|
|
/// Disconnect bot from voice channel
|
2024-12-17 14:28:52 +00:00
|
|
|
#[poise::command(
|
|
|
|
slash_command,
|
2025-01-27 16:55:26 +00:00
|
|
|
description_localized("en-US", "Disconnect from voice channel"),
|
2025-01-31 22:24:33 +00:00
|
|
|
category = "Voice",
|
|
|
|
guild_only
|
2024-12-17 14:28:52 +00:00
|
|
|
)]
|
|
|
|
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 {
|
2025-01-30 18:21:45 +00:00
|
|
|
ctx.reply_ephemeral("I am not connected to a channel!").await?;
|
2024-12-17 14:28:52 +00:00
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-26 21:47:06 +00:00
|
|
|
#[allow(dead_code)]
|
2024-12-17 14:28:52 +00:00
|
|
|
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-27 16:55:26 +00:00
|
|
|
description_localized("en-US", "Play song from server storage"),
|
2025-01-31 22:24:33 +00:00
|
|
|
category = "Voice",
|
|
|
|
guild_only
|
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> {
|
2025-02-01 23:11:29 +00:00
|
|
|
let events = vec![TrackEvent::End];
|
2025-01-31 22:24:33 +00:00
|
|
|
let (manager, guild_id) = match connect(&ctx, channel, events).await {
|
|
|
|
Ok(result) => result,
|
|
|
|
Err(e) => {
|
|
|
|
ctx.reply_ephemeral(&e.to_string()).await?;
|
|
|
|
println!("SONGBIRD MANAGER ERROR: {}", e.to_string());
|
|
|
|
return Ok(())
|
2025-01-06 11:51:57 +00:00
|
|
|
}
|
2025-01-31 22:24:33 +00:00
|
|
|
};
|
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(())
|
|
|
|
}
|
2025-01-26 20:45:24 +00:00
|
|
|
|
2025-01-26 22:47:57 +00:00
|
|
|
/// Sends embed with some info about currently playing source
|
2025-01-26 20:45:24 +00:00
|
|
|
#[poise::command(
|
|
|
|
slash_command,
|
2025-01-27 16:55:26 +00:00
|
|
|
description_localized("en-US", "Display currently playing info"),
|
2025-01-31 22:24:33 +00:00
|
|
|
category = "Voice",
|
|
|
|
guild_only
|
2025-01-26 20:45:24 +00:00
|
|
|
)]
|
|
|
|
pub async fn playing(ctx: Context<'_>) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let Some(guild_id) = ctx.guild_id() else {
|
|
|
|
ctx.reply_ephemeral("Guild id not found").await?;
|
|
|
|
return Ok(())
|
|
|
|
};
|
|
|
|
|
|
|
|
let manager = songbird::get(ctx.serenity_context())
|
|
|
|
.await
|
|
|
|
.expect("Songbird Voice client placed in at initialisation.")
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
let Some(_) = manager.get(guild_id) else {
|
|
|
|
ctx.reply_ephemeral("I am not connected to any voice channel right now").await?;
|
|
|
|
return Ok(())
|
|
|
|
};
|
|
|
|
|
|
|
|
let embed = {
|
|
|
|
let mutex_hashmap = ctx.data().playing_info.lock().await;
|
|
|
|
let Some(playing_info) = mutex_hashmap.get(&guild_id) else {
|
|
|
|
ctx.reply_ephemeral("Entry not found, try to reconnect me").await?;
|
|
|
|
return Ok(());
|
|
|
|
};
|
|
|
|
|
|
|
|
playing_info.generate_embed().await
|
|
|
|
};
|
|
|
|
|
|
|
|
ctx.send(
|
|
|
|
CreateReply::default()
|
|
|
|
.embed(embed)
|
|
|
|
).await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|