mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
feat: use megalodon instead of elefren
This commit is contained in:
32
src/lib.rs
32
src/lib.rs
@@ -19,10 +19,11 @@ mod state;
|
||||
pub use state::{init_db, migrate_db};
|
||||
use state::{read_state, write_state, TweetToToot};
|
||||
|
||||
use elefren::{prelude::*, status_builder::StatusBuilder, Language};
|
||||
use futures::StreamExt;
|
||||
use html_escape::decode_html_entities;
|
||||
use isolang::Language;
|
||||
use log::info;
|
||||
use megalodon::{megalodon::PostStatusInputOptions, Megalodon};
|
||||
use regex::Regex;
|
||||
use rusqlite::Connection;
|
||||
use std::sync::Arc;
|
||||
@@ -170,9 +171,21 @@ pub async fn run(config: Config) {
|
||||
|
||||
info!("Building corresponding Mastodon status");
|
||||
|
||||
let mut status_builder = StatusBuilder::new();
|
||||
let mut post_status = PostStatusInputOptions {
|
||||
media_ids: None,
|
||||
poll: None,
|
||||
in_reply_to_id: None,
|
||||
sensitive: None,
|
||||
spoiler_text: None,
|
||||
visibility: None,
|
||||
scheduled_at: None,
|
||||
language: None,
|
||||
quote_id: None,
|
||||
};
|
||||
|
||||
status_builder.status(status_text).media_ids(status_medias);
|
||||
if !status_medias.is_empty() {
|
||||
post_status.media_ids = Some(status_medias);
|
||||
}
|
||||
|
||||
// thread if necessary
|
||||
if tweet.in_reply_to_user_id.is_some() {
|
||||
@@ -182,7 +195,7 @@ pub async fn run(config: Config) {
|
||||
&mastodon_config.twitter_screen_name,
|
||||
tweet.in_reply_to_status_id,
|
||||
) {
|
||||
status_builder.in_reply_to(&r.toot_id);
|
||||
post_status.in_reply_to_id = Some(r.toot_id.to_owned());
|
||||
}
|
||||
drop(lconn);
|
||||
}
|
||||
@@ -190,16 +203,17 @@ pub async fn run(config: Config) {
|
||||
// language if any
|
||||
if let Some(l) = &tweet.lang {
|
||||
if let Some(r) = Language::from_639_1(l) {
|
||||
status_builder.language(r);
|
||||
post_status.language = Some(r.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// can be activated for test purposes
|
||||
// status_builder.visibility(elefren::status_builder::Visibility::Private);
|
||||
// post_status.visibility = Some(megalodon::entities::StatusVisibility::Direct);
|
||||
|
||||
let status = status_builder.build()?;
|
||||
|
||||
let published_status = mastodon.new_status(status)?;
|
||||
let published_status = mastodon
|
||||
.post_status(status_text, Some(&post_status))
|
||||
.await?
|
||||
.json();
|
||||
// this will return if it cannot publish the status preventing the last_tweet from
|
||||
// being written into db
|
||||
|
||||
|
Reference in New Issue
Block a user