diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74ed0c5..476d9aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: steps: # The sequence of tasks that make up a job. - name: Checking out repository code - uses: actions/checkout@v4.1.0 # Action for checking out a repo. + uses: actions/checkout@v4.1.1 # Action for checking out a repo. # Cache dependencies to speed up builds - name: Cache cargo dependencies @@ -85,7 +85,7 @@ jobs: steps: # Checkout the repository code - name: Checkout code - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 with: fetch-depth: 0 # Fetches all history for all branches and tags diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 87afdef..c36f054 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,7 +17,7 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 with: ref: ${{ github.event.release.tag_name }} diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b2801..a423ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ All notable changes to this project will be documented in this file. +## [1.0.4-alpha.0] - 2023-10-18 + +### Refactor + +- Change proposal and idea ids to string in caches +- Replace unwrap with error handling in farcaster handlers +- Remove unnecessary condition check before HTTP request +- Replace `unwrap_or` with `ok_or` in retrieving hash + +### Miscellaneous Tasks + +- Update crons schedule in `wrangler.toml` + ## [1.0.3] - 2023-10-18 ### Bug Fixes diff --git a/Cargo.lock b/Cargo.lock index 6b2307b..f3a82d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1553,7 +1553,7 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "lilnouns-bots" -version = "1.0.3" +version = "1.0.4-alpha.0" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index b5bd4ad..bd6eed1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lilnouns-bots" -version = "1.0.3" +version = "1.0.4-alpha.0" authors = ["Milad Nekofar "] edition = "2021" description = "Our bots are designed to keep the Lil Nouns DAO community informed and engaged." diff --git a/src/lil_nouns/handler/farcaster.rs b/src/lil_nouns/handler/farcaster.rs index 15f78dc..3685eea 100644 --- a/src/lil_nouns/handler/farcaster.rs +++ b/src/lil_nouns/handler/farcaster.rs @@ -144,11 +144,16 @@ impl Handler for FarcasterHandler { let mut proposals_casts = self .cache - .get::>("lil_nouns:proposals:casts") + .get::>("lil_nouns:proposals:casts") .await? .unwrap_or_default(); - proposals_casts.insert(proposal.id, cast_hash.to_string()); + proposals_casts.insert(proposal.id.to_string(), cast_hash.to_string()); + + self + .cache + .put("lil_nouns:proposals:casts", &proposals_casts) + .await; Ok(()) } @@ -165,17 +170,18 @@ impl Handler for FarcasterHandler { let proposal = proposals .iter() .find(|&a| a.id == vote.proposal_id) - .unwrap() - .clone(); + .cloned() + .ok_or("Proposal not found in the funding list.")?; let proposals_casts = self .cache - .get::>("lil_nouns:proposals:casts") + .get::>("lil_nouns:proposals:casts") .await? .unwrap_or_default(); - let empty_string = String::new(); - let cast_hash = proposals_casts.get(&proposal.id).unwrap_or(&empty_string); + let cast_hash = proposals_casts + .get(&proposal.id.to_string()) + .ok_or("Cast hash not found")?; let wallet = get_wallet_handle(&vote.voter, "xyz.farcaster").await; @@ -191,15 +197,13 @@ impl Handler for FarcasterHandler { proposal.title ); - if !cast_hash.is_empty() { - let request_data = json!({ - "text": description, - "channelKey": self.channel_key, - "parent": {"hash": cast_hash}, - }); + let request_data = json!({ + "text": description, + "channelKey": self.channel_key, + "parent": {"hash": cast_hash}, + }); - self.make_http_request(request_data).await?; - } + self.make_http_request(request_data).await?; Ok(()) } diff --git a/src/meta_gov/handler/farcaster.rs b/src/meta_gov/handler/farcaster.rs index daa2ff6..8676086 100644 --- a/src/meta_gov/handler/farcaster.rs +++ b/src/meta_gov/handler/farcaster.rs @@ -167,6 +167,11 @@ impl Handler for FarcasterHandler { .unwrap_or_default(); proposals_casts.insert(proposal_id, cast_hash.to_string()); + + self + .cache + .put("meta_gov:proposals:casts", &proposals_casts) + .await; } Err(e) => { error!("Failed to extract proposal info: {}", e); @@ -188,8 +193,8 @@ impl Handler for FarcasterHandler { let proposal = proposals .iter() .find(|&a| a.id == vote.proposal_id) - .unwrap() - .clone(); + .clone() + .ok_or("Proposal not found in the funding list.")?; match self.extract_proposal_info(proposal.clone()).await { Ok((proposal_id, proposal_title)) => { @@ -199,8 +204,9 @@ impl Handler for FarcasterHandler { .await? .unwrap_or_default(); - let empty_string = String::new(); - let cast_hash = proposals_casts.get(&proposal_id).unwrap_or(&empty_string); + let cast_hash = proposals_casts + .get(&proposal_id) + .ok_or("Cast hash not found")?; let wallet = get_wallet_handle(&vote.voter, "xyz.farcaster").await; @@ -216,15 +222,13 @@ impl Handler for FarcasterHandler { proposal_title ); - if !cast_hash.is_empty() { - let request_data = json!({ - "text": description, - "channelKey": self.channel_key, - "parent": {"hash": cast_hash}, - }); + let request_data = json!({ + "text": description, + "channelKey": self.channel_key, + "parent": {"hash": cast_hash}, + }); - self.make_http_request(request_data).await?; - } + self.make_http_request(request_data).await?; } Err(e) => { error!("Failed to extract proposal info: {}", e); diff --git a/src/prop_house/handler/farcaster.rs b/src/prop_house/handler/farcaster.rs index 3cded9a..dd75332 100644 --- a/src/prop_house/handler/farcaster.rs +++ b/src/prop_house/handler/farcaster.rs @@ -126,8 +126,8 @@ impl Handler for FarcasterHandler { let auction = auctions .iter() .find(|&a| a.id == proposal.auction_id) - .unwrap() - .clone(); + .clone() + .ok_or("Auction not found in the funding list.")?; let url = format!( "{}/{}/{}", @@ -181,6 +181,11 @@ impl Handler for FarcasterHandler { proposals_casts.insert(proposal.id, cast_hash.to_string()); + self + .cache + .put("prop_house:proposals:casts", &proposals_casts) + .await; + Ok(()) } @@ -196,8 +201,8 @@ impl Handler for FarcasterHandler { let proposal = proposals .iter() .find(|&a| a.id == vote.proposal_id) - .unwrap() - .clone(); + .clone() + .ok_or("Proposal not found in the funding list.")?; let proposals_casts = self .cache @@ -205,8 +210,9 @@ impl Handler for FarcasterHandler { .await? .unwrap_or_default(); - let empty_string = String::new(); - let cast_hash = proposals_casts.get(&proposal.id).unwrap_or(&empty_string); + let cast_hash = proposals_casts + .get(&proposal.id) + .ok_or("Cast hash not found")?; let wallet = get_wallet_handle(&vote.address, "xyz.farcaster").await; @@ -220,15 +226,13 @@ impl Handler for FarcasterHandler { proposal.title ); - if !cast_hash.is_empty() { - let request_data = json!({ - "text": description, - "channelKey": self.channel_key, - "parent": {"hash": cast_hash}, - }); + let request_data = json!({ + "text": description, + "channelKey": self.channel_key, + "parent": {"hash": cast_hash}, + }); - self.make_http_request(request_data).await?; - } + self.make_http_request(request_data).await?; Ok(()) } diff --git a/src/prop_lot/handler/farcaster.rs b/src/prop_lot/handler/farcaster.rs index 361b8f0..8f13688 100644 --- a/src/prop_lot/handler/farcaster.rs +++ b/src/prop_lot/handler/farcaster.rs @@ -147,11 +147,11 @@ impl Handler for FarcasterHandler { let idea_id = idea.id; let mut ideas_casts = self .cache - .get::>("prop_lot:ideas:casts") + .get::>("prop_lot:ideas:casts") .await? .unwrap_or_default(); - ideas_casts.insert(idea_id, cast_hash.to_string()); + ideas_casts.insert(idea_id.to_string(), cast_hash.to_string()); self.cache.put("prop_lot:ideas:casts", &ideas_casts).await; @@ -170,8 +170,8 @@ impl Handler for FarcasterHandler { let idea = ideas .iter() .find(|&a| a.id == vote.idea_id) - .unwrap() - .clone(); + .clone() + .ok_or("Idea not found in the funding list.")?; let ideas_casts = self .cache @@ -179,8 +179,7 @@ impl Handler for FarcasterHandler { .await? .unwrap_or_default(); - let empty_string = String::new(); - let cast_hash = ideas_casts.get(&idea.id).unwrap_or(&empty_string); + let cast_hash = ideas_casts.get(&idea.id).ok_or("Cast hash not found")?; let wallet = get_wallet_handle(&vote.voter_id, "xyz.farcaster").await; @@ -228,16 +227,18 @@ impl Handler for FarcasterHandler { let idea = ideas .iter() .find(|&a| a.id == comment.idea_id) - .unwrap() - .clone(); + .clone() + .ok_or("Idea not found in the funding list.")?; let ideas_casts = self .cache - .get::>("prop_lot:ideas:casts") + .get::>("prop_lot:ideas:casts") .await? .unwrap_or_default(); - let cast_hash = ideas_casts.get(&idea.id).unwrap(); + let cast_hash = ideas_casts + .get(&idea.id.to_string()) + .ok_or("Cast hash not found")?; let wallet = get_wallet_handle(&comment.author_id, "xyz.farcaster").await; @@ -250,15 +251,13 @@ impl Handler for FarcasterHandler { } description = format!("{}\n\nā€œ{}ā€", description, comment_body); - if !cast_hash.is_empty() { - let request_data = json!({ - "text": description, - "channelKey": self.channel_key, - "parent": {"hash": cast_hash}, - }); + let request_data = json!({ + "text": description, + "channelKey": self.channel_key, + "parent": {"hash": cast_hash}, + }); - self.make_http_request(request_data).await?; - } + self.make_http_request(request_data).await?; Ok(()) } diff --git a/wrangler.toml b/wrangler.toml index 83d5d24..d7e2155 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -14,7 +14,7 @@ command = "cargo install -q -f worker-build && worker-build --release" # Trigger Settings [triggers] -crons = ["*/5 * * * *"] +crons = ["*/1 * * * *"] # Default KV Namespace [[kv_namespaces]]