···99STAR_THRESHOLD=1
10101111# Timeframe in hours to gate posts after a threshold is met (default 24)
1212-POST_WINDOW_HOURS=241212+POST_WINDOW_HOURS=24
1313+1414+DATABASE_URL=./stitch_counter.sqlite
1515+JETSTREAM_URL="wss://jetstream1.us-east.fire.hose.cam/subscribe"
+52-37
bot/src/main.rs
···66use atrium_api::types::{Collection, Union};
77use dotenv::dotenv;
88use logic::BotApi;
99+use rocketman::endpoints::JetstreamEndpoints;
910use rocketman::{
1011 connection::JetstreamConnection, handler, ingestion::LexiconIngestor,
1112 options::JetstreamOptions, types::event::Operation,
···7172 // Run migrations from ./migrations
7273 sqlx::migrate!("./migrations").run(&pool).await?;
73747575+ let jet_stream = match std::env::var("JETSTREAM_URL") {
7676+ Ok(url) => JetstreamEndpoints::Custom(url.into()),
7777+ Err(_) => JetstreamEndpoints::default(),
7878+ };
7479 // Configure Jetstream to listen to sh.tangled.feed.star
7580 let opts = JetstreamOptions::builder()
8181+ .ws_url(jet_stream)
7682 .wanted_collections(vec![atproto_api::sh::tangled::feed::Star::NSID.to_string()])
7783 .build();
7884···235241236242 let parsed = parse_uri(&repo_subject)?;
237243 let cloned_repo_owner = parsed.did.clone();
238238- let stars = fetch_constellation_count(&repo_subject).await?;
244244+ let stars = fetch_constellation_count(&repo_subject)
245245+ .await
246246+ .unwrap_or_else(|err| {
247247+ log::error!("Error calling constellation: {:?}", err);
248248+ 0
249249+ });
239250 let repo_record = &self
240251 .sling_shot
241252 .get_record::<atproto_api::sh::tangled::repo::RecordData>(
···269280 "https://tangled-search.bigmoves.deno.net/repo-image/{}",
270281 encoded_subject
271282 );
272272- let bytes = reqwest::get(url).await?.bytes().await?.to_vec();
273273-274274- let blob_upload = &self
275275- .bot
276276- .agent
277277- .api
278278- .com
279279- .atproto
280280- .repo
281281- .upload_blob(bytes)
282282- .await?;
283283+ log::info!("Attempting to get the picture at: {url}");
283284284284- // let rt = RichText::new_with_detect_facets(format!(
285285- // "{handle_and_repo}{description}\n⭐️ {stars} {tangled_sh_url}"
286286- // ))
287287- // .await?;
288285 let post_text =
289286 format!("{handle_and_repo}{description}\n⭐️ {stars}");
290287291291- let image = atrium_api::app::bsky::embed::images::ImageData {
292292- alt: format!(
293293- "An image showing the same text inside of the post. {post_text}"
294294- ),
295295- aspect_ratio: Some(
296296- atrium_api::app::bsky::embed::defs::AspectRatioData {
297297- height: NonZeroU64::try_from(400_u64)?,
298298- width: NonZeroU64::try_from(800_u64)?,
299299- }
300300- .into(),
301301- ),
302302- //Good lord how many clones is that
303303- image: blob_upload.clone().blob.clone(),
288288+ let response = reqwest::get(url).await?;
289289+290290+ let embed = match response.status().is_success() {
291291+ true => {
292292+ let bytes = response.bytes().await?.to_vec();
293293+ let blob_upload = &self
294294+ .bot
295295+ .agent
296296+ .api
297297+ .com
298298+ .atproto
299299+ .repo
300300+ .upload_blob(bytes)
301301+ .await?;
302302+303303+ let image = atrium_api::app::bsky::embed::images::ImageData {
304304+ alt: format!(
305305+ "An image showing the same text inside of the post. {post_text}"
306306+ ),
307307+ aspect_ratio: Some(
308308+ atrium_api::app::bsky::embed::defs::AspectRatioData {
309309+ height: NonZeroU64::try_from(400_u64)?,
310310+ width: NonZeroU64::try_from(800_u64)?,
311311+ }
312312+ .into(),
313313+ ),
314314+ //Good lord how many clones is that
315315+ image: blob_upload.clone().blob.clone(),
316316+ };
317317+ Some(atrium_api::types::Union::Refs(
318318+ RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new(
319319+ atrium_api::app::bsky::embed::images::MainData {
320320+ images: vec![image.into()],
321321+ }
322322+ .into(),
323323+ )),
324324+ ))
325325+ }
326326+ false => None,
304327 };
305305- let embed = Some(atrium_api::types::Union::Refs(
306306- RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new(
307307- atrium_api::app::bsky::embed::images::MainData {
308308- images: vec![image.into()],
309309- }
310310- .into(),
311311- )),
312312- ));
313328314329 let post = atrium_api::app::bsky::feed::post::RecordData {
315330 created_at: atrium_api::types::string::Datetime::now(),