From bc09fa1a751aa0f951c2d66cbe5f4b8b924b76db Mon Sep 17 00:00:00 2001 From: Someone Date: Mon, 10 Jan 2022 05:06:07 +0100 Subject: [PATCH] modules/DialogManagedReport.py --- modules/DialogManagedReport.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/modules/DialogManagedReport.py b/modules/DialogManagedReport.py index 6f03bab..dc393aa 100644 --- a/modules/DialogManagedReport.py +++ b/modules/DialogManagedReport.py @@ -17,7 +17,7 @@ class DialogManagedReport(AbstractCommand): CONFIG = {"display_name": "somebot-command", "auto_complete": True, "auto_complete_hint": " []", } - CONFIG["auto_complete_desc"] = CONFIG["description"] = "Report a post. Run in same channel. Opens dialog if no reason is given." + CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Report a post. Run in same channel. Opens dialog if no reason is given." def __init__(self, team_id, report_chan_id): @@ -28,35 +28,23 @@ 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 - + post = self.bot.api.get_post(splitpath[5]) except: - 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.respond_err_temp("``/"+self.TRIGGER+"`` failed: The perma-linked post doesnt seem to exist. Was it deleted?") + request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.") return if post["channel_id"] != data["channel_id"]: - request.respond_err_temp("``/"+self.TRIGGER+"`` failed: Must be executed in the same channel as the post. :(") + request.respond_cmd_err("``/"+self.TRIGGER+"`` Must be executed in the same channel as the permalinked post.") return # do actual action if len(msg_text) == 2: self.bot.api.create_post(self.report_chan_id, "``AUTODELETE-MONTH`` ``/"+self.TRIGGER+"`` used by ``@"+data["user_name"]+"`` in ``"+data["team_domain"]+"::"+data["channel_name"]+"``\n#### Reported post: "+msg_text[0]+"\nReason:\n```\n"+msg_text[1].strip()+"\n```") - request.cmd_respond_text_temp("### ``Done.`` :)") + request.respond_cmd_temp("## :white_check_mark: Success! :)") + else: dialog = { "callback_id": post["id"]+"-"+data["user_id"], @@ -74,7 +62,7 @@ class DialogManagedReport(AbstractCommand): } self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog) - request.respond(200) + request.respond() -- 2.43.0