proper response
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use std::str::from_utf8;
|
||||
|
||||
use postcard::to_stdvec;
|
||||
use postcard::{from_bytes, to_stdvec};
|
||||
use serenity::{
|
||||
all::{
|
||||
CommandInteraction,
|
||||
@@ -14,7 +12,7 @@ use serenity::{
|
||||
model::application::{CommandOptionType, ResolvedOption, ResolvedValue},
|
||||
};
|
||||
use types::{
|
||||
jobs::{InnerStruct, Job, JobKind},
|
||||
jobs::{DownloadJob, DownloadResponse, JobResponse},
|
||||
misc::new_uuid_v4,
|
||||
};
|
||||
|
||||
@@ -40,12 +38,9 @@ pub async fn run(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let job = Job {
|
||||
let job = DownloadJob {
|
||||
uuid: new_uuid_v4(),
|
||||
kind: JobKind::Download,
|
||||
inner: InnerStruct {
|
||||
str: value.to_string(),
|
||||
},
|
||||
url: value.to_string(),
|
||||
};
|
||||
|
||||
println!("job {:?}", job);
|
||||
@@ -58,14 +53,22 @@ pub async fn run(
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
};
|
||||
|
||||
println!("response: {:?}", from_utf8(&response.payload).unwrap());
|
||||
let job_response: JobResponse<DownloadResponse> = 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 {
|
||||
text_response = content.path.display().to_string();
|
||||
} else {
|
||||
text_response = "unkown".to_string();
|
||||
}
|
||||
|
||||
interaction
|
||||
.edit_response(
|
||||
ctx,
|
||||
EditInteractionResponse::new()
|
||||
.content(format!("path: {}", from_utf8(&response.payload).unwrap())),
|
||||
)
|
||||
.edit_response(ctx, EditInteractionResponse::new().content(text_response))
|
||||
.await?;
|
||||
} else {
|
||||
interaction
|
||||
|
||||
Reference in New Issue
Block a user