From 03385af397fe0338e84072d2633f343bd67fabf3 Mon Sep 17 00:00:00 2001 From: Someone Date: Thu, 6 Jan 2022 22:21:03 +0100 Subject: [PATCH] modules/DialogManagedReport.py --- modules/DialogManagedReport.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/DialogManagedReport.py b/modules/DialogManagedReport.py index 7e71dd4..2f35ae4 100644 --- a/modules/DialogManagedReport.py +++ b/modules/DialogManagedReport.py @@ -28,22 +28,29 @@ class DialogManagedReport(AbstractCommand): def on_POST(self, request, data): msg_text = data['text'].strip().split(" ", 1) + pl_post_id = "--invalid--" try: splitpath = msg_text[0].strip().strip("/").split("/") if splitpath[4] == "pl": pl_post_id = splitpath[5] + else: + request.respond_err_temp("``/"+self.TRIGGER+"`` failed: The first parameter is not a valid post-permalink. :(") + return + except: - request.cmd_respond_text_temp("``/"+self.TRIGGER+"`` failed: The first parameter is not a valid post-permalink. :(") + request.respond_err_temp("``/"+self.TRIGGER+"`` failed: The first parameter is not a valid post-permalink. :(") return + post = self.bot.api.get_post(pl_post_id, exc=False) + if "status_code" in post and post["status_code"] == 404: - request.cmd_respond_text_temp("``/"+self.TRIGGER+"`` failed: The perma-linked post doesnt seem to exist. Was it deleted?") + request.respond_err_temp("``/"+self.TRIGGER+"`` failed: The perma-linked post doesnt seem to exist. Was it deleted?") return if post["channel_id"] != data["channel_id"]: - request.cmd_respond_text_temp("``/"+self.TRIGGER+"`` failed: Must be executed in the same channel as the post. :(") + request.respond_err_temp("``/"+self.TRIGGER+"`` failed: Must be executed in the same channel as the post. :(") return # do actual action @@ -55,7 +62,7 @@ class DialogManagedReport(AbstractCommand): "callback_id": post["id"]+"-"+data["user_id"], "title": "Report post", "submit_label":"Report", - "state": post["id"], + "state": post["id"], "elements":[{ "display_name": "Reason", "placeholder": "Write the reason here.", @@ -67,7 +74,7 @@ class DialogManagedReport(AbstractCommand): } self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog) - request.respond(200, {}) + request.respond(200) -- 2.43.0