send complex values
This commit is contained in:
Generated
+100
@@ -74,6 +74,15 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "atomic-waker"
|
name = "atomic-waker"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@@ -150,6 +159,15 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
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]]
|
[[package]]
|
||||||
name = "const-oid"
|
name = "const-oid"
|
||||||
version = "0.9.6"
|
version = "0.9.6"
|
||||||
@@ -190,6 +208,12 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "critical-section"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@@ -296,6 +320,18 @@ dependencies = [
|
|||||||
"subtle",
|
"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]]
|
[[package]]
|
||||||
name = "fiat-crypto"
|
name = "fiat-crypto"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
@@ -452,6 +488,29 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"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]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@@ -698,6 +757,15 @@ version = "0.8.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"
|
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]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.29"
|
version = "0.4.29"
|
||||||
@@ -715,6 +783,8 @@ name = "master"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-nats",
|
"async-nats",
|
||||||
|
"postcard",
|
||||||
|
"serde",
|
||||||
"serenity",
|
"serenity",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
@@ -867,6 +937,19 @@ version = "1.13.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
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]]
|
[[package]]
|
||||||
name = "potential_utf"
|
name = "potential_utf"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
@@ -1232,6 +1315,12 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"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]]
|
[[package]]
|
||||||
name = "secrecy"
|
name = "secrecy"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
@@ -1461,6 +1550,15 @@ dependencies = [
|
|||||||
"windows-sys 0.60.2",
|
"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]]
|
[[package]]
|
||||||
name = "spki"
|
name = "spki"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
@@ -2202,6 +2300,8 @@ dependencies = [
|
|||||||
"async-nats",
|
"async-nats",
|
||||||
"futures",
|
"futures",
|
||||||
"futures-executor",
|
"futures-executor",
|
||||||
|
"postcard",
|
||||||
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -13,3 +13,5 @@ serenity = { version = "0.12.5", default-features = false, features = [
|
|||||||
"collector",
|
"collector",
|
||||||
] }
|
] }
|
||||||
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
postcard = { version = "1.1.3", features = ["use-std"] }
|
||||||
|
serde = { version = "1.0.228" }
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
pub mod modal;
|
pub mod modal;
|
||||||
pub mod ping;
|
pub mod ping;
|
||||||
pub mod wonderful_command;
|
|
||||||
pub mod testnats;
|
pub mod testnats;
|
||||||
@@ -5,7 +5,22 @@ use serenity::all::{
|
|||||||
use serenity::builder::CreateCommand;
|
use serenity::builder::CreateCommand;
|
||||||
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
|
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,
|
ctx: &Context,
|
||||||
interaction: &CommandInteraction,
|
interaction: &CommandInteraction,
|
||||||
nats_client: &async_nats::Client,
|
nats_client: &async_nats::Client,
|
||||||
@@ -17,10 +32,19 @@ pub async fn run<'a>(
|
|||||||
..
|
..
|
||||||
}) = options.first()
|
}) = options.first()
|
||||||
{
|
{
|
||||||
if let Err(why) = nats_client
|
let hehe = &MyStruct {
|
||||||
.publish("jobs", format!("{}", value).into())
|
len: value.len(),
|
||||||
.await
|
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"));
|
return Err(serenity::Error::Other("send error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +52,7 @@ pub async fn run<'a>(
|
|||||||
.create_response(
|
.create_response(
|
||||||
ctx,
|
ctx,
|
||||||
CreateInteractionResponse::Message(
|
CreateInteractionResponse::Message(
|
||||||
CreateInteractionResponseMessage::new().content(format!("string: {}", value)),
|
CreateInteractionResponseMessage::new().content(*value),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -48,9 +72,9 @@ pub async fn run<'a>(
|
|||||||
|
|
||||||
pub fn register() -> CreateCommand {
|
pub fn register() -> CreateCommand {
|
||||||
CreateCommand::new("testnats")
|
CreateCommand::new("testnats")
|
||||||
.description("Get a user id")
|
.description("test nats")
|
||||||
.add_option(
|
.add_option(
|
||||||
CreateCommandOption::new(CommandOptionType::String, "str", "The user to lookup")
|
CreateCommandOption::new(CommandOptionType::String, "str", "random string")
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
use serenity::builder::CreateCommand;
|
|
||||||
|
|
||||||
pub fn register() -> CreateCommand {
|
|
||||||
CreateCommand::new("wonderful_command").description("An amazing command")
|
|
||||||
}
|
|
||||||
+10
-20
@@ -6,7 +6,6 @@ use serenity::async_trait;
|
|||||||
use serenity::builder::{CreateInteractionResponse, CreateInteractionResponseMessage};
|
use serenity::builder::{CreateInteractionResponse, CreateInteractionResponseMessage};
|
||||||
use serenity::model::application::{Command, Interaction};
|
use serenity::model::application::{Command, Interaction};
|
||||||
use serenity::model::gateway::Ready;
|
use serenity::model::gateway::Ready;
|
||||||
use serenity::model::id::GuildId;
|
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
|
||||||
struct Handler {
|
struct Handler {
|
||||||
@@ -47,26 +46,17 @@ impl EventHandler for Handler {
|
|||||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
println!("{} is connected!", ready.user.name);
|
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
|
println!("I now have the following slash commands: {commands:#?}");
|
||||||
.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:#?}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,3 +8,5 @@ async-nats = { version = "0.46.0" }
|
|||||||
futures = { version = "0.3.32" }
|
futures = { version = "0.3.32" }
|
||||||
futures-executor = { version = "0.3.32" }
|
futures-executor = { version = "0.3.32" }
|
||||||
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
||||||
|
postcard = { version = "1.1.3", features = ["use-std"] }
|
||||||
|
serde = { version = "1.0.228" }
|
||||||
|
|||||||
+24
-1
@@ -1,17 +1,40 @@
|
|||||||
|
use core::ops::Deref;
|
||||||
|
|
||||||
use futures::StreamExt;
|
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]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let nats_client = async_nats::connect("nats://localhost:4222")
|
let nats_client = async_nats::connect("nats://localhost:4222")
|
||||||
.await
|
.await
|
||||||
.expect("Error creating nats client");
|
.expect("Error creating nats client");
|
||||||
let mut subscriber = nats_client
|
let mut subscriber = nats_client
|
||||||
.queue_subscribe("jobs", "download".to_string())
|
.queue_subscribe("corro-dj.*", "download".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Receive and process messages
|
// Receive and process messages
|
||||||
while let Some(message) = subscriber.next().await {
|
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);
|
println!("Received message {:?}", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user