From 3c9ffdfbcb427aba55acc7a7f569744780afbf55 Mon Sep 17 00:00:00 2001 From: Someone Date: Sat, 12 Feb 2022 00:56:45 +0100 Subject: [PATCH] modules/CommandSpoilerAdv.py --- modules/CommandSpoilerAdv.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/modules/CommandSpoilerAdv.py b/modules/CommandSpoilerAdv.py index 3e4002b..33ef2e6 100644 --- a/modules/CommandSpoilerAdv.py +++ b/modules/CommandSpoilerAdv.py @@ -17,25 +17,28 @@ class CommandSpoilerAdv(AbstractCommand): def on_POST(self, request, data): msg_text = data['text'].strip().split(" ", 1) + if len(msg_text) == 1: + request.respond_cmd_err("``/"+self.TRIGGER+"`` It seems like you did not supply any spoiler-text. (use --remove to remove)") + return + if len(msg_text[1]) > 15000: - request.cmd_respond_text_temp("``/spoiler-adv`` failed: Spoiler-text must be smaller than 15000 characters :(\nYour text is: "+str(len(msg_text[1]))+" characters long.") + request.respond_cmd_err("``/"+self.TRIGGER+"`` reason-text must be smaller than 15000 characters :(\nYour text is: "+str(len(msg_text[1]))+" characters long.") return try: splitpath = msg_text[0].strip().strip("/").split("/") if splitpath[4] == "pl": - pl_post_id = splitpath[5] + post = self.bot.api.get_post(splitpath[5]) except: - request.cmd_respond_text_temp("``/spoiler-adv`` failed: The first parameter is not a valid post permalink. :(") + request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.") return - if len(msg_text) == 1: - request.cmd_respond_text_temp("``/spoiler-adv`` failed: It seems like you did not supply any spoiler-text. (use --remove to remove a spoiler text) :(") + if post['user_id'] != data['user_id']: + request.respond_cmd_err("``/"+self.TRIGGER+"`` Is the permalinked post yours?") return - post = self.bot.api.get_post(pl_post_id) - if post['user_id'] != data['user_id']: - request.cmd_respond_text_temp("``/spoiler-adv`` failed: Is the permalinked post yours? :(") + if "cmd" in post["props"] and post["props"]["cmd"] != self.TRIGGER: + request.respond_cmd_err("``/"+self.TRIGGER+"`` The command **``/"+post["props"]["cmd"]+"``** already affects this post. Undo said command before applying this one.") return att = [{ @@ -48,13 +51,19 @@ class CommandSpoilerAdv(AbstractCommand): post["props"].update(dict({"attachments":att})) - if msg_text[1] == "--remove": + if msg_text[1] in ["--abort", "--undo", "--remove", "--clear"]: + del post["props"]["cmd"] del post["props"]["attachments"] - self.bot.api.patch_post(splitpath[5], props=post["props"]) - request.cmd_respond_text_temp("### ``Done.`` :)") +# self.bot.api.patch_post(splitpath[5], props=post["props"]) + self.bot.api.update_post(splitpath[5], message=post["message"], is_pinned=post["is_pinned"], has_reactions=post["has_reactions"], props=post["props"]) + request.respond_cmd_temp("## :white_check_mark: Success! :)") def on_POST_interactive(self, request, data): if data["context"]["action"] == "show_spoiler": - request.respond(200, {"skip_slack_parsing":True, "ephemeral_text": data["context"]["spoiler"]}) + if data["context"]["spoiler"] != "": + request.respond_interactive_temp(data["context"]["spoiler"]) + else: + request.respond_interactive_err("Post has no stored spoiler text") + -- 2.43.0