tangled.org trending bluesky account
12
fork

Configure Feed

Select the types of activity you want to include in your feed.

wip

+29 -2
+29 -2
bot/src/main.rs
··· 46 46 .and_then(|v| v.parse::<i64>().ok()) 47 47 .filter(|v| *v > 0) 48 48 .unwrap_or(10); 49 + let post_window_hours: i64 = std::env::var("POST_WINDOW_HOURS") 50 + .ok() 51 + .and_then(|v| v.parse::<i64>().ok()) 52 + .filter(|v| *v > 0) 53 + .unwrap_or(24); 49 54 50 55 // Ingestor for the star collection 51 56 let mut ingestors: HashMap<String, Box<dyn LexiconIngestor + Send + Sync>> = HashMap::new(); 52 57 ingestors.insert( 53 58 atproto_api::sh::tangled::feed::Star::NSID.to_string(), 54 - Box::new(StarIngestor { pool: pool.clone(), timeframe_hours, star_threshold }), 59 + Box::new(StarIngestor { pool: pool.clone(), timeframe_hours, star_threshold, post_window_hours }), 55 60 ); 56 61 let ingestors = Arc::new(ingestors); 57 62 ··· 75 80 pool: SqlitePool, 76 81 timeframe_hours: i64, 77 82 star_threshold: i64, 83 + post_window_hours: i64, 78 84 } 79 85 80 86 #[async_trait::async_trait] ··· 108 114 .await?; 109 115 110 116 if count_in_window >= self.star_threshold { 111 - println!( 117 + log::info!( 112 118 "Star threshold met: {} stars in the last {} hour(s) (threshold: {})", 113 119 count_in_window, self.timeframe_hours, self.star_threshold 114 120 ); 121 + 122 + // Check if a post was made within the last post_window_hours 123 + let post_offset = format!("-{} hours", self.post_window_hours); 124 + let (posts_in_window,): (i64,) = sqlx::query_as( 125 + "SELECT COUNT(*) as cnt FROM posts_made WHERE createdAt >= strftime('%Y-%m-%dT%H:%M:%fZ','now', ?)" 126 + ) 127 + .bind(&post_offset) 128 + .fetch_one(&self.pool) 129 + .await?; 130 + 131 + if posts_in_window == 0 { 132 + // Insert a new record to mark that we've posted 133 + let _ = sqlx::query( 134 + "INSERT INTO posts_made(createdAt, subject) VALUES(strftime('%Y-%m-%dT%H:%M:%fZ','now'), ?)" 135 + ) 136 + .bind(&rec.subject) 137 + .execute(&self.pool) 138 + .await?; 139 + 140 + log::info!("Threshold met and allowed to be posted"); 141 + } 115 142 } 116 143 } 117 144 }