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 given 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": "What's going on?",
55 "name": "report_reason",
58 "text": "It's annoying or not interesting",
59 "value": "not_interesting"
61 "text": "I'm in this post and I don't like it",
62 "value": "im_in_it_and_i_dont_like_it"
64 "text": "I think it shouldn't be on Mattermost",
65 "value": "should_not_be_on_mm"
70 "text": "Other reason (Fill in below)",
71 "value": "other_reason"
75 "default": "other_reason"
77 "display_name": "Other reason or additional details",
78 "placeholder": "Write a custom reason or additional details here.",
79 "name": "report_other_reason",
81 "help_text": "The report is submitted to channel and team admin_as.",
86 self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
91 def on_POST_dialog(self, request, data):
92 user = self.bot.api.get_user(data["user_id"])
93 team = self.bot.api.get_team(data["team_id"])
94 chan = self.bot.api.get_channel(data["channel_id"])
96 if "report_other_reason" in data["submission"] and data["submission"]["report_other_reason"]:
97 report_other_reason = "\nAdditional details/other reason:\n```\n"+data["submission"]["report_other_reason"].strip()+"\n```"
99 report_other_reason = ""
100 if "report_reason" in data["submission"] and data["submission"]["report_reason"] == "other_reason":
101 request.respond(200, {"errors": {"report_reason": "Please write some details below, if selecting 'other reason'"}})
104 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 selected: **``"+data["submission"]["report_reason"]+"``**"+report_other_reason)