use vector_sdk::{BotEvent, 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 whitelist: Vec<String> = std::env::var("VECTOR_WHITELIST")
.unwrap_or_default()
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect();
let bot = VectorBot::builder().nsec(nsec).whitelist(whitelist).build().await?;
println!("Private bot online as {}", bot.npub());
for c in bot.communities().await {
println!(" already a member of community {}", c.id());
}
bot.on_event(|bot, event| async move {
match event {
BotEvent::Invite { community_id } => {
println!("invite to {community_id} (auto-join attempted per whitelist)");
}
BotEvent::MemberJoin { channel_id, npub } if npub == bot.npub() => {
let _ = bot.channel(channel_id).send("Hello! Reporting for duty 🫡").await;
}
BotEvent::Message(msg) if !msg.is_mine() => {
let _ = msg.reply("At your service. 🛡️").await;
}
_ => {}
}
})
.await?;
Ok(())
}