2023-09-06 07:26:03 +01:00
|
|
|
mod ai;
|
2023-08-18 20:11:49 +01:00
|
|
|
mod database;
|
|
|
|
mod frames;
|
2023-09-06 07:26:03 +01:00
|
|
|
mod profile_classifying;
|
2023-08-18 20:11:49 +01:00
|
|
|
mod streaming;
|
|
|
|
|
2023-09-06 07:26:03 +01:00
|
|
|
use crate::profile_classifying::classify_unclassified_profiles;
|
|
|
|
use ai::make_ai_client;
|
2023-08-31 08:42:56 +01:00
|
|
|
use anyhow::Result;
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
2023-08-31 14:16:28 +01:00
|
|
|
use crate::database::{
|
|
|
|
insert_post, insert_profile_if_it_doesnt_exist, make_connection_pool, ConnectionPool,
|
|
|
|
};
|
|
|
|
use crate::streaming::{start_processing_operations_with, Operation, OperationProcessor};
|
2023-08-18 20:11:49 +01:00
|
|
|
|
|
|
|
#[tokio::main]
|
2023-08-31 08:42:56 +01:00
|
|
|
async fn main() -> Result<()> {
|
|
|
|
let db_connection_pool = make_connection_pool().await?;
|
2023-09-06 07:26:03 +01:00
|
|
|
let ai_client = make_ai_client();
|
2023-08-31 08:42:56 +01:00
|
|
|
|
|
|
|
// FIXME: This struct shouldn't really exist, but I couldn't find a way to replace
|
|
|
|
// this whole nonsense with a closure, which is what this whole thing should be in
|
|
|
|
// first place.
|
2023-09-06 07:26:03 +01:00
|
|
|
let post_saver = PostSaver {
|
|
|
|
db_connection_pool: db_connection_pool.clone(),
|
|
|
|
};
|
|
|
|
|
|
|
|
tokio::try_join!(
|
|
|
|
start_processing_operations_with(post_saver),
|
|
|
|
classify_unclassified_profiles(db_connection_pool.clone(), ai_client)
|
|
|
|
)?;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-08-31 08:42:56 +01:00
|
|
|
|
|
|
|
struct PostSaver {
|
|
|
|
db_connection_pool: ConnectionPool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl OperationProcessor for PostSaver {
|
|
|
|
async fn process_operation(&self, operation: &Operation) -> Result<()> {
|
|
|
|
match operation {
|
|
|
|
Operation::CreatePost {
|
|
|
|
author_did,
|
|
|
|
cid,
|
|
|
|
uri,
|
|
|
|
languages,
|
|
|
|
text,
|
|
|
|
} => {
|
|
|
|
// TODO: Configure this via env vars
|
|
|
|
if !languages.contains("ru") {
|
2023-08-31 08:56:14 +01:00
|
|
|
return Ok(());
|
2023-08-31 08:42:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlueSky gets confused a lot about Russian vs Ukrainian, so skip posts
|
|
|
|
// that may be in Ukrainian regardless of whether Russian is in the list
|
|
|
|
// TODO: Configure this via env vars
|
|
|
|
if languages.contains("uk") {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("received insertable post from {author_did}: {text}");
|
|
|
|
|
2023-08-31 14:11:14 +01:00
|
|
|
insert_profile_if_it_doesnt_exist(&self.db_connection_pool, &author_did).await?;
|
2023-08-31 08:42:56 +01:00
|
|
|
insert_post(&self.db_connection_pool, &author_did, &cid, &uri).await?;
|
|
|
|
}
|
2023-08-31 14:11:14 +01:00
|
|
|
Operation::DeletePost { uri } => {
|
|
|
|
println!("received a post do delete: {uri}");
|
|
|
|
|
2023-08-31 08:42:56 +01:00
|
|
|
// TODO: Delete posts from db
|
|
|
|
// delete_post(&self.db_connection_pool, &uri).await?;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|