cleaner job send function
This commit is contained in:
+20
-24
@@ -10,7 +10,7 @@ use serenity::{
|
||||
async_trait,
|
||||
};
|
||||
use songbird::SerenityInit;
|
||||
use types::jobs::{JobResponse, Jobs};
|
||||
use types::jobs::{JobResponse, JobsMap, JobsResponseMap};
|
||||
use which::which;
|
||||
use yt_dlp::{Downloader, client::Libraries};
|
||||
|
||||
@@ -36,36 +36,32 @@ impl EventHandler for Handler {
|
||||
while let Some(message) = subscriber.next().await {
|
||||
println!("Received message {:?}", message);
|
||||
|
||||
let subject = message.subject.split(".").collect::<Vec<&str>>()[1];
|
||||
// let subject = message.subject.split(".").collect::<Vec<&str>>()[1];
|
||||
let payload: JobsMap = from_bytes(&message.payload).unwrap();
|
||||
|
||||
let result = match subject {
|
||||
"download" => workers::download::download(
|
||||
&self.downloader,
|
||||
from_bytes(&message.payload).unwrap(),
|
||||
)
|
||||
.await
|
||||
.map(|res| JobResponse {
|
||||
content: res.content.map(Jobs::Download),
|
||||
error: res.error,
|
||||
}),
|
||||
"play" => {
|
||||
workers::play::play(&voice_manager, from_bytes(&message.payload).unwrap())
|
||||
let result =
|
||||
match payload {
|
||||
JobsMap::Download(payload) => {
|
||||
workers::download::download(&self.downloader, payload)
|
||||
.await
|
||||
.map(|res| JobResponse {
|
||||
content: res.content.map(JobsResponseMap::Download),
|
||||
error: res.error,
|
||||
})
|
||||
}
|
||||
JobsMap::Play(payload) => workers::play::play(&voice_manager, payload)
|
||||
.await
|
||||
.map(|res| JobResponse {
|
||||
content: res.content.map(Jobs::Play),
|
||||
content: res.content.map(JobsResponseMap::Play),
|
||||
error: res.error,
|
||||
})
|
||||
}
|
||||
"search" => {
|
||||
workers::search::search(&self.downloader, from_bytes(&message.payload).unwrap())
|
||||
}),
|
||||
JobsMap::Search(payload) => workers::search::search(&self.downloader, payload)
|
||||
.await
|
||||
.map(|res| JobResponse {
|
||||
content: res.content.map(Jobs::Search),
|
||||
content: res.content.map(JobsResponseMap::Search),
|
||||
error: res.error,
|
||||
})
|
||||
}
|
||||
_ => Err(format!("subject {subject} does not exists")),
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
||||
let response = match result {
|
||||
Ok(response) => response,
|
||||
|
||||
@@ -28,10 +28,13 @@ pub async fn download(
|
||||
Err(err) => return Err(err.to_string()),
|
||||
};
|
||||
|
||||
println!("reply: {:?}", audio_path);
|
||||
println!("audio_path: {:?}", &audio_path);
|
||||
|
||||
Ok(JobResponse {
|
||||
content: Some(DownloadResponse { path: audio_path }),
|
||||
content: Some(DownloadResponse {
|
||||
path: audio_path.clone(),
|
||||
test: audio_path.display().to_string(),
|
||||
}),
|
||||
error: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,12 +37,8 @@ pub async fn play(
|
||||
|
||||
let track_handle = handler.play_input(src.into());
|
||||
|
||||
println!("before info {:?}", track_handle);
|
||||
|
||||
println!("{:?}", track_handle.get_info().await);
|
||||
|
||||
println!("after info");
|
||||
|
||||
Ok(JobResponse {
|
||||
content: Some(PlayResponse {}),
|
||||
error: None,
|
||||
|
||||
Reference in New Issue
Block a user