search
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
pub mod modal;
|
||||
pub mod ping;
|
||||
pub mod testnats;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
use serenity::{builder::*, model::prelude::*, prelude::*, utils::CreateQuickModal};
|
||||
|
||||
pub async fn run(ctx: &Context, interaction: &CommandInteraction) -> Result<(), serenity::Error> {
|
||||
let modal = CreateQuickModal::new("About you")
|
||||
.timeout(std::time::Duration::from_secs(600))
|
||||
.short_field("First name")
|
||||
.short_field("Last name")
|
||||
.paragraph_field("Hobbies and interests");
|
||||
let response = interaction.quick_modal(ctx, modal).await?.unwrap();
|
||||
|
||||
let inputs = response.inputs;
|
||||
let (first_name, last_name, hobbies) = (&inputs[0], &inputs[1], &inputs[2]);
|
||||
|
||||
response
|
||||
.interaction
|
||||
.create_response(
|
||||
ctx,
|
||||
CreateInteractionResponse::Message(CreateInteractionResponseMessage::new().content(
|
||||
format!("**Name**: {first_name} {last_name}\n\nHobbies and interests: {hobbies}"),
|
||||
)),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("modal").description("Asks some details about you")
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use serenity::{builder::CreateCommand, model::application::ResolvedOption};
|
||||
|
||||
pub fn run(_options: &[ResolvedOption]) -> String {
|
||||
"Hey, I'm alive!".to_string()
|
||||
"Pong!".to_string()
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
|
||||
@@ -14,7 +14,7 @@ use serenity::{
|
||||
model::application::{CommandOptionType, ResolvedOption, ResolvedValue},
|
||||
};
|
||||
use types::{
|
||||
jobs::{DownloadJob, JobResponse, Jobs, PlayJob},
|
||||
jobs::{DownloadJob, JobResponse, Jobs, PlayJob, SearchJob},
|
||||
misc::new_uuid_v4,
|
||||
};
|
||||
|
||||
@@ -40,9 +40,44 @@ pub async fn run(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let url: String;
|
||||
let is_url = value.starts_with("https://");
|
||||
if !is_url {
|
||||
let search_job = SearchJob {
|
||||
uuid: new_uuid_v4(),
|
||||
query: value.to_string(),
|
||||
};
|
||||
|
||||
let response = match nats_client
|
||||
.request("corro-dj.search", to_stdvec(&search_job).unwrap().into())
|
||||
.await
|
||||
{
|
||||
Ok(resp) => resp,
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
};
|
||||
|
||||
let search_response: JobResponse = from_bytes(&response.payload).unwrap();
|
||||
|
||||
if let Some(error) = search_response.error {
|
||||
interaction
|
||||
.edit_response(ctx, EditInteractionResponse::new().content(error))
|
||||
.await?;
|
||||
return Err(serenity::Error::Other("Search error"));
|
||||
} else if let Some(Jobs::Search(content)) = search_response.content {
|
||||
url = content.url;
|
||||
} else {
|
||||
interaction
|
||||
.edit_response(ctx, EditInteractionResponse::new().content("unknown error"))
|
||||
.await?;
|
||||
return Err(serenity::Error::Other("unknown error"));
|
||||
}
|
||||
} else {
|
||||
url = value.to_string();
|
||||
}
|
||||
|
||||
let download_job = DownloadJob {
|
||||
uuid: new_uuid_v4(),
|
||||
url: value.to_string(),
|
||||
url,
|
||||
};
|
||||
|
||||
println!("job {:?}", download_job);
|
||||
@@ -58,7 +93,7 @@ pub async fn run(
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
};
|
||||
|
||||
let job_response: JobResponse<Jobs> = from_bytes(&response.payload).unwrap();
|
||||
let job_response: JobResponse = from_bytes(&response.payload).unwrap();
|
||||
|
||||
println!("response: {:?}", job_response);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user