From b8a004f4f789edb3542119b073f34c1248f59782 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot] /ta-mod-del --- somebot/modules/TACommandModDel.py | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 somebot/modules/TACommandModDel.py diff --git a/somebot/modules/TACommandModDel.py b/somebot/modules/TACommandModDel.py new file mode 100644 index 0000000..a774505 --- /dev/null +++ b/somebot/modules/TACommandModDel.py @@ -0,0 +1,55 @@ +# Mattermost Bot. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License +# +# This command relies on the priviledged DB-Cleaner maint script. + + + +from AbstractCommand import * +class TACommandModDel(AbstractCommand): + TRIGGER = "ta-mod-del" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": " ", + } + CONFIG["auto_complete_desc"] = CONFIG["description"] = "Delete permalinked post in 24 hours. Use to explain why. Must be executed in the same channel. [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 + + msg_text = data['text'].strip().split(" ", 1) + + try: + splitpath = msg_text[0].strip().strip("/").split("/") + if splitpath[4] == "pl": + pl_post_id = splitpath[5] + except: + request.cmd_respond_text_temp("``/ta-mod-del`` failed: The first parameter is not a valid post-permalink. :(") + return + + if len(msg_text) == 1: + request.cmd_respond_text_temp("``/ta-mod-del`` failed: It seems like you did not supply any reason-text. (use --remove to disable auto-deletion) :(") + return + + if len(msg_text[1]) > 7000: + request.cmd_respond_text_temp("``/ta-mod-del`` failed: reason-text must be smaller than 7000 characters :(\nYour text is: "+str(len(msg_text[1]))+" characters long.") + return + + post = self.bot.api.get_post(pl_post_id) + if post["channel_id"] != data["channel_id"]: + request.cmd_respond_text_temp("``/ta-mod-del`` failed: must be executd in the same channel as the post. :(") + return + + att = [{"color":"#f35912", "text": "**This post was marked for deletion in 24 hours by @"+str(data["user_name"])+". Reason:**\n"+msg_text[1]}] + post["props"].update(dict({"attachments":att, "cleaner_auto_delete":"day"})) + + if msg_text[1] == "--remove": + del post["props"]["attachments"] + del post["props"]["cleaner_auto_delete"] + + self.bot.api.patch_post(splitpath[5], post["message"], post["props"]) + request.cmd_respond_text_temp("### ``Done.`` :)") -- 2.43.0