2 # Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # published under MIT-License
5 # This command relies on the priviledged DB-Cleaner maint script.
9 from AbstractCommand import *
10 class TACommandModDel(AbstractCommand):
11 TRIGGER = "ta-mod-del"
12 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
13 "auto_complete_hint": "<permalink> <reason>",
15 CONFIG["auto_complete_desc"] = CONFIG["description"] = "Delete permalinked post in 24 hours. Use <reason> to explain why. Must be executed in the same channel. [TEAM_ADMIN]"
18 def on_POST(self, request, data):
19 user = self.bot.api.get_team_member(data["team_id"], data["user_id"])
20 if "team_admin" not in user["roles"]:
21 request.cmd_respond_text_temp("### You are not a Team Admin. :(")
24 msg_text = data['text'].strip().split(" ", 1)
27 splitpath = msg_text[0].strip().strip("/").split("/")
28 if splitpath[4] == "pl":
29 pl_post_id = splitpath[5]
31 request.cmd_respond_text_temp("``/ta-mod-del`` failed: The first parameter is not a valid post-permalink. :(")
34 if len(msg_text) == 1:
35 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) :(")
38 if len(msg_text[1]) > 7000:
39 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.")
42 post = self.bot.api.get_post(pl_post_id)
43 if post["channel_id"] != data["channel_id"]:
44 request.cmd_respond_text_temp("``/ta-mod-del`` failed: must be executd in the same channel as the post. :(")
47 att = [{"color":"#f35912", "text": "**This post was marked for deletion in 24 hours by @"+str(data["user_name"])+". Reason:**\n"+msg_text[1]}]
48 post["props"].update(dict({"attachments":att, "cleaner_auto_delete":"day"}))
50 if msg_text[1] == "--remove":
51 del post["props"]["attachments"]
52 del post["props"]["cleaner_auto_delete"]
54 self.bot.api.patch_post(splitpath[5], post["message"], post["props"])
55 request.cmd_respond_text_temp("### ``Done.`` :)")