# Mattermost Bot.
#  Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
#  Copyright (c) 2020 by lavish <marco.squarcina@tuwien.ac.at> ("Typos" fixed)
#  published under MIT-License



from AbstractCommand import *
class CommandJoinAll(AbstractCommand):
    TRIGGER = "join-all"
    CONFIG = {"display_name": "somebot-command", "auto_complete": True}
    USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Join all public channels in this team. There is no undo."


    def on_POST(self, request, data):
        msg = ""
        for c in self.bot.api.get_team_channels(self.TEAM_ID):
            self.bot.api.add_user_to_channel(c["id"], data["user_id"])
            msg += "\n + ~"+c["name"]

        request.cmd_respond_text_temp("### ``Done`` :)\nYou joined all the public channels in the team:\n{}\nA reload might be needed to display the updated list of channels".format(msg))

