Add methods for invites
This commit is contained in:
parent
f54e4c47b0
commit
18667084ad
|
@ -0,0 +1,32 @@
|
|||
use async_std::stream::StreamExt;
|
||||
use futures::pin_mut;
|
||||
use std::process;
|
||||
|
||||
use golgi::error::GolgiError;
|
||||
use golgi::messages::SsbMessageContent;
|
||||
use golgi::sbot::Sbot;
|
||||
use golgi::sbot::{FriendsHopsOpts, SubsetQuery, SubsetQueryOptions};
|
||||
|
||||
async fn run() -> Result<(), GolgiError> {
|
||||
let mut sbot_client = Sbot::init(None, None).await?;
|
||||
|
||||
let id = sbot_client.whoami().await?;
|
||||
println!("whoami: {}", id);
|
||||
|
||||
let invite_link = sbot_client.invite_create(100).await?;
|
||||
println!("invite: {:?}", invite_link);
|
||||
|
||||
let test_invite = "net:ssbroom2.commoninternet.net:8009~shs:wm8a1zHWjtESv4XSKMWU/rPRhnAoAiSAe4hQSY0UF5A=";
|
||||
let mref = sbot_client.invite_use(test_invite).await?;
|
||||
println!("mref: {:?}", mref);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
if let Err(e) = run().await {
|
||||
eprintln!("Application error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
38
src/sbot.rs
38
src/sbot.rs
|
@ -314,6 +314,44 @@ impl Sbot {
|
|||
.await
|
||||
}
|
||||
|
||||
/// Call the `invite create` RPC method and return the created invite
|
||||
pub async fn invite_create(
|
||||
&mut self,
|
||||
uses: i32,
|
||||
) -> Result<String, GolgiError> {
|
||||
let mut sbot_connection = self.get_sbot_connection().await?;
|
||||
let req_id = sbot_connection
|
||||
.client
|
||||
.invite_create_req_send(uses)
|
||||
.await?;
|
||||
|
||||
utils::get_async(
|
||||
&mut sbot_connection.rpc_reader,
|
||||
req_id,
|
||||
utils::string_res_parse,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Call the `invite use` RPC method and return a reference to the message.
|
||||
pub async fn invite_use(
|
||||
&mut self,
|
||||
invite_link: &str,
|
||||
) -> Result<String, GolgiError> {
|
||||
let mut sbot_connection = self.get_sbot_connection().await?;
|
||||
let req_id = sbot_connection
|
||||
.client
|
||||
.invite_use_req_send(invite_link)
|
||||
.await?;
|
||||
|
||||
utils::get_async(
|
||||
&mut sbot_connection.rpc_reader,
|
||||
req_id,
|
||||
utils::string_res_parse,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Wrapper for publish which constructs and publishes a post message appropriately from a string.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
Loading…
Reference in New Issue