Rustendo/src/commands/play.rs

49 lines
1.4 KiB
Rust

use crate::music::music_manager;
use serenity::all::{CommandDataOptionValue, CommandInteraction, Context};
use serenity::builder::{CreateCommand, CreateCommandOption, CreateEmbed};
use serenity::model::application::CommandOptionType;
use crate::util::embed::Embed;
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
let username = command.user.name.as_str();
let options = &command.data.options;
let query = options.first().and_then(|option| {
if let CommandDataOptionValue::String(query) = &option.value {
Some(query)
} else {
None
}
});
if query.is_none() {
return Embed::create_error_respose(username, "400: Bad request", "There is no query provided");
}
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.");
}
};
music_manager::attempt_to_queue_song(
ctx,
guild_id,
&command.user.id,
&command.user.name,
query.unwrap(),
)
.await
}
pub fn register() -> CreateCommand {
CreateCommand::new("play")
.description("Play music")
.add_option(
CreateCommandOption::new(CommandOptionType::String, "query", "Link or search term")
.required(true),
)
}