use vector_sdk::VectorBot;
#[tokio::main]
async fn main() -> vector_sdk::Result<()> {
let nsec = std::env::var("VECTOR_NSEC").expect("set VECTOR_NSEC to your bot's nsec");
let bot = VectorBot::builder().nsec(nsec).build().await?;
println!("v2 community bot online as {}", bot.npub());
if std::env::var("VECTOR_CREATE").is_ok() {
let summary = bot.core().create_community_v2("Vector v2 Demo").await?;
let id = summary.get("community_id").and_then(|v| v.as_str()).unwrap_or_default().to_string();
let community = bot.community(id);
println!("created v2 community {}", community.id());
let url = community.create_invite().await?;
println!("shareable invite link: {url}");
if let Ok(guest) = std::env::var("VECTOR_INVITE_NPUB") {
community.invite(&guest).await?;
println!("direct-invited {guest}");
}
}
bot.on_message(|_bot, msg| async move {
if msg.is_mine() {
return; }
let _ = msg.channel().typing().await;
let _ = msg.reply(&format!("v2 heard: {}", msg.text())).await;
})
.await?;
Ok(())
}