From ddccba0f911ad96cd656898ecabb47713b89dcfa Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] /ta-announce-all --- modules/TACommandAnnounceAll.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 modules/TACommandAnnounceAll.py diff --git a/modules/TACommandAnnounceAll.py b/modules/TACommandAnnounceAll.py new file mode 100644 index 0000000..244c6f2 --- /dev/null +++ b/modules/TACommandAnnounceAll.py @@ -0,0 +1,30 @@ +# Mattermost Bot module. +# Copyright (c) 2016-2021 by Someone (aka. Jan Vales ) +# published under MIT-License + + + +from AbstractCommand import * +class TACommandAnnounceAll(AbstractCommand): + TRIGGER = "ta-announce-all" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "", + } + CONFIG["auto_complete_desc"] = CONFIG["description"] = "Posts into every teams' announcement channel where the poster is a TA. [TEAM_ADMIN]" + + + def on_POST(self, request, data): + posted_to = "" + + for t in self.bot.api.get_teams(): + user = self.bot.api.get_team_member(t["id"], data["user_id"], exc=False) + + if "roles" in user and "team_admin" in user["roles"]: + channel = self.bot.api.get_channel_by_name(t["id"], "town-square") + self.bot.api.create_post(channel["id"], data["text"]) + posted_to += "\n+ "+t["name"] + + if posted_to != "": + request.cmd_respond_text_temp("### ``Done.`` :)\n\nPosted to:"+posted_to) + else: + request.cmd_respond_text_temp("### ``Done.`` :(\n\nDid not post anything. Are you a Team-Admin anywhere?") -- 2.43.0