Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ client_id = "WlVrcm4xSEpXQ2l3TURFM3lLZnE6MTpjaQ"
client_secret = "lfXc45dZLqYTzP62Ms32EhXinGQzxcIP9TvjJml2B-h0T1nIJK"

[x_association]
bio_mention = "@QuantusNetwork"
keywords = "Quantus"

[tweet_sync]
api_key = "some-key"
Expand Down
2 changes: 1 addition & 1 deletion config/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ client_id = "example-id"
client_secret = "example-secret"

[x_association]
bio_mention = "@QuantusNetwork"
keywords = "Quantus"

[tweet_sync]
api_key = "some-key"
Expand Down
2 changes: 1 addition & 1 deletion config/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ client_id = "test-id"
client_secret = "test-secret"

[x_association]
bio_mention = "@QuantusNetwork"
keywords = "Quantus"

[tweet_sync]
api_key = "some-key"
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub struct AlertConfig {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct XAssociationConfig {
pub bio_mention: String,
pub keywords: String,
}

impl Config {
Expand Down Expand Up @@ -142,8 +142,8 @@ impl Config {
time::Duration::from_secs(self.raid_leaderboard.tweets_req_interval_in_secs)
}

pub fn get_x_bio_mention(&self) -> &str {
&self.x_association.bio_mention
pub fn get_x_association_keywords(&self) -> &str {
&self.x_association.keywords
}
}

Expand Down Expand Up @@ -204,7 +204,7 @@ impl Default for Config {
webhook_url: "https://your-webhook-url.com".to_string(),
},
x_association: XAssociationConfig {
bio_mention: "@QuantusNetwork".to_string(),
keywords: "Quantus".to_string(),
},
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/handlers/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ pub async fn associate_x_handle(
)))
})?;

let bio = twitter_user.description.unwrap_or_default();
let x_bio_mention = state.config.get_x_bio_mention();
if !bio.to_lowercase().contains(&x_bio_mention.to_lowercase()) {
let name = twitter_user.name;
let x_association_keywords = state.config.get_x_association_keywords();
if !name.to_lowercase().contains(&x_association_keywords.to_lowercase()) {
return Err(AppError::Handler(HandlerError::Address(
AddressHandlerError::Unauthorized(format!(
"Twitter bio must contain '{}' to verify ownership",
x_bio_mention
"Twitter name must contain '{}' to verify ownership",
x_association_keywords
)),
)));
}
Expand Down Expand Up @@ -431,14 +431,14 @@ mod tests {
let mut mock_user_api = MockUserApi::new();

// Expect get_by_username
let bio_mention = state.config.get_x_bio_mention().to_string();
let x_association_keywords = state.config.get_x_association_keywords().to_string();
mock_user_api.expect_get_by_username().returning(move |_, _| {
Ok(TwitterApiResponse {
data: Some(User {
id: "u1".to_string(),
name: "Test User".to_string(),
name: format!("Test User {}", x_association_keywords),
username: "test_user".to_string(),
description: Some(format!("I love {}", bio_mention)), // Contains keyword from config
description: Some(format!("I love {}", x_association_keywords)), // Contains keyword from config
public_metrics: None,
}),
includes: None,
Expand Down Expand Up @@ -552,17 +552,17 @@ mod tests {
let mut mock_user_api = MockUserApi::new();

// Expect get_by_username
let bio_mention = state.config.get_x_bio_mention().to_string();
let x_association_keywords = state.config.get_x_association_keywords().to_string();
// Create a lowercase version of the mention for the bio
let lowercase_bio_mention = bio_mention.to_lowercase();
let lowercase_x_association_keywords = x_association_keywords.to_lowercase();

mock_user_api.expect_get_by_username().returning(move |_, _| {
Ok(TwitterApiResponse {
data: Some(User {
id: "u1".to_string(),
name: "Test User".to_string(),
name: format!("Test User {}", lowercase_x_association_keywords),
username: "test_user".to_string(),
description: Some(format!("I love {}", lowercase_bio_mention)), // Contains lowercase keyword
description: Some(format!("I love {}", lowercase_x_association_keywords)), // Contains lowercase keyword
public_metrics: None,
}),
includes: None,
Expand Down