From 43c11d19579a4151096c07cdbf60a8415b225439 Mon Sep 17 00:00:00 2001 From: Suguivy Date: Thu, 9 Mar 2023 20:23:56 +0100 Subject: [PATCH] remaining images in bio --- src/main.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index ca8c57f..27fe623 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,9 @@ use std::collections::HashSet; -use mastodon_async::helpers::toml; // requires `features = ["toml"]` -use mastodon_async::prelude::*; +use std::process::Command; +use mastodon_async::helpers::toml; use mastodon_async::scopes; +use mastodon_async::{prelude::*, UpdateCredsRequest}; use mastodon_async::{entities::visibility::Visibility}; -use mastodon_async::{helpers::cli, Result}; +use mastodon_async::{helpers::cli}; use reqwest; use std::io::Cursor; use std::io::Write; @@ -16,7 +17,10 @@ async fn main() -> Result<()> { }; match get_next_url() { - Some(url) => post_image(&mastodon, &url).await, + Some(url) => { + post_image(&mastodon, &url).await; + update_bio(&mastodon).await; + }, None => post(&mastodon, "@Sugui@awoo.fai.st @MeDueleLaTeta@awoo.fai.st me quedé sin chicas").await }; @@ -53,6 +57,25 @@ async fn post_image(account: &Mastodon, url: &String) { .build() .unwrap(); account.new_status(status).await.unwrap(); + + +} + +async fn update_bio(account: &Mastodon) { + let binding = std::fs::read("./posted.csv").expect("File not found").iter().map(|c| *c as char).collect::(); + let posted = binding.lines().collect::>(); + let binding = std::fs::read("./urls.csv").expect("File not found").iter().map(|c| *c as char).collect::(); + let urls = binding.lines().collect::>(); + + let remaining = urls.difference(&posted).count(); + + Command::new("curl") + .args([ + "-X", "PATCH", + "https://awoo.fai.st/api/v1/accounts/update_credentials", + "-H", &format!("Authorization:Bearer {}", account.data.token), + "-d", &format!("note=Bot who posts images of sleeping girls every 6 hours.\n\n{} new images remaining", remaining), + ]).spawn().unwrap().wait().unwrap(); } async fn post(account: &Mastodon, msg: &str) { @@ -75,7 +98,7 @@ async fn fetch_url(url: String, file_name: String) -> Result<()> { async fn register() -> Result { let registration = Registration::new("https://awoo.fai.st") .client_name("sleeping-girls-bot") - .scopes(Scopes::all()) + .scopes(Scopes::write(scopes::Write::Accounts)) .build() .await?; let mastodon = cli::authenticate(registration).await?;