lot of refactor
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
use nats::functions::JobClient;
|
||||
use nats_libs::functions::JobClient;
|
||||
use serenity::{
|
||||
all::{
|
||||
CommandInteraction,
|
||||
Context,
|
||||
CreateCommandOption,
|
||||
CreateInteractionResponse,
|
||||
CreateInteractionResponseMessage,
|
||||
EditInteractionResponse,
|
||||
},
|
||||
all::{CommandInteraction, Context, CreateCommandOption},
|
||||
builder::CreateCommand,
|
||||
model::application::{CommandOptionType, ResolvedOption, ResolvedValue},
|
||||
};
|
||||
use serenity_libs::functions::CustomInteraction;
|
||||
use types::{
|
||||
error::{CorroError, CorroErrorType},
|
||||
jobs::{DownloadJob, JobsMap, JobsResponseMap, PlayJob, SearchJob},
|
||||
misc::{new_uuid_v4, parse_url_or_default},
|
||||
};
|
||||
@@ -21,7 +16,7 @@ pub async fn run(
|
||||
ctx: &Context,
|
||||
interaction: &CommandInteraction,
|
||||
nats_client: &async_nats::Client,
|
||||
) -> Result<(), serenity::Error> {
|
||||
) -> Result<(), CorroError> {
|
||||
let options = interaction.data.options();
|
||||
|
||||
if let Some(ResolvedOption {
|
||||
@@ -29,15 +24,13 @@ pub async fn run(
|
||||
..
|
||||
}) = options.first()
|
||||
{
|
||||
interaction
|
||||
.create_response(
|
||||
ctx,
|
||||
CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content(format!("Searching: {value}...")),
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
match interaction
|
||||
.create_text_response(ctx, format!("Searching: {value}..."))
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(why) => return Err(why),
|
||||
};
|
||||
|
||||
let url: Url;
|
||||
let is_url = value.starts_with("https://") || value.starts_with("http://");
|
||||
@@ -52,13 +45,16 @@ pub async fn run(
|
||||
{
|
||||
Ok(resp) => match resp {
|
||||
JobsResponseMap::Search(resp) => resp,
|
||||
_ => return Err(serenity::Error::Other("Unexpected return type")),
|
||||
_ => {
|
||||
return Err(CorroError {
|
||||
error_type: CorroErrorType::JobError,
|
||||
message: "Unexpected return type".to_string(),
|
||||
});
|
||||
}
|
||||
},
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
Err(why) => return Err(why),
|
||||
};
|
||||
|
||||
println!("{:?}", &search_response);
|
||||
|
||||
url = search_response.song.url;
|
||||
} else {
|
||||
url = parse_url_or_default(value.to_string());
|
||||
@@ -73,13 +69,16 @@ pub async fn run(
|
||||
{
|
||||
Ok(resp) => match resp {
|
||||
JobsResponseMap::Download(resp) => resp,
|
||||
_ => return Err(serenity::Error::Other("Unexpected return type")),
|
||||
_ => {
|
||||
return Err(CorroError {
|
||||
error_type: CorroErrorType::JobError,
|
||||
message: "Unexpected return type".to_string(),
|
||||
});
|
||||
}
|
||||
},
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
Err(why) => return Err(why),
|
||||
};
|
||||
|
||||
println!("{:?}", &download_response);
|
||||
|
||||
let guild_id = interaction.guild_id.unwrap();
|
||||
|
||||
let channel_id = guild_id
|
||||
@@ -89,7 +88,7 @@ pub async fn run(
|
||||
.channel_id
|
||||
.unwrap();
|
||||
|
||||
let _ = match nats_client
|
||||
match nats_client
|
||||
.send_job(JobsMap::Play(PlayJob {
|
||||
uuid: new_uuid_v4(),
|
||||
path: download_response.path,
|
||||
@@ -100,15 +99,25 @@ pub async fn run(
|
||||
{
|
||||
Ok(resp) => match resp {
|
||||
JobsResponseMap::Play(resp) => resp,
|
||||
_ => return Err(serenity::Error::Other("Unexpected return type")),
|
||||
_ => {
|
||||
return Err(CorroError {
|
||||
error_type: CorroErrorType::JobError,
|
||||
message: "Unexpected return type".to_string(),
|
||||
});
|
||||
}
|
||||
},
|
||||
Err(_why) => return Err(serenity::Error::Other("send error")),
|
||||
Err(why) => return Err(why),
|
||||
};
|
||||
|
||||
interaction
|
||||
.edit_response(ctx, EditInteractionResponse::new().content("Playing..."))
|
||||
.await?;
|
||||
match interaction
|
||||
.edit_text_response(ctx, "Playing...".to_string())
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(why) => return Err(why),
|
||||
};
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user