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 from inspect import cleandoc
9 # pylint: disable=wrong-import-position
10 from AbstractCommand import AbstractCommand
11 class DialogManagedPrologFeedback(AbstractCommand):
12 TRIGGER = "prolog-feedback"
13 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14 "auto_complete_hint": "Generate feedback-message",
16 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Post request for feedback. [BOT_ADMIN]"
19 def __init__(self, team_id, datadir):
20 super().__init__(team_id)
21 self.datadir = datadir
24 def on_POST(self, request, data):
25 self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
28 ## @all `Habts Feedback für uns bzgl. des Beginners' Events diese Woche?`
29 Wir hoffen ihr hattet genau so viel Spaß und einen tollen Abend, wie wir. :)
30 Man kann immer etwas besser machen und deshalb wollen wir euch explizit um Feedback bitten.
35 "actions": [{"name": "Schreibe/Bearbeite dein Feedback", "integration": {"url": self.URL+"/interactive"}}]
39 request.cmd_respond_text_chan(msg, {"attachments":att})
42 def on_POST_interactive(self, request, data):
44 print("on_POST_interactive")
47 filename_feedback_day1 = self.datadir+data["user_id"]+"-feedback_day1.txt"
49 if os.path.isfile(filename_feedback_day1):
50 with open(filename_feedback_day1, "r") as f:
51 feedback_day1 = f.read()
52 filename_feedback_day2 = self.datadir+data["user_id"]+"-feedback_day2.txt"
54 if os.path.isfile(filename_feedback_day2):
55 with open(filename_feedback_day2, "r") as f:
56 feedback_day2 = f.read()
57 filename_feedback_day3 = self.datadir+data["user_id"]+"-feedback_day3.txt"
59 if os.path.isfile(filename_feedback_day3):
60 with open(filename_feedback_day3, "r") as f:
61 feedback_day3 = f.read()
64 "callback_id": data["user_id"],
65 "title": "Feedback zu Fachschaftsevents dieser Prolog-Woche",
66 "submit_label":"Speichern",
69 "display_name": "Feedback zum montägigen HowTUni-Fachschaftvortrag (Max. 3000 Zeichen)",
70 "placeholder": "Schreibe dein Feedback hier. Max. 3000 Zeichen.",
71 "name": "feedback-day1",
74 "default": feedback_day1
76 "display_name": "Feedback zu den Kleingruppen-Sessions am Dienstag (Max. 3000 Zeichen)",
77 "placeholder": "Schreibe dein Feedback hier. Max. 3000 Zeichen.",
78 "name": "feedback-day2",
81 "default": feedback_day2
83 "display_name": "Feedback zum Abhängen am Karlsplatz am Mittwoch (Max. 3000 Zeichen)",
84 "placeholder": "Schreibe dein Feedback hier. Max. 3000 Zeichen.",
85 "name": "feedback-day3",
87 "help_text": "Du kannst dein Feedback im nachhinein jederzeit bearbeiten/leeren.",
89 "default": feedback_day3
94 request.respond(200, {})
95 self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
98 def on_POST_dialog(self, request, data):
100 print("on_POST_dialog")
103 msg = "``prolog-feedback``\n"
104 filename_feedback_day1 = self.datadir+data["callback_id"]+"-feedback_day1.txt"
105 if data["submission"]["feedback-day1"]:
106 feedback_day1 = data["submission"]["feedback-day1"].strip()
109 if feedback_day1 == "":
110 if os.path.isfile(filename_feedback_day1):
111 os.remove(filename_feedback_day1)
112 msg += "result-day1 result was deleted.\n"
114 with open(filename_feedback_day1, "w") as f:
115 f.write(feedback_day1)
116 msg += "result-day1 result was stored.\n"
117 filename_feedback_day2 = self.datadir+data["callback_id"]+"-feedback_day2.txt"
118 if data["submission"]["feedback-day2"]:
119 feedback_day2= data["submission"]["feedback-day2"].strip()
122 if feedback_day2 == "":
123 if os.path.isfile(filename_feedback_day2):
124 os.remove(filename_feedback_day2)
125 msg += "result-day2 result was deleted.\n"
127 with open(filename_feedback_day2, "w") as f:
128 f.write(feedback_day2)
129 msg += "result-day2 result was stored.\n"
130 filename_feedback_day3 = self.datadir+data["callback_id"]+"-feedback_day3.txt"
131 if data["submission"]["feedback-day3"]:
132 feedback_day3 = data["submission"]["feedback-day3"].strip()
135 if feedback_day3 == "":
136 if os.path.isfile(filename_feedback_day3):
137 os.remove(filename_feedback_day3)
138 msg += "result-day3 result was deleted.\n"
140 with open(filename_feedback_day3, "w") as f:
141 f.write(feedback_day3)
142 msg += "result-day3 result was stored.\n"
144 self.bot.debug_chan(msg)
145 request.respond(200, {})