commit
8c60120549
@ -0,0 +1,4 @@ |
||||
/target |
||||
**/*.rs.bk |
||||
group-actor-data.toml |
||||
.idea/ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@ |
||||
[package] |
||||
name = "group" |
||||
version = "0.1.0" |
||||
authors = ["Ondřej Hruška <ondra@ondrovo.com>"] |
||||
edition = "2018" |
||||
publish = false |
||||
build = "build.rs" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
#elefren = { version = "0.22.0", features = ["toml"] } |
||||
elefren = { path = "../elefren22-fork", features = ["toml"] } |
||||
|
||||
simple-logging = "2.0.2" |
||||
#elefren = { path = "../elefren-fork" } |
||||
log = "0.4.14" |
||||
serde = "1" |
||||
serde_json = "1" |
||||
smart-default = "0.6.0" |
||||
anyhow = "1" |
||||
clap = "2.33.0" |
||||
|
||||
native-tls = "0.2.8" |
||||
websocket = "0.26.2" |
||||
|
||||
#tokio = { version = "0.2.22", features = ["full"] } |
@ -0,0 +1,12 @@ |
||||
use std::process::Command; |
||||
use std::str; |
||||
|
||||
fn main() { |
||||
let desc_c = Command::new("git").args(&["describe", "--all", "--long"]).output().unwrap(); |
||||
|
||||
let desc = unsafe { |
||||
str::from_utf8_unchecked( &desc_c.stdout ) |
||||
}; |
||||
|
||||
println!("cargo:rustc-env=GIT_REV={}", desc); |
||||
} |
@ -0,0 +1,107 @@ |
||||
#[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", ¬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"); |
||||
|
||||
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 |
||||
) |
||||
} |
Loading…
Reference in new issue