Skip to content

Commit

Permalink
hacer que xmppmsg funcione con rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
s-nt-s committed Jun 2, 2023
1 parent 3e19b1d commit 2ba1036
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions xmppbot/xmppmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 2ba1036

Please sign in to comment.