2021-08-21 20:35:01 +00:00
|
|
|
#![deny(unused_must_use)]
|
|
|
|
|
2021-08-20 20:59:19 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate smart_default;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde;
|
2021-08-21 20:35:01 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate thiserror;
|
2021-08-20 20:59:19 +00:00
|
|
|
extern crate elefren;
|
|
|
|
|
|
|
|
use elefren::entities::event::Event;
|
|
|
|
use log::LevelFilter;
|
|
|
|
use elefren::entities::notification::NotificationType;
|
|
|
|
use elefren::entities::account::Account;
|
|
|
|
use elefren::status_builder::Visibility;
|
2021-08-21 20:35:01 +00:00
|
|
|
use elefren::{Registration, Scopes, StatusBuilder, FediClient};
|
|
|
|
use tokio_stream::{Stream, StreamExt};
|
|
|
|
use elefren::scopes;
|
|
|
|
use crate::store::{NewGroupOptions, StoreOptions};
|
|
|
|
use elefren::debug::NotificationDisplay;
|
|
|
|
|
|
|
|
mod store;
|
|
|
|
mod group_handle;
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
env_logger::Builder::new()
|
|
|
|
.filter_level(LevelFilter::Debug)
|
|
|
|
.write_style(env_logger::WriteStyle::Always)
|
|
|
|
.filter_module("rustls", LevelFilter::Warn)
|
|
|
|
.filter_module("reqwest", LevelFilter::Warn)
|
|
|
|
.init();
|
|
|
|
|
|
|
|
let store = store::ConfigStore::new(StoreOptions {
|
|
|
|
store_path: "groups.json".to_string(),
|
|
|
|
save_pretty: true
|
|
|
|
}).await?;
|
|
|
|
|
|
|
|
/*
|
|
|
|
let mut new_group = store.auth_new_group(NewGroupOptions {
|
|
|
|
server: "https://botsin.space".to_string(),
|
|
|
|
acct: "betty@botsin.space".to_string()
|
|
|
|
}).await?;
|
|
|
|
// */
|
2021-08-20 20:59:19 +00:00
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
let mut groups = store.spawn_groups().await;
|
|
|
|
//groups.push(new_group);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
let mut betty = groups.remove(0);
|
|
|
|
|
|
|
|
let notifications = betty.client.notifications().await?;
|
|
|
|
let mut iter = notifications.items_iter();
|
|
|
|
|
|
|
|
let mut num = 0;
|
|
|
|
while let Some(n) = iter.next_item().await {
|
|
|
|
debug!("A notification: {}", NotificationDisplay(&n));
|
|
|
|
num += 1;
|
|
|
|
if num > 10 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-08-20 20:59:19 +00:00
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
return Ok(());
|
|
|
|
*/
|
|
|
|
|
|
|
|
let mut handles = vec![];
|
|
|
|
|
|
|
|
for mut g in groups {
|
|
|
|
handles.push(tokio::spawn(async move {
|
|
|
|
g.run().await
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
futures::future::join_all(handles).await;
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
let client = if let Ok(data) = elefren::helpers::toml::from_file("group-actor-data.toml") {
|
|
|
|
FediClient::from(data)
|
2021-08-20 20:59:19 +00:00
|
|
|
} else {
|
2021-08-21 20:35:01 +00:00
|
|
|
register().await?
|
2021-08-20 20:59:19 +00:00
|
|
|
};
|
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
let you = client.verify_credentials().await?;
|
2021-08-20 20:59:19 +00:00
|
|
|
println!("{:#?}", you);
|
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
let mut events = client.streaming_user().await?;
|
|
|
|
|
|
|
|
while let Some(event) = events.next().await {
|
2021-08-20 20:59:19 +00:00
|
|
|
match event {
|
|
|
|
Event::Update(status) => {
|
2021-08-20 22:33:06 +00:00
|
|
|
info!("Status: {:?}", status);
|
2021-08-20 20:59:19 +00:00
|
|
|
},
|
|
|
|
Event::Notification(notification) => {
|
2021-08-20 22:33:06 +00:00
|
|
|
info!("Notification: {:?}", notification.notification_type);
|
|
|
|
debug!("{:?}", notification);
|
2021-08-20 20:59:19 +00:00
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
/*
|
2021-08-20 20:59:19 +00:00
|
|
|
match notification.notification_type {
|
|
|
|
NotificationType::Mention => {
|
|
|
|
if let Some(status) = notification.status {
|
|
|
|
if status.content.contains("/gi") {
|
|
|
|
debug!("GRPIGNORE!");
|
|
|
|
} else if status.content.contains("/gb") {
|
|
|
|
debug!("GROUP BOOST PREV!");
|
|
|
|
if let Some(id) = status.in_reply_to_id {
|
|
|
|
let _ = client.reblog(&id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else if status.content.contains("/gping") {
|
|
|
|
// let post = StatusBuilder::new()
|
|
|
|
// .status(format!("@{} hello", ¬ification.account.acct))
|
|
|
|
// .content_type("text/markdown")
|
|
|
|
// //.in_reply_to(status.id)
|
|
|
|
// .visibility(Visibility::Unlisted)
|
|
|
|
// .build().expect("error build status");
|
|
|
|
//
|
|
|
|
// let _ = client.new_status(post);
|
|
|
|
// }
|
|
|
|
else {
|
|
|
|
info!("BOOSTING");
|
|
|
|
let _ = client.reblog(&status.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NotificationType::Follow => {
|
|
|
|
info!("New follower!");
|
|
|
|
|
|
|
|
let post = StatusBuilder::new()
|
|
|
|
.status(format!("@{} welcome to the group!", ¬ification.account.acct))
|
|
|
|
.content_type("text/markdown")
|
|
|
|
.visibility(Visibility::Unlisted)
|
|
|
|
.build().expect("error build status");
|
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
let _ = client.new_status(post).await;
|
2021-08-20 20:59:19 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2021-08-21 20:35:01 +00:00
|
|
|
*/
|
2021-08-20 20:59:19 +00:00
|
|
|
},
|
|
|
|
Event::Delete(id) => {
|
2021-08-20 22:33:06 +00:00
|
|
|
info!("Delete: {}", id);
|
2021-08-20 20:59:19 +00:00
|
|
|
},
|
|
|
|
Event::FiltersChanged => {
|
2021-08-20 22:33:06 +00:00
|
|
|
info!("FiltersChanged");
|
2021-08-20 20:59:19 +00:00
|
|
|
// ???
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-20 22:33:06 +00:00
|
|
|
println!("Main loop ended!");
|
|
|
|
|
2021-08-20 20:59:19 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-08-21 20:35:01 +00:00
|
|
|
/*
|
|
|
|
async fn register() -> anyhow::Result<FediClient> {
|
2021-08-20 20:59:19 +00:00
|
|
|
let registration = Registration::new("https://piggo.space")
|
|
|
|
.client_name("group-actor")
|
2021-08-21 20:35:01 +00:00
|
|
|
.force_login(true)
|
|
|
|
.scopes(
|
|
|
|
Scopes::read(scopes::Read::Accounts)
|
|
|
|
| Scopes::read(scopes::Read::Notifications)
|
|
|
|
| Scopes::read(scopes::Read::Statuses)
|
|
|
|
| Scopes::read(scopes::Read::Follows)
|
|
|
|
| Scopes::write(scopes::Write::Statuses)
|
|
|
|
| Scopes::write(scopes::Write::Media)
|
|
|
|
)
|
|
|
|
.build().await?;
|
|
|
|
let client = elefren::helpers::cli::authenticate(registration).await?;
|
|
|
|
elefren::helpers::toml::to_file(&*client, "group-actor-data.toml")?;
|
2021-08-20 20:59:19 +00:00
|
|
|
Ok(client)
|
|
|
|
}
|
2021-08-21 20:35:01 +00:00
|
|
|
*/
|