mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
echo_bot: use xmpp-parsers to generate stanzas
This also fixes a bug where show and status were inverted while creating the presence element.
This commit is contained in:
parent
68af9d2110
commit
0ec0f3413e
2 changed files with 12 additions and 15 deletions
|
@ -17,3 +17,4 @@ sasl = "*"
|
|||
rustc-serialize = "*"
|
||||
jid = "*"
|
||||
domain = "0.2.1"
|
||||
xmpp-parsers = "0.6.0"
|
||||
|
|
|
@ -3,6 +3,7 @@ extern crate tokio_core;
|
|||
extern crate tokio_xmpp;
|
||||
extern crate jid;
|
||||
extern crate minidom;
|
||||
extern crate xmpp_parsers;
|
||||
|
||||
use std::env::args;
|
||||
use std::process::exit;
|
||||
|
@ -10,6 +11,8 @@ use tokio_core::reactor::Core;
|
|||
use futures::{Future, Stream, Sink, future};
|
||||
use tokio_xmpp::Client;
|
||||
use minidom::Element;
|
||||
use xmpp_parsers::presence::{Presence, Type as PresenceType, Show as PresenceShow};
|
||||
use xmpp_parsers::message::Message;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = args().collect();
|
||||
|
@ -80,23 +83,16 @@ fn main() {
|
|||
|
||||
// Construct a <presence/>
|
||||
fn make_presence() -> Element {
|
||||
Element::builder("presence")
|
||||
.append(Element::builder("status")
|
||||
.append("chat")
|
||||
.build())
|
||||
.append(Element::builder("show")
|
||||
.append("Echoing messages")
|
||||
.build())
|
||||
.build()
|
||||
let mut presence = Presence::new(PresenceType::None);
|
||||
presence.show = PresenceShow::Chat;
|
||||
presence.statuses.insert(String::from("en"), String::from("Echoing messages."));
|
||||
Element::from(presence)
|
||||
}
|
||||
|
||||
// Construct a chat <message/>
|
||||
fn make_reply(to: &str, body: String) -> Element {
|
||||
Element::builder("message")
|
||||
.attr("type", "chat")
|
||||
.attr("to", to)
|
||||
.append(Element::builder("body")
|
||||
.append(body)
|
||||
.build())
|
||||
.build()
|
||||
let jid = to.parse().unwrap();
|
||||
let mut message = Message::new(Some(jid));
|
||||
message.bodies.insert(String::new(), body);
|
||||
Element::from(message)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue