wrap lock function
This commit is contained in:
Generated
+28
-28
@@ -314,9 +314,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.56"
|
version = "1.2.57"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2"
|
checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
"jobserver",
|
"jobserver",
|
||||||
@@ -653,12 +653,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling"
|
name = "darling"
|
||||||
version = "0.21.3"
|
version = "0.23.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0"
|
checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core 0.21.3",
|
"darling_core 0.23.0",
|
||||||
"darling_macro 0.21.3",
|
"darling_macro 0.23.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -677,11 +677,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling_core"
|
name = "darling_core"
|
||||||
version = "0.21.3"
|
version = "0.23.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4"
|
checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fnv",
|
|
||||||
"ident_case",
|
"ident_case",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -702,11 +701,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling_macro"
|
name = "darling_macro"
|
||||||
version = "0.21.3"
|
version = "0.23.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81"
|
checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core 0.21.3",
|
"darling_core 0.23.0",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.117",
|
"syn 2.0.117",
|
||||||
]
|
]
|
||||||
@@ -2181,9 +2180,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lofty"
|
name = "lofty"
|
||||||
version = "0.23.2"
|
version = "0.23.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "179408be6ddda3771589a4e940b1b5718613fa9986d78f420890d20e2b6fc278"
|
checksum = "6d0c107dba5af049cf1c36b646fc1ba0cd2705f40d766d2c4c64f1b797c5fbed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -2843,9 +2842,9 @@ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "portable-atomic-util"
|
name = "portable-atomic-util"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7a9db96d7fa8782dd8c15ce32ffe8680bbd1e978a43bf51a34d39483540495f5"
|
checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"portable-atomic",
|
"portable-atomic",
|
||||||
]
|
]
|
||||||
@@ -3786,9 +3785,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with"
|
name = "serde_with"
|
||||||
version = "3.17.0"
|
version = "3.18.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "381b283ce7bc6b476d903296fb59d0d36633652b633b27f64db4fb46dcbfc3b9"
|
checksum = "dd5414fad8e6907dbdd5bc441a50ae8d6e26151a03b1de04d89a5576de61d01f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -3805,11 +3804,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with_macros"
|
name = "serde_with_macros"
|
||||||
version = "3.17.0"
|
version = "3.18.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a6d4e30573c8cb306ed6ab1dca8423eec9a463ea0e155f45399455e0368b27e0"
|
checksum = "d3db8978e608f1fe7357e211969fd9abdcae80bac1ba7a3369bb7eb6b404eb65"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling 0.21.3",
|
"darling 0.23.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.117",
|
"syn 2.0.117",
|
||||||
@@ -3857,8 +3856,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serenity-voice-model"
|
name = "serenity-voice-model"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/serenity-rs/voice-model.git?branch=next#b1400a1272da4ed259314133b2536006de1850ab"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "910c6511e59df6fa362921e4900cdbd3192210231a2ba135594c480871422af6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.11.0",
|
"bitflags 2.11.0",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
@@ -4001,7 +4001,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "songbird"
|
name = "songbird"
|
||||||
version = "0.5.0"
|
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 = [
|
dependencies = [
|
||||||
"aead",
|
"aead",
|
||||||
"aes-gcm",
|
"aes-gcm",
|
||||||
@@ -4470,9 +4470,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinyvec"
|
name = "tinyvec"
|
||||||
version = "1.10.0"
|
version = "1.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa"
|
checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tinyvec_macros",
|
"tinyvec_macros",
|
||||||
]
|
]
|
||||||
@@ -5795,9 +5795,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yt-dlp"
|
name = "yt-dlp"
|
||||||
version = "2.6.0"
|
version = "2.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "12e0bb5cb558359e6de1c929769b86aae55d1ed1d457ae3c61f9e1bb319fe030"
|
checksum = "f9ed388fbfcd437f1a0af3ff9e53b0d4903f9edebe2991c4afb14d3daa582dcb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
|||||||
@@ -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 ping;
|
||||||
pub mod play;
|
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<Output = Result<(), CorroError>> + '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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+2
-18
@@ -4,7 +4,6 @@ mod common;
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use async_nats::jetstream;
|
use async_nats::jetstream;
|
||||||
use nats_libs::stream::{JetstreamClient, StreamClient};
|
|
||||||
use serenity::{
|
use serenity::{
|
||||||
all::{Context, EventHandler, GatewayIntents},
|
all::{Context, EventHandler, GatewayIntents},
|
||||||
async_trait,
|
async_trait,
|
||||||
@@ -16,7 +15,7 @@ use serenity::{
|
|||||||
use serenity_libs::functions::CustomInteraction;
|
use serenity_libs::functions::CustomInteraction;
|
||||||
use types::error::{CorroError, CorroErrorType};
|
use types::error::{CorroError, CorroErrorType};
|
||||||
|
|
||||||
use crate::common::Services;
|
use crate::{commands::queue_lock, common::Services};
|
||||||
|
|
||||||
struct Handler {
|
struct Handler {
|
||||||
services: Services,
|
services: Services,
|
||||||
@@ -29,22 +28,7 @@ impl EventHandler for Handler {
|
|||||||
println!("Received command interaction: {command:?}");
|
println!("Received command interaction: {command:?}");
|
||||||
|
|
||||||
if let Err(why) = match command.data.name.as_str() {
|
if let Err(why) = match command.data.name.as_str() {
|
||||||
"play" => {
|
"play" => queue_lock(&self.services, &ctx, &command, commands::play::run).await,
|
||||||
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}") })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"ping" => commands::ping::run(&ctx, &command).await,
|
"ping" => commands::ping::run(&ctx, &command).await,
|
||||||
_ => Err(CorroError {
|
_ => Err(CorroError {
|
||||||
error_type: CorroErrorType::CommandError,
|
error_type: CorroErrorType::CommandError,
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ symphonia = { version = "0.5.5" }
|
|||||||
tokio = { version = "1.50.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.50.0", features = ["macros", "rt-multi-thread"] }
|
||||||
types = { path = "../../libs/types" }
|
types = { path = "../../libs/types" }
|
||||||
which = { version = "8.0.2" }
|
which = { version = "8.0.2" }
|
||||||
yt-dlp = { version = "2.6.0" }
|
yt-dlp = { version = "2.7.0" }
|
||||||
|
|||||||
Reference in New Issue
Block a user