From c29e87be03d1c14a1e480cf44b08e71404599866 Mon Sep 17 00:00:00 2001 From: pep Date: Thu, 19 Dec 2024 23:58:47 +0100 Subject: [PATCH] Update xmpp dep to main (5bc94dce95) Signed-off-by: pep --- Cargo.toml | 2 +- src/bot.rs | 42 +++++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf6276e..6562de1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/bot.rs b/src/bot.rs index 7bf6951..d1a3c3f 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -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, + agent: Agent, rooms: Vec, - nickname: String, + nickname: ResourcePart, } impl XmppClient { pub fn new(jid: BareJid, password: &str, rooms: Vec, 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");