Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-alpha.42'
Browse files Browse the repository at this point in the history
  • Loading branch information
nekofar committed Oct 5, 2023
2 parents 8c2e6c2 + f1896d6 commit 39ecae1
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 86 deletions.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
# Change these settings to your own preference
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Specific for Makefiles
[Makefile]
indent_style = tab
indent_size = 2

# Specific for Rust files
[*.rs]
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:

# Generate a changelog for the new release using Git
- name: Generate a changelog
uses: orhun/git-cliff-action@v2.1.0
uses: orhun/git-cliff-action@v2.1.1
id: git-cliff
with:
config: cliff.toml # The configuration file for git-cliff
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
override: true

- name: Deploy to Workers
uses: cloudflare/wrangler-action@v3.1.1
uses: cloudflare/wrangler-action@v3.2.0
with:
accountId: ${{ secrets.CF_ACCOUNT_ID }}
apiToken: ${{ secrets.CF_API_TOKEN }}
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to this project will be documented in this file.

## [1.0.0-alpha.42] - 2023-10-05

### Features

- Add link generation utility

### Refactor

- Move panic hook configuration to utils module
- Improve error handling in link generator
- Add `Link` utils to `FarcasterHandler` for Prop Lot URL generation.
- Update discord and farcaster event descriptions for prop lot
- Update vote and proposal message format and add Link utility support

### Miscellaneous Tasks

- Add `.editorconfig` for coding consistency

## [1.0.0-alpha.41] - 2023-09-29

### Refactor
Expand Down
36 changes: 29 additions & 7 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lilnouns-bots"
version = "1.0.0-alpha.41"
version = "1.0.0-alpha.42"
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 Expand Up @@ -30,8 +30,8 @@ ethers = { version = "2.0.10", default-features = false }
getrandom = { version = "0.2.10", features = ["js"] }
graphql_client = { version = "0.13.0", features = ["reqwest"] }
log = "0.4.20"
regex = "1.9.5"
reqwest = "0.11.20"
regex = "1.9.6"
reqwest = "0.11.22"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
worker = "0.0.18"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"dev": "wrangler dev --env dev --test-scheduled"
},
"devDependencies": {
"wrangler": "3.10.0"
"wrangler": "3.10.1"
}
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

20 changes: 6 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cfg_if::cfg_if;
use log::{error, info, Level};
use worker::{event, Env, Result, ScheduleContext, ScheduledEvent};

Expand All @@ -10,16 +9,6 @@ mod prop_house;
mod prop_lot;
mod utils;

cfg_if! {
// https://github.com/rustwasm/console_error_panic_hook#readme
if #[cfg(feature = "console_error_panic_hook")] {
pub use console_error_panic_hook::set_once as set_panic_hook;
} else {
#[inline]
pub fn set_panic_hook() {}
}
}

async fn start(env: &Env) -> Result<()> {
if env.var("META_GOV_ENABLED").unwrap().to_string() == "true" {
match MetaGov::new_from_env(env) {
Expand Down Expand Up @@ -57,11 +46,14 @@ async fn start(env: &Env) -> Result<()> {
Ok(())
}

#[event(scheduled)]
async fn cron(_event: ScheduledEvent, env: Env, _ctx: ScheduleContext) {
#[event(start)]
pub fn start() {
worker_logger::init_with_level(&Level::Debug);
set_panic_hook();
utils::set_panic_hook();
}

#[event(scheduled)]
async fn cron(_event: ScheduledEvent, env: Env, _ctx: ScheduleContext) {
match start(&env).await {
Ok(_) => info!("Operation was a success."),
Err(e) => error!("An error occurred: {:?}", e),
Expand Down
28 changes: 21 additions & 7 deletions src/meta_gov/handler/farcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
fetcher::{Proposal, Vote},
handler::Handler,
},
utils::ens::get_wallet_handle,
utils::{ens::get_wallet_handle, link::Link},
};

pub struct FarcasterHandler {
Expand All @@ -23,6 +23,7 @@ pub struct FarcasterHandler {
channel_key: String,
cache: Cache,
client: Client,
link: Link,
}

impl FarcasterHandler {
Expand All @@ -32,13 +33,15 @@ impl FarcasterHandler {
channel_key: String,
cache: Cache,
client: Client,
link: Link,
) -> Self {
Self {
base_url,
bearer_token,
channel_key,
cache,
client,
link,
}
}

Expand All @@ -49,13 +52,15 @@ impl FarcasterHandler {

let cache = Cache::new_from_env(env);
let client = Client::new();
let link = Link::new_from_env(&env);

Ok(Self::new(
base_url,
bearer_token,
channel_key,
cache,
client,
link,
))
}

Expand Down Expand Up @@ -117,7 +122,12 @@ impl Handler for FarcasterHandler {
Ok((proposal_id, proposal_title)) => {
info!("Handling new proposal: {}", proposal_title);

let url = format!("{}/{}", self.base_url, proposal_id);
let url = &self
.link
.generate(format!("{}/{}", self.base_url, proposal_id))
.await
.unwrap_or_else(|_| format!("{}/{}", self.base_url, proposal_id));

let description = format!(
"A new Meta Gov proposal has been created: “{}”",
proposal_title
Expand Down Expand Up @@ -156,20 +166,24 @@ impl Handler for FarcasterHandler {

match self.extract_proposal_info(proposal.clone()).await {
Ok((proposal_id, proposal_title)) => {
let url = format!("{}/{}", self.base_url, proposal_id);
let url = &self
.link
.generate(format!("{}/{}", self.base_url, proposal_id))
.await
.unwrap_or_else(|_| format!("{}/{}", self.base_url, proposal_id));

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

let description = format!(
"“{}” voted {} by {}.",
proposal_title.to_uppercase(),
"{} has voted {} “{}” proposal.",
wallet,
match vote.choice {
1 => "for",
2 => "against",
3 => "abstain",
3 => "abstain on",
_ => "unknown",
},
wallet,
proposal_title
);

let request_data = json!({
Expand Down
6 changes: 3 additions & 3 deletions src/prop_house/handler/farcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ impl Handler for FarcasterHandler {
let wallet = get_wallet_handle(&vote.address, "xyz.farcaster").await;

let description = format!(
"“{}” voted {} by {}.",
proposal.title.to_uppercase(),
"{} has voted {} “{}” proposal.",
wallet,
match vote.direction {
1 => "for",
_ => "against",
},
wallet,
proposal.title
);

let request_data = json!({
Expand Down
Loading

0 comments on commit 39ecae1

Please sign in to comment.