1 # Mattermost Bot module.
2 # Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 # published under MIT-License
5 from inspect import cleandoc
9 from AbstractCommand import *
10 class DialogManagedPrologFeedback(AbstractCommand):
11 TRIGGER = "prolog-feedback"
12 CONFIG = {"display_name": "somebot-command", "auto_complete": True,
13 "auto_complete_hint": "Generate feedback-message",
15 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Post request for feedback. [BOT_ADMIN]"
18 def __init__(self, team_id, datadir):
19 super().__init__(team_id)
20 self.datadir = datadir
23 def on_POST(self, request, data):
24 self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
27 ## @all `Habts Feedback für uns bzgl. des Beginners' Events diese Woche?`
28 Wir hoffen ihr hattet genau so viel Spaß und einen tollen Abend, wie wir. :)
29 Man kann immer etwas besser machen und deshalb wollen wir euch explizit um Feedback bitten.
34 "actions": [{"name": "Schreibe/Bearbeite dein Feedback", "integration": {"url": self.URL+"/interactive"}}]
38 request.cmd_respond_text_chan(msg, {"attachments":att})
41 def on_POST_interactive(self, request, data):
43 print("on_POST_interactive")
46 filename_feedback_day1 = self.datadir+data["user_id"]+"-feedback_day1.txt"
48 if os.path.isfile(filename_feedback_day1):
49 with open(filename_feedback_day1, "r") as f:
50 feedback_day1 = f.read()
51 filename_feedback_day2 = self.datadir+data["user_id"]+"-feedback_day2.txt"
53 if os.path.isfile(filename_feedback_day2):
54 with open(filename_feedback_day2, "r") as f:
55 feedback_day2 = f.read()
56 filename_feedback_day3 = self.datadir+data["user_id"]+"-feedback_day3.txt"
58 if os.path.isfile(filename_feedback_day3):
59 with open(filename_feedback_day3, "r") as f:
60 feedback_day3 = f.read()
63 "callback_id": data["user_id"],
64 "title": "Feedback zu Fachschaftsevents dieser Prolog-Woche",
65 "submit_label":"Speichern",
68 "display_name": "Feedback zum montägigen HowTUni-Fachschaftvortrag (Max. 3000 Zeichen)",
69 "placeholder": "Schreibe dein Feedback hier. Max. 3000 Zeichen.",
70 "name": "feedback-day1",
73 "default": feedback_day1
75 "display_name": "Feedback zu den Kleingruppen-Sessions am Dienstag (Max. 3000 Zeichen)",
76 "placeholder": "Schreibe dein Feedback hier. Max. 3000 Zeichen.",
77 "name": "feedback-day2",
80 "default": feedback_day2
82 "display_name": "Feedback zum Abhängen am Karlsplatz am Mittwoch (Max. 3000 Zeichen)",
83 "placeholder": "Schreibe dein Feedback hier. Max. 3000 Zeichen.",
84 "name": "feedback-day3",
86 "help_text": "Du kannst dein Feedback im nachhinein jederzeit bearbeiten/leeren.",
88 "default": feedback_day3
93 request.respond(200, {})
94 self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
97 def on_POST_dialog(self, request, data):
99 print("on_POST_dialog")
102 msg = "``prolog-feedback``\n"
103 filename_feedback_day1 = self.datadir+data["callback_id"]+"-feedback_day1.txt"
104 if data["submission"]["feedback-day1"]:
105 feedback_day1 = data["submission"]["feedback-day1"].strip()
108 if feedback_day1 == "":
109 if os.path.isfile(filename_feedback_day1):
110 os.remove(filename_feedback_day1)
111 msg += "result-day1 result was deleted.\n"
113 with open(filename_feedback_day1, "w") as f:
114 f.write(feedback_day1)
115 msg += "result-day1 result was stored.\n"
116 filename_feedback_day2 = self.datadir+data["callback_id"]+"-feedback_day2.txt"
117 if data["submission"]["feedback-day2"]:
118 feedback_day2= data["submission"]["feedback-day2"].strip()
121 if feedback_day2 == "":
122 if os.path.isfile(filename_feedback_day2):
123 os.remove(filename_feedback_day2)
124 msg += "result-day2 result was deleted.\n"
126 with open(filename_feedback_day2, "w") as f:
127 f.write(feedback_day2)
128 msg += "result-day2 result was stored.\n"
129 filename_feedback_day3 = self.datadir+data["callback_id"]+"-feedback_day3.txt"
130 if data["submission"]["feedback-day3"]:
131 feedback_day3 = data["submission"]["feedback-day3"].strip()
134 if feedback_day3 == "":
135 if os.path.isfile(filename_feedback_day3):
136 os.remove(filename_feedback_day3)
137 msg += "result-day3 result was deleted.\n"
139 with open(filename_feedback_day3, "w") as f:
140 f.write(feedback_day3)
141 msg += "result-day3 result was stored.\n"
143 self.bot.debug_chan(msg)
144 request.respond(200, {})