Update xmpp dep to main (5bc94dce95)
Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
161c259dee
commit
c29e87be03
2 changed files with 24 additions and 20 deletions
|
@ -20,7 +20,7 @@ pretty_env_logger = "0.5"
|
||||||
serde = { version = "1.0", features = [ "derive" ] }
|
serde = { version = "1.0", features = [ "derive" ] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
xmpp = { git = "https://gitlab.com/xmpp-rs/xmpp-rs", rev = "274baaef9afb", default-features = false, features = [ "serde", "starttls-native"] }
|
xmpp = { git = "https://gitlab.com/xmpp-rs/xmpp-rs", rev = "5bc94dce95", default-features = false, features = [ "serde", "starttls-native"] }
|
||||||
hmac = "0.12"
|
hmac = "0.12"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
|
|
42
src/bot.rs
42
src/bot.rs
|
@ -16,25 +16,29 @@
|
||||||
use crate::hooks::{format_hook, Hook};
|
use crate::hooks::{format_hook, Hook};
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use xmpp::jid::{BareJid, Jid};
|
use tokio::sync::mpsc;
|
||||||
|
use xmpp::jid::{BareJid, Jid, ResourcePart};
|
||||||
use xmpp::parsers::message::MessageType;
|
use xmpp::parsers::message::MessageType;
|
||||||
use xmpp::tokio_xmpp::connect::StartTlsServerConnector;
|
use xmpp::tokio_xmpp::connect::StartTlsServerConnector;
|
||||||
use xmpp::{Agent, ClientBuilder, ClientFeature, ClientType, Event};
|
use xmpp::{
|
||||||
use tokio::sync::mpsc;
|
message::send::RawMessageSettings, muc::room::JoinRoomSettings, Agent, ClientBuilder,
|
||||||
|
ClientFeature, ClientType, Event, RoomNick,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct XmppClient {
|
pub struct XmppClient {
|
||||||
is_online: bool,
|
is_online: bool,
|
||||||
agent: Agent<StartTlsServerConnector>,
|
agent: Agent,
|
||||||
rooms: Vec<BareJid>,
|
rooms: Vec<BareJid>,
|
||||||
nickname: String,
|
nickname: ResourcePart,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XmppClient {
|
impl XmppClient {
|
||||||
pub fn new(jid: BareJid, password: &str, rooms: Vec<BareJid>, nickname: String) -> XmppClient {
|
pub fn new(jid: BareJid, password: &str, rooms: Vec<BareJid>, nickname: String) -> XmppClient {
|
||||||
|
let nickname: ResourcePart = ResourcePart::new(&nickname).unwrap().into();
|
||||||
let agent = ClientBuilder::new(jid, password)
|
let agent = ClientBuilder::new(jid, password)
|
||||||
.set_client(ClientType::Bot, "xmpp-rs")
|
.set_client(ClientType::Bot, "xmpp-rs")
|
||||||
.set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
|
.set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
|
||||||
.set_default_nick("bot")
|
.set_default_nick(&nickname)
|
||||||
.enable_feature(ClientFeature::JoinRooms)
|
.enable_feature(ClientFeature::JoinRooms)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -55,13 +59,12 @@ impl XmppClient {
|
||||||
|
|
||||||
for room in &self.rooms {
|
for room in &self.rooms {
|
||||||
self.agent
|
self.agent
|
||||||
.join_room(
|
.join_room(JoinRoomSettings {
|
||||||
room.clone(),
|
room: room.clone(),
|
||||||
Some(self.nickname.clone()),
|
nick: Some(RoomNick::from_resource_ref(self.nickname.as_ref())),
|
||||||
None,
|
password: None,
|
||||||
"en",
|
status: Some(("en", "Hi there!")),
|
||||||
"Hi there!",
|
})
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,12 +99,13 @@ impl XmppClient {
|
||||||
debug!("Hook: {}", display);
|
debug!("Hook: {}", display);
|
||||||
for room in &self.rooms {
|
for room in &self.rooms {
|
||||||
self.agent
|
self.agent
|
||||||
.send_message(
|
.send_raw_message(RawMessageSettings {
|
||||||
Jid::from(room.clone()),
|
recipient: Jid::from(room.clone()),
|
||||||
MessageType::Groupchat,
|
message_type: MessageType::Groupchat,
|
||||||
"en",
|
message: &display,
|
||||||
&display,
|
lang: Some("en"),
|
||||||
)
|
payloads: Vec::new(),
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
debug!("XMPP Bot Processed Hook");
|
debug!("XMPP Bot Processed Hook");
|
||||||
|
|
Loading…
Reference in a new issue