diff --git a/Cargo.lock b/Cargo.lock index b9855e2..7856aa8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,6 +74,15 @@ dependencies = [ "syn", ] +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -150,6 +159,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "cobs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" +dependencies = [ + "thiserror 2.0.18", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -190,6 +208,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + [[package]] name = "crypto-common" version = "0.1.7" @@ -296,6 +320,18 @@ dependencies = [ "subtle", ] +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "fiat-crypto" version = "0.2.9" @@ -452,6 +488,29 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version", + "serde", + "spin", + "stable_deref_trait", +] + [[package]] name = "http" version = "1.4.0" @@ -698,6 +757,15 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.29" @@ -715,6 +783,8 @@ name = "master" version = "0.1.0" dependencies = [ "async-nats", + "postcard", + "serde", "serenity", "tokio", ] @@ -867,6 +937,19 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" +[[package]] +name = "postcard" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "heapless", + "serde", +] + [[package]] name = "potential_utf" version = "0.1.4" @@ -1232,6 +1315,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "secrecy" version = "0.8.0" @@ -1461,6 +1550,15 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + [[package]] name = "spki" version = "0.7.3" @@ -2202,6 +2300,8 @@ dependencies = [ "async-nats", "futures", "futures-executor", + "postcard", + "serde", "tokio", ] diff --git a/master/Cargo.toml b/master/Cargo.toml index 797c81d..edaae87 100644 --- a/master/Cargo.toml +++ b/master/Cargo.toml @@ -13,3 +13,5 @@ serenity = { version = "0.12.5", default-features = false, features = [ "collector", ] } tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] } +postcard = { version = "1.1.3", features = ["use-std"] } +serde = { version = "1.0.228" } diff --git a/master/src/commands/mod.rs b/master/src/commands/mod.rs index c71885f..5d04254 100644 --- a/master/src/commands/mod.rs +++ b/master/src/commands/mod.rs @@ -1,4 +1,3 @@ pub mod modal; pub mod ping; -pub mod wonderful_command; -pub mod testnats; \ No newline at end of file +pub mod testnats; diff --git a/master/src/commands/testnats.rs b/master/src/commands/testnats.rs index e80ec61..5915743 100644 --- a/master/src/commands/testnats.rs +++ b/master/src/commands/testnats.rs @@ -5,7 +5,22 @@ use serenity::all::{ use serenity::builder::CreateCommand; use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue}; -pub async fn run<'a>( +use postcard::to_stdvec; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +struct InnerStruct<'a> { + str: &'a str, +} + +#[derive(Serialize, Deserialize, Debug)] +struct MyStruct<'a> { + len: usize, + str: &'a str, + inner: InnerStruct<'a>, +} + +pub async fn run( ctx: &Context, interaction: &CommandInteraction, nats_client: &async_nats::Client, @@ -17,10 +32,19 @@ pub async fn run<'a>( .. }) = options.first() { - if let Err(why) = nats_client - .publish("jobs", format!("{}", value).into()) - .await - { + let hehe = &MyStruct { + len: value.len(), + str: value, + inner: InnerStruct { str: &value.repeat(3) } + }; + + println!("{:?}", hehe); + + let ahah = to_stdvec(hehe).unwrap(); + + println!("{:?}", ahah); + + if let Err(why) = nats_client.publish("corro-dj.download", ahah.into()).await { return Err(serenity::Error::Other("send error")); } @@ -28,7 +52,7 @@ pub async fn run<'a>( .create_response( ctx, CreateInteractionResponse::Message( - CreateInteractionResponseMessage::new().content(format!("string: {}", value)), + CreateInteractionResponseMessage::new().content(*value), ), ) .await?; @@ -48,9 +72,9 @@ pub async fn run<'a>( pub fn register() -> CreateCommand { CreateCommand::new("testnats") - .description("Get a user id") + .description("test nats") .add_option( - CreateCommandOption::new(CommandOptionType::String, "str", "The user to lookup") + CreateCommandOption::new(CommandOptionType::String, "str", "random string") .required(false), ) } diff --git a/master/src/commands/wonderful_command.rs b/master/src/commands/wonderful_command.rs deleted file mode 100644 index 95e4f17..0000000 --- a/master/src/commands/wonderful_command.rs +++ /dev/null @@ -1,5 +0,0 @@ -use serenity::builder::CreateCommand; - -pub fn register() -> CreateCommand { - CreateCommand::new("wonderful_command").description("An amazing command") -} diff --git a/master/src/main.rs b/master/src/main.rs index a47cf83..695244e 100644 --- a/master/src/main.rs +++ b/master/src/main.rs @@ -6,7 +6,6 @@ use serenity::async_trait; use serenity::builder::{CreateInteractionResponse, CreateInteractionResponseMessage}; use serenity::model::application::{Command, Interaction}; use serenity::model::gateway::Ready; -use serenity::model::id::GuildId; use serenity::prelude::*; struct Handler { @@ -47,26 +46,17 @@ impl EventHandler for Handler { async fn ready(&self, ctx: Context, ready: Ready) { println!("{} is connected!", ready.user.name); - let guild_id = GuildId::new(302837320250294283); + let commands = Command::set_global_commands( + &ctx.http, + vec![ + commands::ping::register(), + commands::modal::register(), + commands::testnats::register(), + ], + ) + .await; - let commands = guild_id - .set_commands( - &ctx.http, - vec![ - commands::ping::register(), - commands::modal::register(), - commands::testnats::register(), - ], - ) - .await; - - println!("I now have the following guild slash commands: {commands:#?}"); - - let global_command = - Command::create_global_command(&ctx.http, commands::wonderful_command::register()) - .await; - - println!("I created the following global slash command: {global_command:#?}"); + println!("I now have the following slash commands: {commands:#?}"); } } diff --git a/worker/Cargo.toml b/worker/Cargo.toml index 09cca19..d6133de 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -8,3 +8,5 @@ async-nats = { version = "0.46.0" } futures = { version = "0.3.32" } futures-executor = { version = "0.3.32" } tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] } +postcard = { version = "1.1.3", features = ["use-std"] } +serde = { version = "1.0.228" } diff --git a/worker/src/main.rs b/worker/src/main.rs index da1ab40..da1cec5 100644 --- a/worker/src/main.rs +++ b/worker/src/main.rs @@ -1,17 +1,40 @@ +use core::ops::Deref; + use futures::StreamExt; +use postcard::from_bytes; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +struct InnerStruct<'a> { + str: &'a str, +} + +#[derive(Serialize, Deserialize, Debug)] +struct MyStruct<'a> { + len: usize, + str: &'a str, + inner: InnerStruct<'a>, +} + #[tokio::main] async fn main() { let nats_client = async_nats::connect("nats://localhost:4222") .await .expect("Error creating nats client"); let mut subscriber = nats_client - .queue_subscribe("jobs", "download".to_string()) + .queue_subscribe("corro-dj.*", "download".to_string()) .await .unwrap(); // Receive and process messages while let Some(message) = subscriber.next().await { + println!("{:?}", message.payload); + + let result: MyStruct = from_bytes(message.payload.deref()).unwrap(); + + println!("{:?}", result); + println!("Received message {:?}", message); } }