From 32752dcaf417ec867014e2ec4cd0efa2305afb59 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot] /ta-announce-all --- somebot/modules/TACommandAnnounceAll.py | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 somebot/modules/TACommandAnnounceAll.py diff --git a/somebot/modules/TACommandAnnounceAll.py b/somebot/modules/TACommandAnnounceAll.py new file mode 100644 index 0000000..f43c48a --- /dev/null +++ b/somebot/modules/TACommandAnnounceAll.py @@ -0,0 +1,31 @@ +# Mattermost Bot. +# Copyright (c) 2016-2020 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"]) + + 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