diff --git a/Cargo.lock b/Cargo.lock index f46e8df..f1a49a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -285,12 +285,6 @@ version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" -[[package]] -name = "bytecount" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" - [[package]] name = "bytemuck" version = "1.25.0" @@ -312,37 +306,6 @@ dependencies = [ "serde", ] -[[package]] -name = "camino" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48" -dependencies = [ - "serde_core", -] - -[[package]] -name = "cargo-platform" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo_metadata" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" -dependencies = [ - "camino", - "cargo-platform", - "semver", - "serde", - "serde_json", -] - [[package]] name = "cc" version = "1.2.56" @@ -719,20 +682,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if", - "hashbrown 0.14.5", - "lock_api", - "once_cell", - "parking_lot_core", - "serde", -] - [[package]] name = "dashmap" version = "6.1.0" @@ -966,15 +915,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "version_check", -] - [[package]] name = "event-listener" version = "5.4.1" @@ -1246,12 +1186,6 @@ dependencies = [ "polyval", ] -[[package]] -name = "glob" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" - [[package]] name = "h2" version = "0.4.13" @@ -1896,21 +1830,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "mini-moka" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c325dfab65f261f386debee8b0969da215b3fa0037e74c8a1234db7ba986d803" -dependencies = [ - "crossbeam-channel", - "crossbeam-utils", - "dashmap 5.5.3", - "skeptic", - "smallvec", - "tagptr", - "triomphe", -] - [[package]] name = "miniz_oxide" version = "0.8.9" @@ -2354,17 +2273,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "pulldown-cmark" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" -dependencies = [ - "bitflags 2.11.0", - "memchr", - "unicase", -] - [[package]] name = "quinn" version = "0.11.9" @@ -3007,10 +2915,6 @@ name = "semver" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" -dependencies = [ - "serde", - "serde_core", -] [[package]] name = "serde" @@ -3160,9 +3064,7 @@ dependencies = [ "base64", "bitflags 2.11.0", "bytes", - "chrono", "command_attr", - "dashmap 5.5.3", "flate2", "futures", "levenshtein", @@ -3170,7 +3072,6 @@ dependencies = [ "parking_lot", "percent-encoding", "reqwest 0.12.28", - "rustc-hash", "secrecy", "serde", "serde_cow", @@ -3181,7 +3082,6 @@ dependencies = [ "tokio-tungstenite 0.21.0", "tracing", "typemap_rev", - "typesize", "url", "uwl", ] @@ -3298,21 +3198,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" -[[package]] -name = "skeptic" -version = "0.13.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d23b015676c90a0f01c197bfdc786c20342c73a0afdda9025adb0bc42940a8" -dependencies = [ - "bytecount", - "cargo_metadata", - "error-chain", - "glob", - "pulldown-cmark", - "tempfile", - "walkdir", -] - [[package]] name = "slab" version = "0.4.12" @@ -3359,7 +3244,7 @@ dependencies = [ "bytes", "chacha20poly1305", "crypto-common", - "dashmap 6.1.0", + "dashmap", "derivative", "discortp", "either", @@ -4023,12 +3908,6 @@ dependencies = [ "strength_reduce", ] -[[package]] -name = "triomphe" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd69c5aa8f924c7519d6372789a74eac5b94fb0f8fcf0d4a97eb0bfc3e785f39" - [[package]] name = "try-lock" version = "0.2.5" @@ -4174,35 +4053,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "typesize" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da66c62c5b7017a2787e77373c03e6a5aafde77a73bff1ff96e91cd2e128179" -dependencies = [ - "chrono", - "dashmap 5.5.3", - "hashbrown 0.14.5", - "mini-moka", - "parking_lot", - "secrecy", - "serde_json", - "time", - "typesize-derive", - "url", -] - -[[package]] -name = "typesize-derive" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "536b6812192bda8551cfa0e52524e328c6a951b48e66529ee4522d6c721243d6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.117", -] - [[package]] name = "unicase" version = "2.9.0" diff --git a/apps/worker/Cargo.toml b/apps/worker/Cargo.toml index 719aec8..6456958 100644 --- a/apps/worker/Cargo.toml +++ b/apps/worker/Cargo.toml @@ -8,8 +8,12 @@ async-nats = { version = "0.46.0" } futures = { version = "0.3.32" } futures-executor = { version = "0.3.32" } postcard = { version = "1.1.3", features = ["use-std"] } -serenity = { version = "0.12.5" } -songbird = { version = "0.5.0", default-features = true } +serenity = { version = "0.12.5", default-features = false, features = [ + "client", + "standard_framework", + "voice", +] } +songbird = { version = "0.5.0" } tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] } types = { path = "../../libs/types" } which = { version = "8.0.0" } diff --git a/apps/worker/src/workers/play.rs b/apps/worker/src/workers/play.rs index 2c0b380..9a0b56c 100644 --- a/apps/worker/src/workers/play.rs +++ b/apps/worker/src/workers/play.rs @@ -1,6 +1,9 @@ use std::sync::Arc; +use serenity::async_trait; use songbird::Songbird; +use songbird::events::{Event, EventContext, EventHandler as VoiceEventHandler, TrackEvent}; +use songbird::input::File; use types::jobs::{JobResponse, PlayJob, PlayResponse}; pub async fn play( @@ -10,11 +13,36 @@ pub async fn play( println!("job: {:?}", job); if let Some(voice_manager) = voice_manager { - if let Err(why) = voice_manager.join(job.guild_id, job.channel_id).await { - println!("{why}:?"); - return Err(format!("{why}")); + if let Ok(handler_lock) = voice_manager.join(job.guild_id, job.channel_id).await { + // Attach an event handler to see notifications of all track errors. + let mut handler = handler_lock.lock().await; + handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier); + } + + let handler_lock = match voice_manager.get(job.guild_id) { + Some(handler) => handler, + None => { + return Ok(JobResponse { + content: Some(PlayResponse {}), + error: None, + }); + } }; + let mut handler = handler_lock.lock().await; + + let src = File::new("output/sQaKWttol58.opus").clone(); + + let track_handle = handler.play_input(src.into()); + + println!("before info"); + + println!("{:?}", track_handle.get_info().await); + + println!("after info"); + + let _ = track_handle.play(); + Ok(JobResponse { content: Some(PlayResponse {}), error: None, @@ -23,3 +51,22 @@ pub async fn play( Err("No voice_manager defined".to_string()) } } + +struct TrackErrorNotifier; + +#[async_trait] +impl VoiceEventHandler for TrackErrorNotifier { + async fn act(&self, ctx: &EventContext<'_>) -> Option { + if let EventContext::Track(track_list) = ctx { + for (state, handle) in *track_list { + println!( + "Track {:?} encountered an error: {:?}", + handle.uuid(), + state.playing + ); + } + } + + None + } +}