cleaner job send function
This commit is contained in:
@@ -7,8 +7,11 @@ edition = "2024"
|
||||
async-nats = { version = "0.46.0" }
|
||||
futures = { version = "0.3.32" }
|
||||
futures-executor = { version = "0.3.32" }
|
||||
nats = { path = "../../libs/nats" }
|
||||
postcard = { version = "1.1.3", features = ["use-std"] }
|
||||
rustls = { version = "0.23.37", default-features = false, features = ["aws-lc-rs"] }
|
||||
rustls = { version = "0.23.37", default-features = false, features = [
|
||||
"aws-lc-rs",
|
||||
] }
|
||||
serenity = { version = "0.12.5", default-features = false, features = [
|
||||
"cache",
|
||||
"rustls_backend",
|
||||
@@ -19,4 +22,4 @@ symphonia = { version = "0.5.5" }
|
||||
tokio = { version = "1.50.0", features = ["macros", "rt-multi-thread"] }
|
||||
types = { path = "../../libs/types" }
|
||||
which = { version = "8.0.2" }
|
||||
yt-dlp = { version = "2.5.0" }
|
||||
yt-dlp = { version = "2.6.0" }
|
||||
|
||||
+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