From 3194b8e37d9f92d3fc4185de90b779e7ed5a6e7a Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 22 Feb 2021 20:05:23 -0500 Subject: [PATCH] Make role field optional and reduce debug msgs --- src/auth_tools.rs | 18 +++++++++--------- src/discord.rs | 2 +- src/main.rs | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/auth_tools.rs b/src/auth_tools.rs index cb74424..92772ee 100644 --- a/src/auth_tools.rs +++ b/src/auth_tools.rs @@ -30,7 +30,7 @@ impl FromDataSimple for AuthenticatedInteraction { if signature_opt.is_some() && timestamp_opt.is_some() { let signature = signature_opt.unwrap().to_owned(); let timestamp = timestamp_opt.unwrap().to_owned(); - println!("signature: `{}` time: `{}`", &signature, ×tamp); // debug + //println!("signature: `{}` time: `{}`", &signature, ×tamp); // debug if let Ok(hex_data) = hex::decode(signature.clone()) { let mut buffer = [0; 64]; for i in 0..64 { // copy hex decode into static-size buffer @@ -47,7 +47,7 @@ impl FromDataSimple for AuthenticatedInteraction { .unwrap() .verify(msg.as_bytes(), &sign); if verif_result.is_err() { - println!("Signature validation error"); + //println!("Signature validation error"); return Outcome::Failure((Status::Unauthorized, ())) } if let Ok(payload) = serde_json::from_str::(&string_buf[..string_len]) { @@ -61,16 +61,16 @@ impl FromDataSimple for AuthenticatedInteraction { } return Outcome::Success(auth); } - println!("Invalid json payload {}\n({})", &string_buf[..string_len], serde_json::from_str::(&string_buf[..string_len]).err().unwrap()); - return Outcome::Failure((Status::Unauthorized, ())) + //println!("Invalid json payload {}\n({})", &string_buf[..string_len], serde_json::from_str::(&string_buf[..string_len]).err().unwrap()); + //return Outcome::Failure((Status::Unauthorized, ())) } - println!("Invalid body"); - return Outcome::Failure((Status::Unauthorized, ())) + //println!("Invalid body"); + //return Outcome::Failure((Status::Unauthorized, ())) } - println!("Invalid signature headers"); - return Outcome::Failure((Status::Unauthorized, ())) + //println!("Invalid signature headers"); + //return Outcome::Failure((Status::Unauthorized, ())) } - println!("Missing signature headers"); + //println!("Missing signature headers"); Outcome::Failure((Status::Unauthorized, ())) } } \ No newline at end of file diff --git a/src/discord.rs b/src/discord.rs index 11dd451..e2ef65e 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -103,7 +103,7 @@ pub struct InteractionCommand { pub struct GuildMember { pub user: Option, pub nick: Option, - pub role: Vec, + pub role: Option>, pub joined_at: String, pub premium_since: Option, pub deaf: bool, diff --git a/src/main.rs b/src/main.rs index ecf19c4..2bac7f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,19 +46,19 @@ fn main() { // Init verification key let public_key = std::env::var("DISCORD_PUBLIC_KEY") .expect("Environment variable DISCORD_PUBLIC_KEY not found"); - println!("Discord Pub Key {}", &public_key); + //println!("Discord Pub Key {}", &public_key); *VERIFICATION_KEY.write().unwrap() = Some(ed25519_dalek::PublicKey::from_bytes( &hex::decode(public_key) .expect("Invalid hex string")).expect("Invalid public key")); // get application ID for sending API requests let app_id = std::env::var("DISCORD_APP_ID") .expect("Environment variable DISCORD_APP_ID not found"); - println!("Discord App Id {}", &app_id); + //println!("Discord App Id {}", &app_id); *APPLICATION_ID.write().unwrap() = Some(app_id.to_string()); // get bot token for sending API requests let token = std::env::var("DISCORD_TOKEN") .expect("Environment variable DISCORD_TOKEN not found"); - println!("Discord Token {}", &token); + //println!("Discord Token {}", &token); *BOT_TOKEN.write().unwrap() = Some(token.to_string()); // send API requests to bootstrap commands @@ -80,8 +80,8 @@ fn register_command(f: &dyn Fn() -> (discord::ApplicationCommand, Option .json(&payload) .send(); if let Ok(d) = res { - println!("`{}` status {}", &payload.name, &d.status().as_str()); - println!("{}", &d.text().unwrap()); + println!("Registered/updated `{}` ({}) GUILD:{}", &payload.name, &d.status().as_str(), &guild_id); + //println!("{}", &d.text().unwrap()); } } else { // create/upsert command @@ -91,8 +91,8 @@ fn register_command(f: &dyn Fn() -> (discord::ApplicationCommand, Option .json(&payload) .send(); if let Ok(d) = res { - println!("`{}` status {}", &payload.name, &d.status().as_str()); - println!("{}", &d.text().unwrap()); + println!("Registered/updated `{}` ({})", &payload.name, &d.status().as_str()); + //println!("{}", &d.text().unwrap()); } } }