[somebot] /ta-announce-all <text>
authorSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
committerSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
modules/TACommandAnnounceAll.py [new file with mode: 0644]

diff --git a/modules/TACommandAnnounceAll.py b/modules/TACommandAnnounceAll.py
new file mode 100644 (file)
index 0000000..244c6f2
--- /dev/null
@@ -0,0 +1,30 @@
+# Mattermost Bot module.
+#  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+#  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": "<text>",
+             }
+    CONFIG["auto_complete_desc"] = CONFIG["description"] = "Posts <text> 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?")