Skip to content

Commit a683f0c

Browse files
authored
Merge pull request #52 from Quantus-Network/feat/update-x-association-logic
Update x association logic
2 parents 24c7f47 + 238ed1d commit a683f0c

5 files changed

Lines changed: 19 additions & 19 deletions

File tree

config/default.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ client_id = "WlVrcm4xSEpXQ2l3TURFM3lLZnE6MTpjaQ"
5555
client_secret = "lfXc45dZLqYTzP62Ms32EhXinGQzxcIP9TvjJml2B-h0T1nIJK"
5656

5757
[x_association]
58-
bio_mention = "@QuantusNetwork"
58+
keywords = "Quantus"
5959

6060
[tweet_sync]
6161
api_key = "some-key"

config/example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ client_id = "example-id"
6565
client_secret = "example-secret"
6666

6767
[x_association]
68-
bio_mention = "@QuantusNetwork"
68+
keywords = "Quantus"
6969

7070
[tweet_sync]
7171
api_key = "some-key"

config/test.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ client_id = "test-id"
5555
client_secret = "test-secret"
5656

5757
[x_association]
58-
bio_mention = "@QuantusNetwork"
58+
keywords = "Quantus"
5959

6060
[tweet_sync]
6161
api_key = "some-key"

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub struct AlertConfig {
8888

8989
#[derive(Debug, Clone, Serialize, Deserialize)]
9090
pub struct XAssociationConfig {
91-
pub bio_mention: String,
91+
pub keywords: String,
9292
}
9393

9494
impl Config {
@@ -142,8 +142,8 @@ impl Config {
142142
time::Duration::from_secs(self.raid_leaderboard.tweets_req_interval_in_secs)
143143
}
144144

145-
pub fn get_x_bio_mention(&self) -> &str {
146-
&self.x_association.bio_mention
145+
pub fn get_x_association_keywords(&self) -> &str {
146+
&self.x_association.keywords
147147
}
148148
}
149149

@@ -204,7 +204,7 @@ impl Default for Config {
204204
webhook_url: "https://your-webhook-url.com".to_string(),
205205
},
206206
x_association: XAssociationConfig {
207-
bio_mention: "@QuantusNetwork".to_string(),
207+
keywords: "Quantus".to_string(),
208208
},
209209
}
210210
}

src/handlers/address.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ pub async fn associate_x_handle(
258258
)))
259259
})?;
260260

261-
let bio = twitter_user.description.unwrap_or_default();
262-
let x_bio_mention = state.config.get_x_bio_mention();
263-
if !bio.to_lowercase().contains(&x_bio_mention.to_lowercase()) {
261+
let name = twitter_user.name;
262+
let x_association_keywords = state.config.get_x_association_keywords();
263+
if !name.to_lowercase().contains(&x_association_keywords.to_lowercase()) {
264264
return Err(AppError::Handler(HandlerError::Address(
265265
AddressHandlerError::Unauthorized(format!(
266-
"Twitter bio must contain '{}' to verify ownership",
267-
x_bio_mention
266+
"Twitter name must contain '{}' to verify ownership",
267+
x_association_keywords
268268
)),
269269
)));
270270
}
@@ -431,14 +431,14 @@ mod tests {
431431
let mut mock_user_api = MockUserApi::new();
432432

433433
// Expect get_by_username
434-
let bio_mention = state.config.get_x_bio_mention().to_string();
434+
let x_association_keywords = state.config.get_x_association_keywords().to_string();
435435
mock_user_api.expect_get_by_username().returning(move |_, _| {
436436
Ok(TwitterApiResponse {
437437
data: Some(User {
438438
id: "u1".to_string(),
439-
name: "Test User".to_string(),
439+
name: format!("Test User {}", x_association_keywords),
440440
username: "test_user".to_string(),
441-
description: Some(format!("I love {}", bio_mention)), // Contains keyword from config
441+
description: Some(format!("I love {}", x_association_keywords)), // Contains keyword from config
442442
public_metrics: None,
443443
}),
444444
includes: None,
@@ -552,17 +552,17 @@ mod tests {
552552
let mut mock_user_api = MockUserApi::new();
553553

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

559559
mock_user_api.expect_get_by_username().returning(move |_, _| {
560560
Ok(TwitterApiResponse {
561561
data: Some(User {
562562
id: "u1".to_string(),
563-
name: "Test User".to_string(),
563+
name: format!("Test User {}", lowercase_x_association_keywords),
564564
username: "test_user".to_string(),
565-
description: Some(format!("I love {}", lowercase_bio_mention)), // Contains lowercase keyword
565+
description: Some(format!("I love {}", lowercase_x_association_keywords)), // Contains lowercase keyword
566566
public_metrics: None,
567567
}),
568568
includes: None,

0 commit comments

Comments
 (0)