modules/DialogManagedReport.py
authorSomeone <someone@somenet.org>
Thu, 6 Jan 2022 21:21:03 +0000 (22:21 +0100)
committerSomeone <someone@somenet.org>
Thu, 6 Jan 2022 21:21:03 +0000 (22:21 +0100)
modules/DialogManagedReport.py

index 7e71dd46b66229e66de5cec5712bb8a9d9cdd1ec..2f35ae480ad90879aaf2dd43a656f6b3c0dba260 100644 (file)
@@ -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)