From c05624fc761bce652a000ce1e5538597f55cced7 Mon Sep 17 00:00:00 2001 From: DaXcess Date: Tue, 24 Sep 2024 22:59:14 +0200 Subject: [PATCH 1/4] Track unexpected disconnects from AP --- spoticord_player/src/lib.rs | 32 ++++++++++++++++++++++++++++---- spoticord_session/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/spoticord_player/src/lib.rs b/spoticord_player/src/lib.rs index dec3d9a..ca23d93 100644 --- a/spoticord_player/src/lib.rs +++ b/spoticord_player/src/lib.rs @@ -13,13 +13,16 @@ use librespot::{ player::{Player as SpotifyPlayer, PlayerEvent as SpotifyPlayerEvent}, }, }; -use log::error; +use log::{error, trace}; use songbird::{input::RawAdapter, tracks::TrackHandle, Call}; use spoticord_audio::{ sink::{SinkEvent, StreamSink}, stream::Stream, }; -use std::{io::Write, sync::Arc}; +use std::{ + io::Write, + sync::{atomic::AtomicBool, Arc}, +}; use tokio::sync::{mpsc, oneshot, Mutex}; #[derive(Debug)] @@ -41,6 +44,7 @@ pub enum PlayerEvent { Play, Stopped, TrackChanged(Box), + ConnectionReset, } pub struct Player { @@ -57,6 +61,9 @@ pub struct Player { commands: mpsc::Receiver, spotify_events: mpsc::UnboundedReceiver, sink_events: mpsc::UnboundedReceiver, + + /// A shared boolean that reflects whether this Player has shut down + shutdown: Arc, } impl Player { @@ -132,6 +139,7 @@ impl Player { } }; + let shutdown = Arc::new(AtomicBool::new(false)); let (tx, rx) = mpsc::channel(16); let player = Self { session, @@ -141,15 +149,24 @@ impl Player { playback_info: None, - events: event_tx, + events: event_tx.clone(), commands: rx, spotify_events: rx_player, sink_events: rx_sink, + + shutdown: shutdown.clone(), }; // Launch it all! - tokio::spawn(spirc_task); + tokio::spawn(async move { + spirc_task.await; + + // If the shutdown flag isn't set, we most likely lost connection to the Spotify AP + if !shutdown.load(std::sync::atomic::Ordering::SeqCst) { + _ = event_tx.send(PlayerEvent::ConnectionReset).await; + } + }); tokio::spawn(player.run()); Ok((PlayerHandle { commands: tx }, event_rx)) @@ -178,6 +195,11 @@ impl Player { else => break, } } + + self.shutdown + .store(true, std::sync::atomic::Ordering::SeqCst); + + trace!("End of Player::run"); } async fn handle_command(&mut self, command: PlayerCommand) { @@ -195,6 +217,8 @@ impl Player { } async fn handle_spotify_event(&mut self, event: SpotifyPlayerEvent) { + trace!("Spotify event received: {event:#?}"); + match event { SpotifyPlayerEvent::PositionCorrection { position_ms, .. } | SpotifyPlayerEvent::Seeked { position_ms, .. } => { diff --git a/spoticord_session/src/lib.rs b/spoticord_session/src/lib.rs index 5c5dd33..b0c1761 100644 --- a/spoticord_session/src/lib.rs +++ b/spoticord_session/src/lib.rs @@ -301,6 +301,22 @@ impl Session { PlayerEvent::Pause => self.start_timeout(), PlayerEvent::Stopped => self.shutdown_player().await, PlayerEvent::TrackChanged(_) => {} + PlayerEvent::ConnectionReset => { + self.disconnect().await; + + _ = self + .text_channel + .send_message( + &self.context, + CreateMessage::new().embed( + CreateEmbed::new() + .title("Spotify connection lost") + .description("The bot has lost connection to the Spotify AP servers.\nThis is most likely caused by a connection reset on Spotify's end.\n\nUse `/join` to resummon the bot to your voice channel.") + .color(Colors::Error), + ), + ) + .await; + } } let force_edit = !matches!(event, PlayerEvent::TrackChanged(_)); From 41d75a956c620845713644cdffd952d9c35d63af Mon Sep 17 00:00:00 2001 From: DaXcess Date: Fri, 27 Sep 2024 14:53:58 +0200 Subject: [PATCH 2/4] 2.2.4-dev.1 - Updated librespot to latest commits + login5 PR merged - Fix non premium account shutting down bot - Add additional timeouts to credential retrieval - Add message for if AP connection drops --- CHANGELOG.md | 7 + Cargo.lock | 506 ++++++++++++++++++++++++++------- Cargo.toml | 3 +- spoticord_audio/Cargo.toml | 2 +- spoticord_config/Cargo.toml | 2 +- spoticord_database/Cargo.toml | 2 +- spoticord_player/Cargo.toml | 2 +- spoticord_session/Cargo.toml | 2 +- spoticord_session/src/lib.rs | 6 +- spoticord_stats/Cargo.toml | 2 +- spoticord_utils/Cargo.toml | 2 +- spoticord_utils/src/spotify.rs | 71 ++--- src/main.rs | 7 +- 13 files changed, 457 insertions(+), 157 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8946c92..059089d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 2.2.4 | TBD + +- Added a message for if the Spotify AP connection drops +- Added additional timeouts to credential retrieval +- Removed multiple points of failure in `librespot` that could shut down the bot +- Fixed an issue where non-premium users could crash the bot for everyone (See point 3) + ## 2.2.3 | September 20th 2024 - Made backend changes to librespot to prevent deadlocking by not waiting for thread shutdowns diff --git a/Cargo.lock b/Cargo.lock index a8579b0..b2fadc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,9 +168,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", @@ -205,9 +205,36 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "aws-lc-rs" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f95446d919226d587817a7d21379e6eb099b97b45110a7f272a444ca5c54070" +dependencies = [ + "aws-lc-sys", + "mirai-annotations", + "paste", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "b3ddc4a5b231dd6958b140ff3151b6412b3f4321fab354f399eec8f14b06df62" +dependencies = [ + "bindgen", + "cc", + "cmake", + "dunce", + "fs_extra", + "libc", + "paste", +] [[package]] name = "backtrace" @@ -248,6 +275,29 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.6.0", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex", + "syn 2.0.77", + "which", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -332,13 +382,24 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.21" +version = "1.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" dependencies = [ + "jobserver", + "libc", "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -371,6 +432,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "cmake" version = "0.1.51" @@ -649,12 +721,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" dependencies = [ "darling 0.10.2", - "derive_builder_core", + "derive_builder_core 0.9.0", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "derive_builder" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd33f37ee6a119146a1781d3356a7c26028f83d779b2e04ecd45fdc75c76877b" +dependencies = [ + "derive_builder_macro", +] + [[package]] name = "derive_builder_core" version = "0.9.0" @@ -667,6 +748,28 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_builder_core" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7431fa049613920234f22c47fdc33e6cf3ee83067091ea4277a3f8c4587aae38" +dependencies = [ + "darling 0.20.10", + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc" +dependencies = [ + "derive_builder_core 0.20.1", + "syn 2.0.77", +] + [[package]] name = "derive_more" version = "0.99.18" @@ -796,6 +899,12 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "either" version = "1.13.0" @@ -891,9 +1000,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" dependencies = [ "crc32fast", "miniz_oxide", @@ -944,6 +1053,12 @@ dependencies = [ "hashmap_derive", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures" version = "0.3.30" @@ -1250,7 +1365,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b906521a5b0e6d2ec07ea0bb855d92a1db30b48812744a645a3b2a1405cb8159" dependencies = [ - "derive_builder", + "derive_builder 0.9.0", "derive_more", "hex", "shorthand", @@ -1471,7 +1586,9 @@ dependencies = [ "http 1.1.0", "hyper 1.4.1", "hyper-util", + "log", "rustls 0.23.13", + "rustls-native-certs 0.8.0", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -1481,9 +1598,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -1494,7 +1611,6 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", "tower-service", "tracing", ] @@ -1510,7 +1626,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -1579,12 +1695,30 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.70" @@ -1603,6 +1737,12 @@ dependencies = [ "spin 0.9.8", ] +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "levenshtein" version = "1.0.5" @@ -1611,9 +1751,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" [[package]] name = "lexical-core" -version = "0.8.5" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46" +checksum = "0431c65b318a590c1de6b8fd6e72798c92291d27762d94c9e6c37ed7a73d8458" dependencies = [ "lexical-parse-float", "lexical-parse-integer", @@ -1624,9 +1764,9 @@ dependencies = [ [[package]] name = "lexical-parse-float" -version = "0.8.5" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f" +checksum = "eb17a4bdb9b418051aa59d41d65b1c9be5affab314a872e5ad7f06231fb3b4e0" dependencies = [ "lexical-parse-integer", "lexical-util", @@ -1635,9 +1775,9 @@ dependencies = [ [[package]] name = "lexical-parse-integer" -version = "0.8.6" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9" +checksum = "5df98f4a4ab53bf8b175b363a34c7af608fe31f93cc1fb1bf07130622ca4ef61" dependencies = [ "lexical-util", "static_assertions", @@ -1645,18 +1785,18 @@ dependencies = [ [[package]] name = "lexical-util" -version = "0.8.5" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc" +checksum = "85314db53332e5c192b6bca611fb10c114a80d1b831ddac0af1e9be1b9232ca0" dependencies = [ "static_assertions", ] [[package]] name = "lexical-write-float" -version = "0.8.5" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862" +checksum = "6e7c3ad4e37db81c1cbe7cf34610340adc09c322871972f74877a712abc6c809" dependencies = [ "lexical-util", "lexical-write-integer", @@ -1665,9 +1805,9 @@ dependencies = [ [[package]] name = "lexical-write-integer" -version = "0.8.5" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446" +checksum = "eb89e9f6958b83258afa3deed90b5de9ef68eef090ad5086c791cd2345610162" dependencies = [ "lexical-util", "static_assertions", @@ -1675,9 +1815,19 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets 0.52.6", +] [[package]] name = "libm" @@ -1706,7 +1856,7 @@ dependencies = [ [[package]] name = "librespot" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "data-encoding", "env_logger", @@ -1717,6 +1867,7 @@ dependencies = [ "librespot-core", "librespot-discovery", "librespot-metadata", + "librespot-oauth", "librespot-playback", "librespot-protocol", "log", @@ -1732,7 +1883,7 @@ dependencies = [ [[package]] name = "librespot-audio" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "aes", "byteorder", @@ -1754,7 +1905,7 @@ dependencies = [ [[package]] name = "librespot-connect" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "form_urlencoded", "futures-util", @@ -1774,7 +1925,7 @@ dependencies = [ [[package]] name = "librespot-core" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "aes", "base64 0.22.1", @@ -1791,8 +1942,9 @@ dependencies = [ "httparse", "hyper 1.4.1", "hyper-proxy2", - "hyper-rustls 0.26.0", + "hyper-rustls 0.27.3", "hyper-util", + "librespot-oauth", "librespot-protocol", "log", "nonzero_ext", @@ -1821,13 +1973,13 @@ dependencies = [ "tokio-util", "url", "uuid", - "vergen", + "vergen-gitcl", ] [[package]] name = "librespot-discovery" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "aes", "base64 0.22.1", @@ -1854,7 +2006,7 @@ dependencies = [ [[package]] name = "librespot-metadata" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "async-trait", "byteorder", @@ -1869,10 +2021,21 @@ dependencies = [ "uuid", ] +[[package]] +name = "librespot-oauth" +version = "0.5.0-dev" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" +dependencies = [ + "log", + "oauth2", + "thiserror", + "url", +] + [[package]] name = "librespot-playback" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "byteorder", "futures-util", @@ -1893,7 +2056,7 @@ dependencies = [ [[package]] name = "librespot-protocol" version = "0.5.0-dev" -source = "git+https://github.com/SpoticordMusic/librespot.git#47069dee2c5fdb705f0484cdbd3cd28f3bb949b5" +source = "git+https://github.com/SpoticordMusic/librespot.git#32d17580fcf785062f10a6634d6735d29e5304cc" dependencies = [ "protobuf", "protobuf-codegen", @@ -2003,6 +2166,12 @@ dependencies = [ "triomphe", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.0" @@ -2024,6 +2193,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "mirai-annotations" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1" + [[package]] name = "multimap" version = "0.10.0" @@ -2066,6 +2241,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nonzero_ext" version = "0.3.0" @@ -2194,6 +2379,26 @@ dependencies = [ "libc", ] +[[package]] +name = "oauth2" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c38841cdd844847e3e7c8d29cef9dcfed8877f8f56f9071f77843ecf3baf937f" +dependencies = [ + "base64 0.13.1", + "chrono", + "getrandom", + "http 0.2.12", + "rand", + "reqwest 0.11.27", + "serde", + "serde_json", + "serde_path_to_error", + "sha2", + "thiserror", + "url", +] + [[package]] name = "object" version = "0.36.4" @@ -2262,6 +2467,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "patricia_tree" version = "0.8.0" @@ -2379,9 +2590,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "pnet_base" @@ -2455,9 +2666,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "d30538d42559de6b034bc76fd6dd4c38961b1ee5c6c56e3808c50128fdbc22ce" [[package]] name = "postgres-protocol" @@ -2512,6 +2723,16 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "prettyplease" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" +dependencies = [ + "proc-macro2", + "syn 2.0.77", +] + [[package]] name = "primal-check" version = "0.3.4" @@ -2523,9 +2744,9 @@ dependencies = [ [[package]] name = "priority-queue" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560bcab673ff7f6ca9e270c17bf3affd8a05e3bd9207f123b0d45076fd8197e8" +checksum = "714c75db297bc88a63783ffc6ab9f830698a6705aa0201416931759ef4c8183d" dependencies = [ "autocfg", "equivalent", @@ -2605,9 +2826,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.32.0" +version = "0.36.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2" +checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe" dependencies = [ "memchr", "serde", @@ -2623,7 +2844,7 @@ dependencies = [ "pin-project-lite", "quinn-proto", "quinn-udp", - "rustc-hash", + "rustc-hash 2.0.0", "rustls 0.23.13", "socket2", "thiserror", @@ -2640,7 +2861,7 @@ dependencies = [ "bytes", "rand", "ring 0.17.8", - "rustc-hash", + "rustc-hash 2.0.0", "rustls 0.23.13", "slab", "thiserror", @@ -2712,9 +2933,9 @@ dependencies = [ [[package]] name = "realfft" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953d9f7e5cdd80963547b456251296efc2626ed4e3cbf36c869d9564e0220571" +checksum = "390252372b7f2aac8360fc5e72eba10136b166d6faeed97e6d0c8324eb99b2b1" dependencies = [ "rustfft", ] @@ -2734,9 +2955,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b" dependencies = [ "bitflags 2.6.0", ] @@ -2924,9 +3145,9 @@ dependencies = [ [[package]] name = "ringbuf" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f7f1b88601a8ee13cabf203611ccdf64345dc1c5d24de8b11e1a678ee619b6" +checksum = "fb0d14419487131a897031a7e81c3b23d092296984fac4eb6df48cc4e3b2f3c5" dependencies = [ "crossbeam-utils", ] @@ -3048,6 +3269,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc-hash" version = "2.0.0" @@ -3135,6 +3362,8 @@ version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ + "aws-lc-rs", + "log", "once_cell", "ring 0.17.8", "rustls-pki-types", @@ -3222,6 +3451,7 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ + "aws-lc-rs", "ring 0.17.8", "rustls-pki-types", "untrusted 0.9.0", @@ -3336,9 +3566,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -3415,6 +3645,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.19" @@ -3573,9 +3813,9 @@ dependencies = [ [[package]] name = "simd-json" -version = "0.13.10" +version = "0.13.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "570c430b3d902ea083097e853263ae782dfe40857d93db019a12356c8e8143fa" +checksum = "a0228a564470f81724e30996bbc2b171713b37b15254a6440c7e2d5449b95691" dependencies = [ "getrandom", "halfbrown", @@ -3589,9 +3829,9 @@ dependencies = [ [[package]] name = "simdutf8" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" [[package]] name = "siphasher" @@ -3722,13 +3962,14 @@ dependencies = [ [[package]] name = "spoticord" -version = "2.2.3" +version = "2.2.4" dependencies = [ "anyhow", "dotenvy", "env_logger", "log", "poise", + "rustls 0.23.13", "serenity", "songbird", "spoticord_config", @@ -3742,7 +3983,7 @@ dependencies = [ [[package]] name = "spoticord_audio" -version = "2.2.3" +version = "2.2.4" dependencies = [ "librespot", "songbird", @@ -3752,7 +3993,7 @@ dependencies = [ [[package]] name = "spoticord_config" -version = "2.2.3" +version = "2.2.4" dependencies = [ "rspotify", "serenity", @@ -3760,7 +4001,7 @@ dependencies = [ [[package]] name = "spoticord_database" -version = "2.2.3" +version = "2.2.4" dependencies = [ "chrono", "diesel", @@ -3774,7 +4015,7 @@ dependencies = [ [[package]] name = "spoticord_player" -version = "2.2.3" +version = "2.2.4" dependencies = [ "anyhow", "hex", @@ -3789,7 +4030,7 @@ dependencies = [ [[package]] name = "spoticord_session" -version = "2.2.3" +version = "2.2.4" dependencies = [ "anyhow", "base64 0.22.1", @@ -3807,14 +4048,14 @@ dependencies = [ [[package]] name = "spoticord_stats" -version = "2.2.3" +version = "2.2.4" dependencies = [ "redis", ] [[package]] name = "spoticord_utils" -version = "2.2.3" +version = "2.2.4" dependencies = [ "anyhow", "base64 0.22.1", @@ -4079,16 +4320,15 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.13" +version = "0.31.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" +checksum = "355dbe4f8799b304b05e1b0f05fc59b2a18d36645cf169607da45bde2f69a1be" dependencies = [ - "cfg-if", "core-foundation-sys", "libc", + "memchr", "ntapi", - "once_cell", - "windows 0.52.0", + "windows 0.57.0", ] [[package]] @@ -4133,18 +4373,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -4401,27 +4641,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - [[package]] name = "tower-service" version = "0.3.3" @@ -4804,14 +5023,40 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vergen" -version = "8.3.2" +version = "9.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2990d9ea5967266ea0ccf413a4aa5c42a93dbcfda9cb49a97de6931726b12566" +checksum = "349ed9e45296a581f455bc18039878f409992999bc1d5da12a6800eb18c8752f" dependencies = [ "anyhow", - "cfg-if", + "derive_builder 0.20.1", + "rustversion", + "time", + "vergen-lib", +] + +[[package]] +name = "vergen-gitcl" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3a7f91caabecefc3c249fd864b11d4abe315c166fbdb568964421bccfd2b7a" +dependencies = [ + "anyhow", + "derive_builder 0.20.1", "rustversion", "time", + "vergen", + "vergen-lib", +] + +[[package]] +name = "vergen-lib" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229eaddb0050920816cf051e619affaf18caa3dd512de8de5839ccbc8e53abb0" +dependencies = [ + "anyhow", + "derive_builder 0.20.1", + "rustversion", ] [[package]] @@ -5035,7 +5280,17 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ - "windows-core", + "windows-core 0.52.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", "windows-targets 0.52.6", ] @@ -5048,17 +5303,60 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "windows-registry" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-strings", "windows-targets 0.52.6", ] +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.2.0" @@ -5074,7 +5372,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-targets 0.52.6", ] diff --git a/Cargo.toml b/Cargo.toml index de2fc02..0b780a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord" -version = "2.2.3" +version = "2.2.4" edition = "2021" rust-version = "1.80.0" @@ -39,6 +39,7 @@ poise = "0.6.1" serenity = "0.12.2" songbird = { version = "0.4.3", features = ["simd-json"] } tokio = { version = "1.39.3", features = ["full"] } +rustls = { version = "0.23.13", features = ["aws-lc-rs"] } [profile.release] opt-level = 3 diff --git a/spoticord_audio/Cargo.toml b/spoticord_audio/Cargo.toml index 53d0ceb..5a61a3b 100644 --- a/spoticord_audio/Cargo.toml +++ b/spoticord_audio/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord_audio" -version = "2.2.3" +version = "2.2.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/spoticord_config/Cargo.toml b/spoticord_config/Cargo.toml index 5065259..fa21abe 100644 --- a/spoticord_config/Cargo.toml +++ b/spoticord_config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord_config" -version = "2.2.3" +version = "2.2.4" edition = "2021" [dependencies] diff --git a/spoticord_database/Cargo.toml b/spoticord_database/Cargo.toml index 0fd9e65..c8d8b0c 100644 --- a/spoticord_database/Cargo.toml +++ b/spoticord_database/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord_database" -version = "2.2.3" +version = "2.2.4" edition = "2021" [dependencies] diff --git a/spoticord_player/Cargo.toml b/spoticord_player/Cargo.toml index 01fd22c..ac0b178 100644 --- a/spoticord_player/Cargo.toml +++ b/spoticord_player/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord_player" -version = "2.2.3" +version = "2.2.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/spoticord_session/Cargo.toml b/spoticord_session/Cargo.toml index 1a1c702..e9a6c91 100644 --- a/spoticord_session/Cargo.toml +++ b/spoticord_session/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord_session" -version = "2.2.3" +version = "2.2.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/spoticord_session/src/lib.rs b/spoticord_session/src/lib.rs index b0c1761..4332d80 100644 --- a/spoticord_session/src/lib.rs +++ b/spoticord_session/src/lib.rs @@ -106,7 +106,7 @@ impl Session { Err(why) => { error!("Failed to retrieve credentials: {why}"); - return Err(why.into()); + return Err(why); } }; let device_name = match session_manager.database().get_user(owner.to_string()).await { @@ -616,7 +616,7 @@ async fn retrieve_credentials(database: &Database, owner: impl AsRef) -> Re None => { let access_token = database.get_access_token(&account.user_id).await?; let credentials = spotify::request_session_token(Credentials { - username: account.username.clone(), + username: Some(account.username.to_string()), auth_type: AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN, auth_data: access_token.into_bytes(), }) @@ -632,7 +632,7 @@ async fn retrieve_credentials(database: &Database, owner: impl AsRef) -> Re }; Ok(Credentials { - username: account.username, + username: Some(account.username), auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS, auth_data: BASE64.decode(token)?, }) diff --git a/spoticord_stats/Cargo.toml b/spoticord_stats/Cargo.toml index aaf21cb..ee330c0 100644 --- a/spoticord_stats/Cargo.toml +++ b/spoticord_stats/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord_stats" -version = "2.2.3" +version = "2.2.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/spoticord_utils/Cargo.toml b/spoticord_utils/Cargo.toml index f7e42b3..0ab8c3c 100644 --- a/spoticord_utils/Cargo.toml +++ b/spoticord_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spoticord_utils" -version = "2.2.3" +version = "2.2.4" edition = "2021" [dependencies] diff --git a/spoticord_utils/src/spotify.rs b/spoticord_utils/src/spotify.rs index 4cdf2de..f9b0333 100644 --- a/spoticord_utils/src/spotify.rs +++ b/spoticord_utils/src/spotify.rs @@ -1,9 +1,9 @@ use anyhow::Result; use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; use librespot::{ - core::{connection::AuthenticationError, Session, SessionConfig}, + core::{Session, SessionConfig}, discovery::Credentials, - protocol::{authentication::AuthenticationType, keyexchange::ErrorCode}, + protocol::authentication::AuthenticationType, }; use log::debug; use std::time::Duration; @@ -15,17 +15,17 @@ pub async fn validate_token( let auth_data = BASE64.decode(token.into())?; let credentials = Credentials { - username: username.into(), + username: Some(username.into()), auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS, auth_data, }; - debug!("Validating session token for {}", credentials.username); + debug!("Validating session token for {:?}", credentials.username); let new_credentials = request_session_token(credentials.clone()).await?; if credentials.auth_data != new_credentials.auth_data { - debug!("New session token retrieved for {}", credentials.username); + debug!("New session token retrieved for {:?}", credentials.username); return Ok(Some(BASE64.encode(new_credentials.auth_data))); } @@ -34,54 +34,45 @@ pub async fn validate_token( } pub async fn request_session_token(credentials: Credentials) -> Result { - debug!("Requesting session token for {}", credentials.username); + debug!("Requesting session token for {:?}", credentials.username); let session = Session::new(SessionConfig::default(), None); let mut tries = 0; Ok(loop { - let (host, port) = session.apresolver().resolve("accesspoint").await?; - - let mut transport = match librespot::core::connection::connect(&host, port, None).await { - Ok(transport) => transport, - Err(why) => { - // Retry - + match connect(&session, credentials.clone()).await { + Ok(creds) => break creds, + Err(e) => { tries += 1; if tries > 3 { - return Err(why.into()); + return Err(e); } tokio::time::sleep(Duration::from_millis(100)).await; - - continue; } - }; + } + }) +} + +/// Wrapper around session connecting that times out if an operation is still busy after 3 seconds +async fn connect(session: &Session, credentials: Credentials) -> Result { + const TIMEOUT: Duration = Duration::from_secs(3); - match librespot::core::connection::authenticate( + let (host, port) = + tokio::time::timeout(TIMEOUT, session.apresolver().resolve("accesspoint")).await??; + + // `connect` already has a 3 second timeout internally + let mut transport = librespot::core::connection::connect(&host, port, None).await?; + + let creds = tokio::time::timeout( + TIMEOUT, + librespot::core::connection::authenticate( &mut transport, credentials.clone(), &session.config().device_id, - ) - .await - { - Ok(creds) => break creds, - Err(e) => { - if let Some(AuthenticationError::LoginFailed(ErrorCode::TryAnotherAP)) = - e.error.downcast_ref::() - { - tries += 1; - if tries > 3 { - return Err(e.into()); - } - - tokio::time::sleep(Duration::from_millis(100)).await; - - continue; - } else { - return Err(e.into()); - } - } - }; - }) + ), + ) + .await??; + + Ok(creds) } diff --git a/src/main.rs b/src/main.rs index 7a761b7..7599770 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ mod bot; mod commands; -// mod session; -// mod utils; use log::{error, info}; use poise::Framework; @@ -11,6 +9,11 @@ use spoticord_database::Database; #[tokio::main] async fn main() { + // Force aws-lc-rs as default crypto provider + // Since multiple dependencies either enable aws_lc_rs or ring, they cause a clash, so we have to + // explicitly tell rustls to use the aws-lc-rs provider + _ = rustls::crypto::aws_lc_rs::default_provider().install_default(); + // Setup logging if std::env::var("RUST_LOG").is_err() { #[cfg(debug_assertions)] From 58df939280244ca4c6cfb3997571ade785f80cd8 Mon Sep 17 00:00:00 2001 From: DaXcess Date: Fri, 27 Sep 2024 16:15:29 +0200 Subject: [PATCH 3/4] Made missing KV_URL env error more obvious --- spoticord_audio/src/sink.rs | 4 ++-- spoticord_config/src/env.rs | 4 ++++ spoticord_config/src/lib.rs | 4 ++++ src/bot.rs | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spoticord_audio/src/sink.rs b/spoticord_audio/src/sink.rs index 23187e9..b11fb67 100644 --- a/spoticord_audio/src/sink.rs +++ b/spoticord_audio/src/sink.rs @@ -24,7 +24,7 @@ impl StreamSink { impl Sink for StreamSink { fn start(&mut self) -> SinkResult<()> { if let Err(_why) = self.sender.send(SinkEvent::Start) { - // WARNING: Returning an error causes librespot-playback to exit the process with status 1 + // WARNING: Returning an error causes librespot-playback to panic // return Err(SinkError::ConnectionRefused(_why.to_string())); } @@ -34,7 +34,7 @@ impl Sink for StreamSink { fn stop(&mut self) -> SinkResult<()> { if let Err(_why) = self.sender.send(SinkEvent::Stop) { - // WARNING: Returning an error causes librespot-playback to exit the process with status 1 + // WARNING: Returning an error causes librespot-playback to panic // return Err(SinkError::ConnectionRefused(_why.to_string())); } diff --git a/spoticord_config/src/env.rs b/spoticord_config/src/env.rs index 651bde9..53ad0c1 100644 --- a/spoticord_config/src/env.rs +++ b/spoticord_config/src/env.rs @@ -15,3 +15,7 @@ pub static SPOTIFY_CLIENT_SECRET: LazyLock = LazyLock::new(|| { std::env::var("SPOTIFY_CLIENT_SECRET") .expect("missing SPOTIFY_CLIENT_SECRET environment variable") }); + +// Locked behind `stats` feature +pub static KV_URL: LazyLock = + LazyLock::new(|| std::env::var("KV_URL").expect("missing KV_URL environment variable")); diff --git a/spoticord_config/src/lib.rs b/spoticord_config/src/lib.rs index e711e0f..dcba7c0 100644 --- a/spoticord_config/src/lib.rs +++ b/spoticord_config/src/lib.rs @@ -31,6 +31,10 @@ pub fn link_url() -> &'static str { &env::LINK_URL } +pub fn kv_url() -> &'static str { + &env::KV_URL +} + pub fn get_spotify(token: Token) -> AuthCodeSpotify { AuthCodeSpotify::from_token_with_config( token, diff --git a/src/bot.rs b/src/bot.rs index d48c360..d587b4d 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -68,7 +68,7 @@ pub async fn setup( let manager = SessionManager::new(songbird, database); #[cfg(feature = "stats")] - let stats = StatsManager::new(std::env::var("KV_URL")?)?; + let stats = StatsManager::new(spoticord_config::kv_url())?; tokio::spawn(background_loop( manager.clone(), From a49c1f19792a71be7ceb7401cb155b570ee5a4bd Mon Sep 17 00:00:00 2001 From: DaXcess Date: Mon, 30 Sep 2024 11:08:24 +0200 Subject: [PATCH 4/4] Update deps --- Cargo.lock | 118 ++++++++++++++++++---------------- spoticord_session/src/lib.rs | 4 +- src/commands/music/playing.rs | 5 +- 3 files changed, 64 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2fadc7..166a884 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,7 +163,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -174,7 +174,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -294,7 +294,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.77", + "syn 2.0.79", "which", ] @@ -620,7 +620,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -642,7 +642,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -757,7 +757,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -767,7 +767,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc" dependencies = [ "derive_builder_core 0.20.1", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -780,7 +780,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -845,7 +845,7 @@ dependencies = [ "dsl_auto_type", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -854,7 +854,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" dependencies = [ - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -896,7 +896,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -929,7 +929,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1115,7 +1115,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2116,7 +2116,7 @@ checksum = "5cf92c10c7e361d6b99666ec1c6f9805b0bea2c3bd8c78dc6fe98ac5bd78db11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2327,7 +2327,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2410,9 +2410,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "opaque-debug" @@ -2552,7 +2555,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2612,7 +2615,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2650,7 +2653,7 @@ dependencies = [ "darling 0.20.10", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2666,9 +2669,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d30538d42559de6b034bc76fd6dd4c38961b1ee5c6c56e3808c50128fdbc22ce" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "postgres-protocol" @@ -2730,7 +2733,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2955,9 +2958,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -2979,19 +2982,19 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", + "regex-automata 0.4.8", + "regex-syntax 0.8.5", ] [[package]] @@ -3005,13 +3008,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax 0.8.5", ] [[package]] @@ -3022,9 +3025,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" @@ -3145,11 +3148,12 @@ dependencies = [ [[package]] name = "ringbuf" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb0d14419487131a897031a7e81c3b23d092296984fac4eb6df48cc4e3b2f3c5" +checksum = "726bb493fe9cac765e8f96a144c3a8396bdf766dedad22e504b70b908dcbceb4" dependencies = [ "crossbeam-utils", + "portable-atomic", ] [[package]] @@ -3431,9 +3435,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-webpki" @@ -3630,7 +3634,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3663,7 +3667,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4177,7 +4181,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4294,9 +4298,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -4360,9 +4364,9 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -4388,7 +4392,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4485,7 +4489,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4667,7 +4671,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4884,7 +4888,7 @@ checksum = "905e88c2a4cc27686bd57e495121d451f027e441388a67f773be729ad4be1ea8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -5118,7 +5122,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -5152,7 +5156,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5165,9 +5169,9 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasm-streams" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b65dc4c90b63b118468cf747d8bf3566c1913ef60be765b5730ead9e0a3ba129" +checksum = "4e072d4e72f700fb3443d8fe94a39315df013eef1104903cdb0a2abd322bbecd" dependencies = [ "futures-util", "js-sys", @@ -5323,7 +5327,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -5334,7 +5338,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -5552,7 +5556,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] diff --git a/spoticord_session/src/lib.rs b/spoticord_session/src/lib.rs index 4332d80..4e57f56 100644 --- a/spoticord_session/src/lib.rs +++ b/spoticord_session/src/lib.rs @@ -506,13 +506,13 @@ impl SessionHandle { /// This playback embed will automatically update when certain events happen pub async fn create_playback_embed( &self, - interaction: CommandInteraction, + interaction: &CommandInteraction, behavior: playback_embed::UpdateBehavior, ) -> Result<()> { self.commands .send(SessionCommand::CreatePlaybackEmbed( self.clone(), - interaction, + interaction.to_owned(), behavior, )) .await?; diff --git a/src/commands/music/playing.rs b/src/commands/music/playing.rs index 2ce81b1..c431091 100644 --- a/src/commands/music/playing.rs +++ b/src/commands/music/playing.rs @@ -38,10 +38,7 @@ pub async fn playing( }; session - .create_playback_embed( - context.interaction.clone(), - update_behavior.unwrap_or_default(), - ) + .create_playback_embed(context.interaction, update_behavior.unwrap_or_default()) .await?; Ok(())