From 2ba10366f41390c4156d958b38a7b2c053aa806d Mon Sep 17 00:00:00 2001 From: s-nt-s Date: Fri, 2 Jun 2023 18:28:32 +0200 Subject: [PATCH] hacer que xmppmsg funcione con rooms --- xmppbot/xmppmsg.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xmppbot/xmppmsg.py b/xmppbot/xmppmsg.py index e8a692c..9f3eeef 100644 --- a/xmppbot/xmppmsg.py +++ b/xmppbot/xmppmsg.py @@ -8,17 +8,26 @@ class SendMsgBot(BaseBot): def __init__(self, config_path): super().__init__(config_path) + if self.config.rooms: + self.register_plugin('xep_0045') # Multi-User Chat self.messages = [] self.add_event_handler("session_start", self.start) async def start(self, event): + await self.get_roster() self.send_presence() - self.get_roster() + rooms = set(self.config.rooms).intersection(tm[0] for tm in self.messages) + + for room in rooms: + await self.xep_0045.join_muc(room, self.config.user.split("@")[0]) while self.messages: to, msg = self.messages.pop(0) + mtype = 'chat' + if to in rooms: + mtype = 'groupchat' self.send_message(mto=to, mbody=msg, - mtype='chat') + mtype=mtype) time.sleep(0.1) self.disconnect()