This commit is contained in:
2026-03-12 01:03:44 +01:00
parent 2f6f8414d0
commit 8ed01f2049
15 changed files with 180 additions and 15 deletions
+65
View File
@@ -0,0 +1,65 @@
use std::path::PathBuf;
use postcard::{from_bytes, to_stdvec};
use serenity::{
all::{
CommandInteraction, Context, CreateCommandOption, CreateInteractionResponse,
CreateInteractionResponseMessage, EditInteractionResponse,
},
builder::CreateCommand,
model::application::{CommandOptionType, ResolvedOption, ResolvedValue},
};
use types::{
jobs::{DownloadJob, JobResponse, Jobs, PlayJob, SearchJob},
misc::{new_uuid_v4, parse_url_or_default},
};
use url::Url;
pub async fn run(
ctx: &Context,
interaction: &CommandInteraction,
nats_client: &async_nats::Client,
) -> Result<(), serenity::Error> {
let options = interaction.data.options();
if let Some(ResolvedOption {
value: ResolvedValue::String(value),
..
}) = options.first()
{
let url: Url;
let is_url = value.starts_with("https://") || value.starts_with("http://");
if !is_url {
let response = match nats_client
.request(
"corro-dj.search",
to_stdvec(&SearchJob {
uuid: new_uuid_v4(),
query: value.to_string(),
})
.unwrap()
.into(),
)
.await
{
Ok(resp) => resp,
Err(_why) => return Err(serenity::Error::Other("send error")),
};
}
}
Ok(())
}
pub fn register() -> CreateCommand {
CreateCommand::new("play")
.description("Play a song")
.add_option(
CreateCommandOption::new(
CommandOptionType::String,
"song",
"Name or url of the song to play",
)
.required(false),
)
}