2 # Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # published under MIT-License
7 from AbstractCommand import *
8 class TACommandSyncAdmins(AbstractCommand):
9 TRIGGER = "ta-sync-admins"
10 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
12 CONFIG["auto_complete_desc"] = CONFIG["description"] = "Sync TAs to other managed teams. [TEAM_ADMIN]"
15 def __init__(self, team_id, managed_teams, active_admins_channel_id, additional_user_ids=[]):
16 super().__init__(team_id)
18 self.managed_teams = managed_teams
19 self.active_admins_channel_id = active_admins_channel_id
20 self.additional_user_ids=additional_user_ids
23 def on_POST(self, request, data):
24 user = self.bot.api.get_team_member(data["team_id"], data["user_id"])
25 if "team_admin" not in user["roles"]:
26 request.cmd_respond_text_temp("### You are not a Team Admin. :(")
29 all_user_ids = [u["id"] for u in self.bot.api.get_users()]
30 users_ids = [u["user_id"] for u in self.bot.api.get_channel_members(self.active_admins_channel_id)]
31 users_ids += self.additional_user_ids
33 for _, t in self.managed_teams.items():
36 self.bot.api.add_user_to_team(t[0], u)
37 self.bot.api.update_team_members_scheme_roles(t[0], u, {"scheme_user": True, "scheme_admin": True})
39 diff_uids = set(all_user_ids) - set(users_ids)
41 self.bot.api.update_team_members_scheme_roles(t[0], u, {"scheme_user": True, "scheme_admin": False})
43 request.cmd_respond_text_temp("### ``Done.`` :)")