Browse Source

Make role field optional and reduce debug msgs

master
NGnius (Graham) 3 years ago
parent
commit
3194b8e37d
3 changed files with 17 additions and 17 deletions
  1. +9
    -9
      src/auth_tools.rs
  2. +1
    -1
      src/discord.rs
  3. +7
    -7
      src/main.rs

+ 9
- 9
src/auth_tools.rs View File

@@ -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, &timestamp); // debug
//println!("signature: `{}` time: `{}`", &signature, &timestamp); // 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::<InteractionRaw>(&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::<InteractionRaw>(&string_buf[..string_len]).err().unwrap());
return Outcome::Failure((Status::Unauthorized, ()))
//println!("Invalid json payload {}\n({})", &string_buf[..string_len], serde_json::from_str::<InteractionRaw>(&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, ()))
}
}

+ 1
- 1
src/discord.rs View File

@@ -103,7 +103,7 @@ pub struct InteractionCommand {
pub struct GuildMember {
pub user: Option<User>,
pub nick: Option<String>,
pub role: Vec<String>,
pub role: Option<Vec<String>>,
pub joined_at: String,
pub premium_since: Option<String>,
pub deaf: bool,


+ 7
- 7
src/main.rs View File

@@ -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<String>
.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<String>
.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());
}
}
}


Loading…
Cancel
Save