feat: added nowplaying command
This commit is contained in:
parent
05fae26549
commit
d471bfcb06
5 changed files with 46 additions and 6 deletions
|
@ -2,3 +2,4 @@ pub mod info;
|
|||
pub mod play;
|
||||
pub mod skip;
|
||||
pub mod stop;
|
||||
pub mod now_playing;
|
||||
|
|
43
src/commands/now_playing.rs
Normal file
43
src/commands/now_playing.rs
Normal file
|
@ -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.")
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue