folders structure
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
use std::str::from_utf8;
|
||||
|
||||
use postcard::to_stdvec;
|
||||
use serenity::{
|
||||
all::{
|
||||
CommandInteraction,
|
||||
Context,
|
||||
CreateCommandOption,
|
||||
CreateInteractionResponse,
|
||||
CreateInteractionResponseMessage,
|
||||
EditInteractionResponse,
|
||||
},
|
||||
builder::CreateCommand,
|
||||
model::application::{CommandOptionType, ResolvedOption, ResolvedValue},
|
||||
};
|
||||
use types::{
|
||||
jobs::{InnerStruct, Job, JobKind},
|
||||
misc::new_uuid_v4,
|
||||
};
|
||||
|
||||
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()
|
||||
{
|
||||
interaction
|
||||
.create_response(
|
||||
ctx,
|
||||
CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content(format!("Searching: {value}...")),
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let job = Job {
|
||||
uuid: new_uuid_v4(),
|
||||
kind: JobKind::Download,
|
||||
inner: InnerStruct {
|
||||
str: value.to_string(),
|
||||
},
|
||||
};
|
||||
|
||||
println!("job {:?}", job);
|
||||
|
||||
let response = match nats_client
|
||||
.request("corro-dj.download", to_stdvec(&job).unwrap().into())
|
||||
.await
|
||||
{
|
||||
Ok(resp) => resp,
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
};
|
||||
|
||||
println!("response: {:?}", from_utf8(&response.payload).unwrap());
|
||||
|
||||
interaction
|
||||
.edit_response(
|
||||
ctx,
|
||||
EditInteractionResponse::new()
|
||||
.content(format!("path: {}", from_utf8(&response.payload).unwrap())),
|
||||
)
|
||||
.await?;
|
||||
} else {
|
||||
interaction
|
||||
.create_response(
|
||||
ctx,
|
||||
CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("Please provide a valid string"),
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("testnats")
|
||||
.description("test nats")
|
||||
.add_option(
|
||||
CreateCommandOption::new(CommandOptionType::String, "str", "random string")
|
||||
.required(false),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user