tangled
alpha
login
or
join now
baileytownsend.dev
/
stitch_counter
13
fork
atom
tangled.org trending bluesky account
13
fork
atom
overview
issues
1
pulls
pipelines
commented out chromiumoxide stuff
baileytownsend.dev
6 months ago
874ac1de
61c636fb
+93
-53
1 changed file
expand all
collapse all
unified
split
bot
src
main.rs
+93
-53
bot/src/main.rs
···
5
5
use crate::constellation::fetch_constellation_count;
6
6
use atrium_api::app::bsky::embed::defs::AspectRatioData;
7
7
use atrium_api::app::bsky::feed::post::RecordEmbedRefs;
8
8
-
use atrium_api::types::Collection;
8
8
+
use atrium_api::app::bsky::richtext::facet::{ByteSliceData, LinkData, MainFeaturesItem};
9
9
use atrium_api::types::string::Language;
10
10
+
use atrium_api::types::{Collection, Union};
10
11
use bsky_sdk::rich_text::RichText;
11
12
use chromiumoxide::browser::{Browser, BrowserConfig, HeadlessMode};
12
13
use chromiumoxide::cdp::browser_protocol::page::{
···
110
111
let mut hbs = Handlebars::new();
111
112
let _ = hbs.register_embed_templates::<Templates>();
112
113
113
113
-
let cfg = BrowserConfig::builder()
114
114
-
.headless_mode(HeadlessMode::New)
115
115
-
.no_sandbox()
116
116
-
.build()
117
117
-
.map_err(|e| anyhow::anyhow!(e))
118
118
-
.expect("build browser config");
119
119
-
let (mut browser, mut browser_handler) = Browser::launch(cfg).await.expect("launch browser");
114
114
+
// let cfg = BrowserConfig::builder()
115
115
+
// .headless_mode(HeadlessMode::New)
116
116
+
// .no_sandbox()
117
117
+
// .build()
118
118
+
// .map_err(|e| anyhow::anyhow!(e))
119
119
+
// .expect("build browser config");
120
120
121
121
-
let handle = tokio::spawn(async move { while let Some(_) = browser_handler.next().await {} });
121
121
+
// let handle = tokio::spawn(async move { while let Some(_) = browser_handler.next().await {} });
122
122
123
123
// Ingestor for the star collection
124
124
let mut ingestors: HashMap<String, Box<dyn LexiconIngestor + Send + Sync>> = HashMap::new();
···
128
128
pool: pool.clone(),
129
129
bot: Arc::new(bot_api),
130
130
sling_shot: sling_shot.clone(),
131
131
-
browser: Arc::new(browser),
131
131
+
//Come back to this
132
132
+
// browser: Arc::new(browser),
132
133
hbs: Arc::new(hbs),
133
134
timeframe_hours,
134
135
star_threshold,
···
167
168
pool: SqlitePool,
168
169
bot: Arc<BotApi>,
169
170
sling_shot: Arc<Slingshot>,
170
170
-
browser: Arc<Browser>,
171
171
+
// browser: Arc<Browser>,
171
172
hbs: Arc<Handlebars<'static>>,
172
173
timeframe_hours: i64,
173
174
star_threshold: i64,
···
283
284
284
285
let html = &self.hbs.render("repo_header.hbs", &ctx)?;
285
286
286
286
-
let bytes =
287
287
-
render_with_chromiumoxide(&html, 336, 114, &self.browser)
288
288
-
.await?;
287
287
+
// let bytes = render_with_chromiumoxide(&html, 336, 114).await?;
289
288
290
290
-
let blob_upload = &self
291
291
-
.bot
292
292
-
.agent
293
293
-
.api
294
294
-
.com
295
295
-
.atproto
296
296
-
.repo
297
297
-
.upload_blob(bytes)
298
298
-
.await?;
289
289
+
// let blob_upload = &self
290
290
+
// .bot
291
291
+
// .agent
292
292
+
// .api
293
293
+
// .com
294
294
+
// .atproto
295
295
+
// .repo
296
296
+
// .upload_blob(bytes)
297
297
+
// .await?;
299
298
300
300
-
let rt = RichText::new_with_detect_facets(format!(
301
301
-
"{handle_and_repo}{description}\n⭐️ {stars} {tangled_sh_url}"
302
302
-
))
303
303
-
.await?;
304
304
-
let image = atrium_api::app::bsky::embed::images::ImageData{
305
305
-
alt: "An image showing the same text inside of the post. Repo name, description and how many stars. Just a plain HTML page".to_string(),
306
306
-
aspect_ratio: Some(atrium_api::app::bsky::embed::defs::AspectRatioData{
307
307
-
height: NonZeroU64::try_from(114_u64)?,
308
308
-
width: NonZeroU64::try_from(336_u64)?
309
309
-
}.into()),
310
310
-
//Good lord how many clones is that
311
311
-
image: blob_upload.clone().blob.clone(),
312
312
-
};
313
313
-
let embed = Some(atrium_api::types::Union::Refs(
314
314
-
RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new(
315
315
-
atrium_api::app::bsky::embed::images::MainData {
316
316
-
images: vec![image.into()],
317
317
-
}
318
318
-
.into(),
319
319
-
)),
320
320
-
));
299
299
+
// let rt = RichText::new_with_detect_facets(format!(
300
300
+
// "{handle_and_repo}{description}\n⭐️ {stars} {tangled_sh_url}"
301
301
+
// ))
302
302
+
// .await?;
303
303
+
let post_text =
304
304
+
format!("{handle_and_repo}{description}\n⭐️ {stars}");
305
305
+
306
306
+
// let image = atrium_api::app::bsky::embed::images::ImageData {
307
307
+
// alt: format!(
308
308
+
// "An image showing the same text inside of the post. {post_text}"
309
309
+
// ),
310
310
+
// aspect_ratio: Some(
311
311
+
// atrium_api::app::bsky::embed::defs::AspectRatioData {
312
312
+
// height: NonZeroU64::try_from(114_u64)?,
313
313
+
// width: NonZeroU64::try_from(336_u64)?,
314
314
+
// }
315
315
+
// .into(),
316
316
+
// ),
317
317
+
// //Good lord how many clones is that
318
318
+
// image: blob_upload.clone().blob.clone(),
319
319
+
// };
320
320
+
// let embed = Some(atrium_api::types::Union::Refs(
321
321
+
// RecordEmbedRefs::AppBskyEmbedImagesMain(Box::new(
322
322
+
// atrium_api::app::bsky::embed::images::MainData {
323
323
+
// images: vec![image.into()],
324
324
+
// }
325
325
+
// .into(),
326
326
+
// )),
327
327
+
// ));
321
328
322
329
let post = atrium_api::app::bsky::feed::post::RecordData {
323
330
created_at: atrium_api::types::string::Datetime::now(),
324
324
-
embed,
331
331
+
embed: None,
325
332
entities: None,
326
326
-
facets: rt.facets,
333
333
+
facets: Some(vec![
334
334
+
atrium_api::app::bsky::richtext::facet::MainData {
335
335
+
features: vec![Union::Refs(
336
336
+
MainFeaturesItem::Link(Box::new(
337
337
+
LinkData {
338
338
+
uri: tangled_sh_url,
339
339
+
}
340
340
+
.into(),
341
341
+
)),
342
342
+
)],
343
343
+
index: ByteSliceData {
344
344
+
byte_end: handle_and_repo.chars().count(),
345
345
+
byte_start: 0,
346
346
+
}
347
347
+
.into(),
348
348
+
}
349
349
+
.into(),
350
350
+
]),
327
351
labels: None,
328
352
//You don't see a thing. No unwraps
329
353
langs: Some(vec![Language::new("en".to_string()).unwrap()]),
330
354
reply: None,
331
355
tags: None,
332
332
-
text: rt.text,
356
356
+
text: post_text,
333
357
};
334
358
335
359
match self.bot.agent.create_record(post).await {
···
373
397
html: &str,
374
398
width: u32,
375
399
height: u32,
376
376
-
browser: &Browser,
377
400
) -> Result<Vec<u8>, anyhow::Error> {
378
401
// Configure and launch the browser
379
402
380
380
-
// Spawn the handler task to drive the connection
381
381
-
// let handle = tokio::spawn(async move { while let Some(_) = handler.next().await {} });
403
403
+
let cfg = BrowserConfig::builder()
404
404
+
.headless_mode(HeadlessMode::New)
405
405
+
.no_sandbox()
406
406
+
.build()
407
407
+
.map_err(|e| anyhow::anyhow!(e))
408
408
+
.expect("build browser config");
409
409
+
410
410
+
let (mut browser, mut browser_handler) = Browser::launch(cfg).await.expect("launch browser");
411
411
+
412
412
+
let handle = tokio::task::spawn(async move {
413
413
+
loop {
414
414
+
match browser_handler.next().await {
415
415
+
Some(h) => match h {
416
416
+
Ok(_) => continue,
417
417
+
Err(_) => break,
418
418
+
},
419
419
+
None => break,
420
420
+
}
421
421
+
}
422
422
+
});
382
423
383
424
let page = browser.new_page("about:blank").await?;
384
425
···
405
446
406
447
// Close
407
448
page.close().await.ok();
408
408
-
// browser.close().await.ok();
449
449
+
browser.close().await.ok();
409
450
// stop handler task
410
410
-
// handle.abort();
411
411
-
451
451
+
handle.await?;
412
452
Ok(png_bytes)
413
453
}