diff --git a/Cargo.lock b/Cargo.lock index 838b149..ed16aa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -314,9 +314,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.56" +version = "1.2.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" dependencies = [ "find-msvc-tools", "jobserver", @@ -653,12 +653,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.21.3" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" dependencies = [ - "darling_core 0.21.3", - "darling_macro 0.21.3", + "darling_core 0.23.0", + "darling_macro 0.23.0", ] [[package]] @@ -677,11 +677,10 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.21.3" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" dependencies = [ - "fnv", "ident_case", "proc-macro2", "quote", @@ -702,11 +701,11 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.21.3" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" dependencies = [ - "darling_core 0.21.3", + "darling_core 0.23.0", "quote", "syn 2.0.117", ] @@ -2181,9 +2180,9 @@ dependencies = [ [[package]] name = "lofty" -version = "0.23.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "179408be6ddda3771589a4e940b1b5718613fa9986d78f420890d20e2b6fc278" +checksum = "6d0c107dba5af049cf1c36b646fc1ba0cd2705f40d766d2c4c64f1b797c5fbed" dependencies = [ "byteorder", "data-encoding", @@ -2843,9 +2842,9 @@ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "portable-atomic-util" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a9db96d7fa8782dd8c15ce32ffe8680bbd1e978a43bf51a34d39483540495f5" +checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" dependencies = [ "portable-atomic", ] @@ -3786,9 +3785,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.17.0" +version = "3.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "381b283ce7bc6b476d903296fb59d0d36633652b633b27f64db4fb46dcbfc3b9" +checksum = "dd5414fad8e6907dbdd5bc441a50ae8d6e26151a03b1de04d89a5576de61d01f" dependencies = [ "base64", "chrono", @@ -3805,11 +3804,11 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.17.0" +version = "3.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6d4e30573c8cb306ed6ab1dca8423eec9a463ea0e155f45399455e0368b27e0" +checksum = "d3db8978e608f1fe7357e211969fd9abdcae80bac1ba7a3369bb7eb6b404eb65" dependencies = [ - "darling 0.21.3", + "darling 0.23.0", "proc-macro2", "quote", "syn 2.0.117", @@ -3857,8 +3856,9 @@ dependencies = [ [[package]] name = "serenity-voice-model" -version = "0.2.1" -source = "git+https://github.com/serenity-rs/voice-model.git?branch=next#b1400a1272da4ed259314133b2536006de1850ab" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "910c6511e59df6fa362921e4900cdbd3192210231a2ba135594c480871422af6" dependencies = [ "bitflags 2.11.0", "num-traits", @@ -4001,7 +4001,7 @@ dependencies = [ [[package]] name = "songbird" version = "0.5.0" -source = "git+https://github.com/beerpsi-forks/songbird.git?branch=davey#653177e79f2275516d287861a48e5ff65cb7fa32" +source = "git+https://github.com/beerpsi-forks/songbird.git?branch=davey#4c5c2b5a258744cc731572edf42bb255e72caace" dependencies = [ "aead", "aes-gcm", @@ -4470,9 +4470,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" dependencies = [ "tinyvec_macros", ] @@ -5795,9 +5795,9 @@ dependencies = [ [[package]] name = "yt-dlp" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12e0bb5cb558359e6de1c929769b86aae55d1ed1d457ae3c61f9e1bb319fe030" +checksum = "f9ed388fbfcd437f1a0af3ff9e53b0d4903f9edebe2991c4afb14d3daa582dcb" dependencies = [ "async-trait", "cfg-if", diff --git a/apps/master/src/commands/mod.rs b/apps/master/src/commands/mod.rs index 9d5ba79..49fc66c 100644 --- a/apps/master/src/commands/mod.rs +++ b/apps/master/src/commands/mod.rs @@ -1,2 +1,42 @@ +use nats_libs::stream::{JetstreamClient, StreamClient}; +use serenity::all::{CommandInteraction, Context}; +use types::error::CorroError; + +use crate::common::Services; + pub mod ping; pub mod play; + +pub async fn queue_lock<'a, F, Fut>( + services: &'a Services, + ctx: &'a Context, + interaction: &'a CommandInteraction, + func: F, +) -> Result<(), CorroError> +where + F: Fn(&'a Services, &'a Context, &'a CommandInteraction) -> Fut, + Fut: Future> + 'a, +{ + let guild_id = interaction.guild_id.unwrap(); + + match services.jetstream_client.lock(guild_id.into()).await { + Ok(sequence) => { + let result = func(services, ctx, interaction).await; + + match services.jetstream_stream.unlock(sequence).await { + Ok(unlocked) => { + if !unlocked { + return Err(CorroError { + error_type: types::error::CorroErrorType::NatsError, + message: "Not unlocked".to_string(), + }); + } + } + Err(why) => return Err(why), + } + + result + } + Err(why) => Err(why), + } +} diff --git a/apps/master/src/main.rs b/apps/master/src/main.rs index f808618..f35cac1 100644 --- a/apps/master/src/main.rs +++ b/apps/master/src/main.rs @@ -4,7 +4,6 @@ mod common; use std::env; use async_nats::jetstream; -use nats_libs::stream::{JetstreamClient, StreamClient}; use serenity::{ all::{Context, EventHandler, GatewayIntents}, async_trait, @@ -16,7 +15,7 @@ use serenity::{ use serenity_libs::functions::CustomInteraction; use types::error::{CorroError, CorroErrorType}; -use crate::common::Services; +use crate::{commands::queue_lock, common::Services}; struct Handler { services: Services, @@ -29,22 +28,7 @@ impl EventHandler for Handler { println!("Received command interaction: {command:?}"); if let Err(why) = match command.data.name.as_str() { - "play" => { - let guild_id = command.guild_id.unwrap(); - - if let Ok(sequence) = self - .services - .jetstream_client - .lock(guild_id.into()) - .await - { - let result = commands::play::run(&self.services, &ctx, &command).await; - let _ = self.services.jetstream_stream.unlock(sequence).await; - result - } else { - Err(CorroError { error_type: CorroErrorType::NatsError, message: format!("Cannot lock {guild_id}") }) - } - } + "play" => queue_lock(&self.services, &ctx, &command, commands::play::run).await, "ping" => commands::ping::run(&ctx, &command).await, _ => Err(CorroError { error_type: CorroErrorType::CommandError, diff --git a/apps/worker/Cargo.toml b/apps/worker/Cargo.toml index 64f564d..31abfcc 100644 --- a/apps/worker/Cargo.toml +++ b/apps/worker/Cargo.toml @@ -23,4 +23,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.6.0" } +yt-dlp = { version = "2.7.0" }