diff --git a/src/commands/mod.rs b/src/commands/mod.rs index aa38f60..085759c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2,3 +2,4 @@ pub mod info; pub mod play; pub mod skip; pub mod stop; +pub mod now_playing; diff --git a/src/commands/now_playing.rs b/src/commands/now_playing.rs new file mode 100644 index 0000000..f506a32 --- /dev/null +++ b/src/commands/now_playing.rs @@ -0,0 +1,43 @@ +use crate::music::{music_queue}; +use crate::util::embed::Embed; +use serenity::all::{CommandInteraction, Context}; +use serenity::builder::{CreateCommand, CreateEmbed}; + +pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { + let username = command.user.name.as_str(); + + let guild_id = match &command.guild_id { + Some(guild_id) => guild_id, + None => { + return Embed::create_error_respose( + username, + "guild_id not found", + "Could not find guild id.", + ); + } + }; + + let now_plaing = match music_queue::get_now_playing(&guild_id).await { + Some(ytdl) => ytdl, + None => { + return Embed::create_error_respose(username, "Not playing", "I'm not playing anything!"); + } + }; + + let manager = songbird::get(ctx) + .await + .expect("Cannot get Songbird") + .clone(); + + let handler = match manager.get(*guild_id) { + Some(handler) => handler, + None => { + return Embed::create_error_respose(username, "Error", "Error while getting the audio handler."); + } + }; + Embed::create_yt_playing(now_plaing, username, "Currently playing").await +} + +pub fn register() -> CreateCommand { + CreateCommand::new("nowplaying").description("Show what is currently playing.") +} diff --git a/src/commands/skip.rs b/src/commands/skip.rs index ccf8ad6..e5609df 100644 --- a/src/commands/skip.rs +++ b/src/commands/skip.rs @@ -24,6 +24,3 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { pub fn register() -> CreateCommand { CreateCommand::new("skip").description("Skip to the next song in queue") } - -// >18/02/2024 @ 19:01:59 - bartlo -// >2024-02-19 17:58:39 | moonleay diff --git a/src/commands/stop.rs b/src/commands/stop.rs index 8800a41..6056141 100644 --- a/src/commands/stop.rs +++ b/src/commands/stop.rs @@ -19,6 +19,3 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { pub fn register() -> CreateCommand { CreateCommand::new("stop").description("Stop playing and start leavin'") } - -// >18/02/2024 @ 19:01:59 - bartlo -// >2024-02-19 17:58:39 | moonleay diff --git a/src/main.rs b/src/main.rs index f9ebb10..a5d9f4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,6 +43,7 @@ impl EventHandler for Handler { "play" => commands::play::run(&ctx, &command).await, "stop" => commands::stop::run(&ctx, &command).await, "skip" => commands::skip::run(&ctx, &command).await, + "nowplaying" => commands::now_playing::run(&ctx, &command).await, _ => respond_with_error(&ctx, &command).await, }); @@ -62,6 +63,7 @@ impl EventHandler for Handler { let _command = Command::create_global_command(&ctx.http, commands::stop::register()).await; let _command = Command::create_global_command(&ctx.http, commands::play::register()).await; let _command = Command::create_global_command(&ctx.http, commands::skip::register()).await; + let _command = Command::create_global_command(&ctx.http, commands::now_playing::register()).await; println!("Commands are registered and Rustendo is ready for Freddy."); }