Rustendo/src/commands/now_playing.rs

43 lines
1.3 KiB
Rust

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.")
}