"""XMPP Stuff."""

from twisted.words.xish.domish import Element

from iembot.types import JabberClient


def route(bot: JabberClient, channels: list, elem: Element):
    """Do XMPP stuff."""
    alertedRooms = []
    for channel in channels:
        for room in bot.routingtable.get(channel, []):
            if room in alertedRooms:
                continue
            alertedRooms.append(room)
            elem["to"] = f"{room}@{bot.config['bot.mucservice']}"
            bot.send_groupchat_elem(elem)
