golgi/examples/ssb-friends.rs

84 lines
2.4 KiB
Rust

use std::process;
use golgi::error::GolgiError;
use golgi::sbot::Sbot;
use golgi::sbot::{FriendsHops, RelationshipQuery};
async fn run() -> Result<(), GolgiError> {
let mut sbot_client = Sbot::connect(None, None).await?;
let id = sbot_client.whoami().await?;
println!("whoami: {}", id);
// test ids to follow and block
let to_follow = String::from("@5Pt3dKy2HTJ0mWuS78oIiklIX0gBz6BTfEnXsbvke9c=.ed25519");
let to_block = String::from("@7Y4nwfQmVtAilEzi5knXdS2gilW7cGKSHXdXoT086LM=.ed25519");
// follow to_follow
let response = sbot_client
.set_relationship(&to_follow, true, false)
.await?;
println!("follow_response: {:?}", response);
// block to_block
let response = sbot_client.set_relationship(&to_block, false, true).await?;
println!("follow_response: {:?}", response);
// print all users you are following
let follows = sbot_client
.friends_hops(FriendsHops {
max: 1,
start: None,
// doesnt seem like reverse does anything, currently
reverse: Some(false),
})
.await?;
println!("follows: {:?}", follows);
// print if you are following to_follow (should be true)
let mref = sbot_client
.friends_is_following(RelationshipQuery {
source: id.clone(),
dest: to_follow.clone(),
})
.await?;
println!("isfollowingmref: {}", mref);
// print if you are blocking to_block (should be true)
let mref = sbot_client
.friends_is_blocking(RelationshipQuery {
source: id.clone(),
dest: to_block.clone(),
})
.await?;
println!("isblockingmref: {}", mref);
// print if you are blocking to_follow (should be false)
let mref = sbot_client
.friends_is_blocking(RelationshipQuery {
source: id.clone(),
dest: to_follow,
})
.await?;
println!("isblockingmref(should be false): {}", mref);
// print if you are following to_block (should be false)
let mref = sbot_client
.friends_is_following(RelationshipQuery {
source: id,
dest: to_block.clone(),
})
.await?;
println!("isfollowingmref(should be false): {}", mref);
Ok(())
}
#[async_std::main]
async fn main() {
if let Err(e) = run().await {
eprintln!("Application error: {}", e);
process::exit(1);
}
}