playing works
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use postcard::{from_bytes, to_stdvec};
|
||||
use serenity::{
|
||||
all::{
|
||||
@@ -12,7 +14,7 @@ use serenity::{
|
||||
model::application::{CommandOptionType, ResolvedOption, ResolvedValue},
|
||||
};
|
||||
use types::{
|
||||
jobs::{DownloadJob, DownloadResponse, JobResponse},
|
||||
jobs::{DownloadJob, JobResponse, Jobs, PlayJob},
|
||||
misc::new_uuid_v4,
|
||||
};
|
||||
|
||||
@@ -38,37 +40,69 @@ pub async fn run(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let job = DownloadJob {
|
||||
let download_job = DownloadJob {
|
||||
uuid: new_uuid_v4(),
|
||||
url: value.to_string(),
|
||||
};
|
||||
|
||||
println!("job {:?}", job);
|
||||
println!("job {:?}", download_job);
|
||||
|
||||
let response = match nats_client
|
||||
.request("corro-dj.play", to_stdvec(&job).unwrap().into())
|
||||
.request(
|
||||
"corro-dj.download",
|
||||
to_stdvec(&download_job).unwrap().into(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(resp) => resp,
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
};
|
||||
|
||||
let job_response: JobResponse<DownloadResponse> = from_bytes(&response.payload).unwrap();
|
||||
let job_response: JobResponse<Jobs> = from_bytes(&response.payload).unwrap();
|
||||
|
||||
println!("response: {:?}", job_response);
|
||||
|
||||
let text_response: String;
|
||||
|
||||
if let Some(error) = job_response.error {
|
||||
text_response = error;
|
||||
} else if let Some(content) = job_response.content {
|
||||
} else if let Some(Jobs::Download(content)) = job_response.content {
|
||||
text_response = content.path.display().to_string();
|
||||
} else {
|
||||
text_response = "unkown".to_string();
|
||||
}
|
||||
|
||||
interaction
|
||||
.edit_response(ctx, EditInteractionResponse::new().content(text_response))
|
||||
.edit_response(ctx, EditInteractionResponse::new().content(&text_response))
|
||||
.await?;
|
||||
|
||||
let guild_id = interaction.guild_id.unwrap();
|
||||
|
||||
let channel_id = guild_id
|
||||
.get_user_voice_state(&ctx.http, interaction.user.id)
|
||||
.await
|
||||
.unwrap()
|
||||
.channel_id
|
||||
.unwrap();
|
||||
|
||||
let play_job = PlayJob {
|
||||
uuid: new_uuid_v4(),
|
||||
path: PathBuf::from(&text_response),
|
||||
guild_id: guild_id.into(),
|
||||
channel_id: channel_id.into(),
|
||||
};
|
||||
|
||||
println!("job {:?}", play_job);
|
||||
|
||||
let _ = match nats_client
|
||||
.request("corro-dj.play", to_stdvec(&play_job).unwrap().into())
|
||||
.await
|
||||
{
|
||||
Ok(resp) => resp,
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
};
|
||||
|
||||
interaction
|
||||
.edit_response(ctx, EditInteractionResponse::new().content("playing..."))
|
||||
.await?;
|
||||
} else {
|
||||
interaction
|
||||
@@ -85,10 +119,14 @@ pub async fn run(
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("testnats")
|
||||
.description("test nats")
|
||||
CreateCommand::new("play")
|
||||
.description("Play a song")
|
||||
.add_option(
|
||||
CreateCommandOption::new(CommandOptionType::String, "str", "random string")
|
||||
.required(false),
|
||||
CreateCommandOption::new(
|
||||
CommandOptionType::String,
|
||||
"song",
|
||||
"Name or url of the song to play",
|
||||
)
|
||||
.required(false),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user