Skip to content

Commit

Permalink
Merge branch 'release/1.0.4-alpha.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nekofar committed Oct 18, 2023
2 parents c5584f6 + dd5eec6 commit 299be4e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lilnouns-bots"
version = "1.0.3"
version = "1.0.4-alpha.0"
authors = ["Milad Nekofar <milad@nekofar.com>"]
edition = "2021"
description = "Our bots are designed to keep the Lil Nouns DAO community informed and engaged."
Expand Down
34 changes: 19 additions & 15 deletions src/lil_nouns/handler/farcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,16 @@ impl Handler for FarcasterHandler {

let mut proposals_casts = self
.cache
.get::<HashMap<usize, String>>("lil_nouns:proposals:casts")
.get::<HashMap<String, String>>("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(())
}
Expand All @@ -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::<HashMap<usize, String>>("lil_nouns:proposals:casts")
.get::<HashMap<String, String>>("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;

Expand All @@ -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(())
}
Expand Down
28 changes: 16 additions & 12 deletions src/meta_gov/handler/farcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) => {
Expand All @@ -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;

Expand All @@ -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);
Expand Down
32 changes: 18 additions & 14 deletions src/prop_house/handler/farcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"{}/{}/{}",
Expand Down Expand Up @@ -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(())
}

Expand All @@ -196,17 +201,18 @@ 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
.get::<HashMap<isize, String>>("prop_house: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)
.ok_or("Cast hash not found")?;

let wallet = get_wallet_handle(&vote.address, "xyz.farcaster").await;

Expand All @@ -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(())
}
Expand Down
35 changes: 17 additions & 18 deletions src/prop_lot/handler/farcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ impl Handler for FarcasterHandler {
let idea_id = idea.id;
let mut ideas_casts = self
.cache
.get::<HashMap<isize, String>>("prop_lot:ideas:casts")
.get::<HashMap<String, String>>("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;

Expand All @@ -170,17 +170,16 @@ 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
.get::<HashMap<isize, String>>("prop_lot:ideas:casts")
.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;

Expand Down Expand Up @@ -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::<HashMap<isize, String>>("prop_lot:ideas:casts")
.get::<HashMap<String, String>>("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;

Expand All @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down

0 comments on commit 299be4e

Please sign in to comment.