From 4e3c696308ea840545e919b065a4ba7a13a727b8 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot] /ta-delannounce --- somebot/modules/TACommandDelAnnounce.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 somebot/modules/TACommandDelAnnounce.py diff --git a/somebot/modules/TACommandDelAnnounce.py b/somebot/modules/TACommandDelAnnounce.py new file mode 100644 index 0000000..b87d156 --- /dev/null +++ b/somebot/modules/TACommandDelAnnounce.py @@ -0,0 +1,38 @@ +# Mattermost Bot. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License + + + +from AbstractCommand import * +class TACommandDelAnnounce(AbstractCommand): + TRIGGER = "ta-delete-announce" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "", + } + CONFIG["auto_complete_desc"] = CONFIG["description"] = "Delete announcement referenced by . Must be executed in the same team. [TEAM_ADMIN]" + + + def on_POST(self, request, data): + user = self.bot.api.get_team_member(data["team_id"], data["user_id"]) + if "team_admin" not in user["roles"]: + request.cmd_respond_text_temp("### You are not a Team Admin. :(") + return + + try: + splitpath = data['text'].strip().strip("/").split("/") + if splitpath[4] == "pl": + pl_post_id = splitpath[5] + except: + request.cmd_respond_text_temp("The parameter is not a valid post-permalink. :(") + return + + post = self.bot.api.get_post(pl_post_id) + channel = self.bot.api.get_channel(post["channel_id"]) + + if channel['team_id'] == data['team_id']: + self.bot.api.delete_post(splitpath[5]) + request.cmd_respond_text_temp("### ``Done.`` :)") + + else: + request.cmd_respond_text_temp("Falsches Team?") -- 2.43.0