pleroma groups!!!!!! try it -> https://piggo.space/hob
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
group-actor/src/main.rs

107 lines
3.8 KiB

#[macro_use]
extern crate log;
#[macro_use]
extern crate smart_default;
#[macro_use]
extern crate serde;
extern crate elefren;
use elefren::prelude::*;
use elefren::helpers::{cli, toml};
use elefren::entities::event::Event;
use log::LevelFilter;
use elefren::entities::notification::NotificationType;
use elefren::entities::account::Account;
use elefren::status_builder::Visibility;
fn main() -> anyhow::Result<()> {
simple_logging::log_to_stderr(LevelFilter::Debug);
let client = if let Ok(data) = toml::from_file("group-actor-data.toml") {
Mastodon::from(data)
} else {
register()?
};
let you = client.verify_credentials()?;
println!("{:#?}", you);
for event in client.streaming_user()? {
match event {
Event::Update(status) => {
debug!("Status: {:#?}", status);
},
Event::Notification(notification) => {
debug!("Notification: {:#?}", notification);
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", &notification.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!", &notification.account.acct))
.content_type("text/markdown")
.visibility(Visibility::Unlisted)
.build().expect("error build status");
let _ = client.new_status(post);
}
_ => {}
}
},
Event::Delete(id) => {
debug!("Delete: {}", id);
},
Event::FiltersChanged => {
debug!("FiltersChanged");
// ???
},
}
}
Ok(())
}
fn register() -> anyhow::Result<Mastodon> {
let registration = Registration::new("https://piggo.space")
.client_name("group-actor")
.scopes(Scopes::all())
.build()?;
let client = cli::authenticate(registration)?;
toml::to_file(&*client, "group-actor-data.toml")?;
Ok(client)
}
fn make_mention(user : &Account) -> String {
format!(r#"<span class="h-card"><a class="u-url mention" data-user="{id}" href="{url}" rel="ugc">@<span>{handle}</span></a></span>"#,
id=user.id,
url=user.url, handle=user.acct
)
}