send complex values
This commit is contained in:
@@ -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" }
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod modal;
|
||||
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::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),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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::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:#?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user