mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-21 04:51:17 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
89aec3e0ed | ||
![]() |
6a7eef757a | ||
![]() |
f46f90ad34 | ||
![]() |
4b4f9abe2f |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1283,7 +1283,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oolatoocs"
|
name = "oolatoocs"
|
||||||
version = "3.0.1"
|
version = "3.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atrium-api",
|
"atrium-api",
|
||||||
"bsky-sdk",
|
"bsky-sdk",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "oolatoocs"
|
name = "oolatoocs"
|
||||||
version = "3.0.1"
|
version = "3.0.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
13
src/bsky.rs
13
src/bsky.rs
@@ -16,13 +16,6 @@ pub struct BskyReply {
|
|||||||
pub root_record_uri: String,
|
pub root_record_uri: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_session(user: &str, pass: &str) -> Result<BskyAgent, Box<dyn Error>> {
|
|
||||||
let agent = BskyAgent::builder().build().await?;
|
|
||||||
agent.login(user, pass).await?;
|
|
||||||
|
|
||||||
Ok(agent)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn build_post_record(
|
pub async fn build_post_record(
|
||||||
config: &BlueskyConfig,
|
config: &BlueskyConfig,
|
||||||
text: &str,
|
text: &str,
|
||||||
@@ -38,12 +31,14 @@ pub async fn build_post_record(
|
|||||||
|
|
||||||
while let Some(found) = re.captures(&rt.text.clone()) {
|
while let Some(found) = re.captures(&rt.text.clone()) {
|
||||||
if let Some(group) = found.get(3) {
|
if let Some(group) = found.get(3) {
|
||||||
|
if !group.is_empty() {
|
||||||
rt.insert(group.start(), insert_chars);
|
rt.insert(group.start(), insert_chars);
|
||||||
rt.delete(
|
rt.delete(
|
||||||
group.start() + insert_chars.len(),
|
group.start() + insert_chars.len(),
|
||||||
group.start() + insert_chars.len() + group.len(),
|
group.start() + insert_chars.len() + group.len(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if let Some(group) = found.get(1) {
|
if let Some(group) = found.get(1) {
|
||||||
rt.delete(group.start(), group.start() + group.len());
|
rt.delete(group.start(), group.start() + group.len());
|
||||||
}
|
}
|
||||||
@@ -195,8 +190,8 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_build_post_record() {
|
async fn test_build_post_record() {
|
||||||
let text = "@factornews@piaille.fr Retrouvez-nous ici https://www.nintendojo.fr/articles/editos/le-mod-renovation-de-8bitdo-pour-manette-n64 et là https://www.nintendojo.fr/articles/analyses/vite-vu/vite-vu-morbid-the-lords-of-ire";
|
let text = "@factornews@piaille.fr Retrouvez-nous ici https://www.nintendojo.fr/articles/editos/le-mod-renovation-de-8bitdo-pour-manette-n64 et là https://www.nintendojo.fr/articles/analyses/vite-vu/vite-vu-morbid-the-lords-of-ire et un lien très court http://vsl.ie/TaMere";
|
||||||
let expected_text = "@factornews@piaille.fr Retrouvez-nous ici www.nintendojo.fr/articles… et là www.nintendojo.fr/articles…";
|
let expected_text = "@factornews@piaille.fr Retrouvez-nous ici www.nintendojo.fr/articles… et là www.nintendojo.fr/articles… et un lien très court vsl.ie/TaMere";
|
||||||
|
|
||||||
let bsky_conf = BlueskyConfig {
|
let bsky_conf = BlueskyConfig {
|
||||||
handle: "tamerelol.bsky.social".to_string(),
|
handle: "tamerelol.bsky.social".to_string(),
|
||||||
|
23
src/lib.rs
23
src/lib.rs
@@ -1,3 +1,4 @@
|
|||||||
|
use bsky_sdk::BskyAgent;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
@@ -21,7 +22,7 @@ mod twitter;
|
|||||||
use twitter::{delete_tweet, generate_media_ids, post_tweet, transform_poll};
|
use twitter::{delete_tweet, generate_media_ids, post_tweet, transform_poll};
|
||||||
|
|
||||||
mod bsky;
|
mod bsky;
|
||||||
use bsky::{build_post_record, generate_media_records, get_session, BskyReply};
|
use bsky::{build_post_record, generate_media_records, BskyReply};
|
||||||
|
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
@@ -32,9 +33,10 @@ pub async fn run(config: &Config) {
|
|||||||
|
|
||||||
let mastodon = get_mastodon_instance(&config.mastodon);
|
let mastodon = get_mastodon_instance(&config.mastodon);
|
||||||
|
|
||||||
let bluesky = get_session(&config.bluesky.handle, &config.bluesky.password)
|
let bluesky = BskyAgent::builder()
|
||||||
|
.build()
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| panic!("Cannot connect to Bsky: {}", e));
|
.unwrap_or_else(|e| panic!("Can’t build Bsky Agent: {}", e));
|
||||||
|
|
||||||
let last_entry =
|
let last_entry =
|
||||||
read_state(&conn, None).unwrap_or_else(|e| panic!("Cannot get last toot id: {}", e));
|
read_state(&conn, None).unwrap_or_else(|e| panic!("Cannot get last toot id: {}", e));
|
||||||
@@ -62,6 +64,13 @@ pub async fn run(config: &Config) {
|
|||||||
panic!("Cannot delete Tweet ID ({}): {}", t.tweet_id, e)
|
panic!("Cannot delete Tweet ID ({}): {}", t.tweet_id, e)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("Create Bsky session prior to deletion");
|
||||||
|
bluesky
|
||||||
|
.login(&config.bluesky.handle, &config.bluesky.password)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|e| panic!("Cannot login to Bsky: {}", e));
|
||||||
|
|
||||||
for local_record_uri in local_record_uris.into_iter() {
|
for local_record_uri in local_record_uris.into_iter() {
|
||||||
bluesky
|
bluesky
|
||||||
.delete_record(&local_record_uri)
|
.delete_record(&local_record_uri)
|
||||||
@@ -99,6 +108,14 @@ pub async fn run(config: &Config) {
|
|||||||
continue; // skip in case we can’t strip something
|
continue; // skip in case we can’t strip something
|
||||||
};
|
};
|
||||||
|
|
||||||
|
debug!("Now we need a valid Bsky session, creating it");
|
||||||
|
if bluesky.api.com.atproto.server.get_session().await.is_err() {
|
||||||
|
bluesky
|
||||||
|
.login(&config.bluesky.handle, &config.bluesky.password)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|e| panic!("Cannot login to Bsky: {}", e));
|
||||||
|
}
|
||||||
|
|
||||||
// threads if necessary
|
// threads if necessary
|
||||||
let (mut tweet_reply_to, mut record_reply_to) = toot
|
let (mut tweet_reply_to, mut record_reply_to) = toot
|
||||||
.in_reply_to_id
|
.in_reply_to_id
|
||||||
|
Reference in New Issue
Block a user