Skip to content

Commit

Permalink
chore: improve x bot
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jan 25, 2025
1 parent c7fd427 commit e772bb8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion agents/anda_bot/nitro_enclave/amd64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN mv linux-amd64/dnsproxy ./ && chmod +x dnsproxy
RUN wget -O ic_tee_nitro_gateway https://github.com/ldclabs/ic-tee/releases/download/v0.2.11/ic_tee_nitro_gateway
RUN chmod +x ic_tee_nitro_gateway

RUN wget -O anda_bot https://github.com/ldclabs/anda/releases/download/v0.3.1/anda_bot
RUN wget -O anda_bot https://github.com/ldclabs/anda/releases/download/v0.3.2/anda_bot
RUN chmod +x anda_bot

FROM --platform=linux/amd64 debian:bookworm-slim AS runtime
Expand Down
18 changes: 10 additions & 8 deletions agents/anda_bot/src/twitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tokio_util::sync::CancellationToken;
use crate::handler::ServiceStatus;

const MAX_HISTORY_TWEETS: i64 = 21;
const MAX_SEEN_TWEET_IDS: usize = 1000;
const MAX_SEEN_TWEET_IDS: usize = 10000;

static LOG_TARGET: &str = "twitter";

Expand Down Expand Up @@ -139,7 +139,7 @@ impl TwitterDaemon {
}
}

match rand_number(0..=5) {
match rand_number(0..=10) {
0 => {
if let Err(err) = self.handle_home_timeline().await {
log::error!(target: LOG_TARGET, "handle_home_timeline error: {err:?}");
Expand All @@ -150,7 +150,7 @@ impl TwitterDaemon {
}
}

match rand_number(0..=9) {
match rand_number(0..=20) {
0 => {
if let Err(err) = self.post_new_tweet().await {
log::error!(target: LOG_TARGET, "post_new_tweet error: {err:?}");
Expand All @@ -166,7 +166,7 @@ impl TwitterDaemon {
_ = cancel_token.cancelled() => {
return Ok(());
},
_ = sleep(Duration::from_secs(rand_number(5 * 60..=15 * 60))) => {},
_ = sleep(Duration::from_secs(rand_number(1 * 60..=5 * 60))) => {},
}
}
}
Expand Down Expand Up @@ -220,10 +220,12 @@ impl TwitterDaemon {
if seen_tweet_ids.len() >= MAX_SEEN_TWEET_IDS {
seen_tweet_ids.drain(0..MAX_SEEN_TWEET_IDS / 2);
}
let tweets = self
.scraper
.get_home_timeline(1, seen_tweet_ids.clone())
.await?;
let ids = if seen_tweet_ids.len() > 42 {
seen_tweet_ids[(seen_tweet_ids.len() - 42)..].to_vec()
} else {
seen_tweet_ids.clone()
};
let tweets = self.scraper.get_home_timeline(1, ids).await?;
log::info!(target: LOG_TARGET, "process home timeline, {} tweets", tweets.len());

let mut likes = 0;
Expand Down
Binary file added anda_ architecture.webp
Binary file not shown.
Binary file modified anda_diagram.webp
Binary file not shown.

0 comments on commit e772bb8

Please sign in to comment.