xmpp-rs/examples/client.rs

43 lines
1.6 KiB
Rust
Raw Normal View History

2017-02-18 23:01:51 +00:00
extern crate xmpp;
use xmpp::jid::Jid;
use xmpp::client::ClientBuilder;
use xmpp::plugins::stanza_debug::StanzaDebugPlugin;
use xmpp::plugins::stanza::StanzaPlugin;
2017-05-27 19:43:34 +00:00
use xmpp::plugins::unhandled_iq::UnhandledIqPlugin;
2017-02-20 15:28:51 +00:00
use xmpp::plugins::messaging::{MessagingPlugin, MessageEvent};
use xmpp::plugins::presence::{PresencePlugin, Type, Show};
2017-05-27 17:06:48 +00:00
use xmpp::plugins::disco::DiscoPlugin;
2017-05-27 19:03:59 +00:00
use xmpp::plugins::ibb::IbbPlugin;
2017-05-27 21:12:32 +00:00
use xmpp::plugins::ping::PingPlugin;
2017-05-27 16:01:01 +00:00
use xmpp::event::{Priority, Propagation};
2017-02-18 23:01:51 +00:00
use std::env;
fn main() {
let jid: Jid = env::var("JID").unwrap().parse().unwrap();
let pass = env::var("PASS").unwrap();
let mut client = ClientBuilder::new(jid.clone())
.password(pass)
.connect()
.unwrap();
if env::var("STANZA_DEBUG").is_ok() {
client.register_plugin(StanzaDebugPlugin::new());
}
client.register_plugin(StanzaPlugin::new());
2017-05-27 19:43:34 +00:00
client.register_plugin(UnhandledIqPlugin::new());
2017-02-20 15:28:51 +00:00
client.register_plugin(MessagingPlugin::new());
client.register_plugin(PresencePlugin::new());
2017-05-27 17:06:48 +00:00
client.register_plugin(DiscoPlugin::new("client", "bot", "en", "xmpp-rs"));
2017-05-27 19:03:59 +00:00
client.register_plugin(IbbPlugin::new());
client.register_plugin(PingPlugin::new());
client.plugin::<PingPlugin>().init();
client.plugin::<IbbPlugin>().init();
2017-05-27 16:01:01 +00:00
client.register_handler(Priority::Max, |e: &MessageEvent| {
println!("{:?}", e);
Propagation::Continue
});
client.plugin::<PresencePlugin>().set_presence(Type::None, Show::None, None).unwrap();
client.main().unwrap();
2017-02-18 23:01:51 +00:00
}