Update xmpp dep to main (5bc94dce95)

Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
pep 2024-12-19 23:58:47 +01:00
parent 161c259dee
commit c29e87be03
2 changed files with 24 additions and 20 deletions

View file

@ -20,7 +20,7 @@ pretty_env_logger = "0.5"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
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"
sha2 = "0.10"
hex = "0.4"

View file

@ -16,25 +16,29 @@
use crate::hooks::{format_hook, Hook};
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::tokio_xmpp::connect::StartTlsServerConnector;
use xmpp::{Agent, ClientBuilder, ClientFeature, ClientType, Event};
use tokio::sync::mpsc;
use xmpp::{
message::send::RawMessageSettings, muc::room::JoinRoomSettings, Agent, ClientBuilder,
ClientFeature, ClientType, Event, RoomNick,
};
pub struct XmppClient {
is_online: bool,
agent: Agent<StartTlsServerConnector>,
agent: Agent,
rooms: Vec<BareJid>,
nickname: String,
nickname: ResourcePart,
}
impl 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)
.set_client(ClientType::Bot, "xmpp-rs")
.set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
.set_default_nick("bot")
.set_default_nick(&nickname)
.enable_feature(ClientFeature::JoinRooms)
.build();
@ -55,13 +59,12 @@ impl XmppClient {
for room in &self.rooms {
self.agent
.join_room(
room.clone(),
Some(self.nickname.clone()),
None,
"en",
"Hi there!",
)
.join_room(JoinRoomSettings {
room: room.clone(),
nick: Some(RoomNick::from_resource_ref(self.nickname.as_ref())),
password: None,
status: Some(("en", "Hi there!")),
})
.await
}
}
@ -96,12 +99,13 @@ impl XmppClient {
debug!("Hook: {}", display);
for room in &self.rooms {
self.agent
.send_message(
Jid::from(room.clone()),
MessageType::Groupchat,
"en",
&display,
)
.send_raw_message(RawMessageSettings {
recipient: Jid::from(room.clone()),
message_type: MessageType::Groupchat,
message: &display,
lang: Some("en"),
payloads: Vec::new(),
})
.await
}
debug!("XMPP Bot Processed Hook");