Skip to content

Commit

Permalink
feat(poll api): hash discord user id (ReVanced#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Axelen123 authored Jan 4, 2023
1 parent 403560b commit 99c476d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ reqwest = { version = "0.11", features= ["rustls-tls"], default-features = false
chrono = "0.4"
dirs = "4.0"
tracing = { version = "0.1", features = ["max_level_debug", "release_max_level_info"] }
tracing-subscriber = "0.3"
tracing-subscriber = "0.3"
sha3 = "0.10"
hex = "0.4"
6 changes: 5 additions & 1 deletion src/utils/poll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use poise::serenity_prelude::{ButtonStyle, ReactionType, Timestamp};

use sha3::{Digest, Sha3_256};
use tracing::log::{error, info, trace};

use super::bot::get_data_lock;
Expand All @@ -22,9 +23,12 @@ pub async fn handle_poll(

let eligible = member.joined_at.unwrap() <= min_join_date;
let auth_token = if eligible {
let mut hasher = Sha3_256::new();
hasher.update(&member.user.id.to_string());
let result = data
.api
.authenticate(&member.user.id.to_string())
// We cannot use the entire hash because Discord rejects URLs with more than 512 characters.
.authenticate(&hex::encode(hasher.finalize())[..2^5])
.await
.map(|auth| auth.access_token);

Expand Down

0 comments on commit 99c476d

Please sign in to comment.