From 19a4435ff402dd9d8a2f9179872bdc40123dd832 Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] /ta-delannounce --- modules/TACommandDelAnnounce.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 modules/TACommandDelAnnounce.py diff --git a/modules/TACommandDelAnnounce.py b/modules/TACommandDelAnnounce.py new file mode 100644 index 0000000..ee877c7 --- /dev/null +++ b/modules/TACommandDelAnnounce.py @@ -0,0 +1,35 @@ +# Mattermost Bot module. +# Copyright (c) 2016-2021 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): + self._require_team_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.) + + 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