]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandJoinAll.py
modules/CommandJoinAll.py
[pub/jan/mattermost-bot.git] / modules / CommandJoinAll.py
1 # Mattermost Bot module.
2 #  Copyright (c) 2016-2022 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 #  Copyright (c) 2020 by lavish <marco.squarcina@tuwien.ac.at> ("Typos" fixed)
4 #  published under MIT-License
5
6
7
8 # pylint: disable=wrong-import-position
9 from AbstractCommand import AbstractCommand
10 class CommandJoinAll(AbstractCommand):
11     TRIGGER = "join-all"
12     CONFIG = {"display_name": "somebot-command", "auto_complete": True}
13     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Join all public channels in this team. There is no undo."
14
15
16     def __init__(self, team_id, skip_chann_ids):
17         super().__init__(team_id)
18
19         self.skip_chann_ids = skip_chann_ids
20
21
22     def on_POST(self, request, data):
23         msg = ""
24         for chan in self.bot.api.get_team_channels(self.TEAM_ID):
25             if not chan["id"] in self.skip_chann_ids:
26                 self.bot.api.add_user_to_channel(chan["id"], data["user_id"])
27                 msg += "\n + ~"+chan["name"]
28
29         request.respond_cmd_temp("## :white_check_mark: Success! :)\nYou joined all the public channels in the team:\n{}\nA reload might be needed to display the updated list of channels".format(msg))