1 # Mattermost Bot module.
2 # Copyright (c) 2016-2022 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 logger = logging.getLogger(__name__)
12 # pylint: disable=wrong-import-position
13 from AbstractCommand import AbstractCommand
14 class DialogManagedReport(AbstractCommand):
16 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
17 "auto_complete_hint": "<permalink> [<reason>]",
19 CONFIG["auto_complete_desc"] = CONFIG["description"] = AbstractCommand.ICON_PRIVATE+"Report a post. Run in same channel. Opens dialog if no reason is given."
22 def __init__(self, team_id, report_chan_id):
23 super().__init__(team_id)
24 self.report_chan_id = report_chan_id
27 def on_POST(self, request, data):
28 msg_text = data['text'].strip().split(" ", 1)
31 splitpath = msg_text[0].strip().strip("/").split("/")
32 if splitpath[4] == "pl":
33 post = self.bot.api.get_post(splitpath[5])
35 request.respond_cmd_err("``/"+self.TRIGGER+"`` The first parameter is not a valid post-permalink or the permalinked post has been deleted.")
38 if post["channel_id"] != data["channel_id"]:
39 request.respond_cmd_err("``/"+self.TRIGGER+"`` Must be executed in the same channel as the permalinked post.")
43 if len(msg_text) == 2:
44 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```")
45 request.respond_cmd_temp("## :white_check_mark: Success! :)")
49 "callback_id": post["id"]+"-"+data["user_id"],
50 "title": "Report post",
51 "submit_label":"Report",
54 "display_name": "Reason",
55 "placeholder": "Write the reason here.",
56 "name": "report_reason",
58 "help_text": "The reason is submitted to channel and team admin_as.",
63 self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
68 def on_POST_dialog(self, request, data):
69 user = self.bot.api.get_user(data["user_id"])
70 team = self.bot.api.get_team(data["team_id"])
71 chan = self.bot.api.get_channel(data["channel_id"])
73 self.bot.api.create_post(self.report_chan_id, "``AUTODELETE-MONTH`` ``/"+self.TRIGGER+"`` used by ``@"+user["username"]+"`` in ``"+team["name"]+"::"+chan["name"]+"``\n#### Reported post: https://mattermost.fsinf.at/"+team["name"]+"/pl/"+data["state"]+"\nReason:\n```\n"+data["submission"]["report_reason"].strip()+"\n```")