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
10 # pylint: disable=wrong-import-position
11 from AbstractCommand import AbstractCommand
12 class DialogManagedLVAFeedback(AbstractCommand):
13 TRIGGER = "lva-feedback"
14 CONFIG = {"display_name": "somebot-command", "auto_complete": False,
15 "auto_complete_hint": "",
17 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "preview-spams channel and asks for feedback. spam manuall!. [BOT_ADMIN]"
20 def __init__(self, team_id, datadir):
21 super().__init__(team_id)
23 self.datadir = datadir
24 self.channels = dict()
26 with open(self.datadir+'channels.csv', newline='') as csvfile:
27 self.channels = {row[0]:row for row in csv.reader(csvfile, delimiter=',', quotechar='"')}
30 def on_POST(self, request, data):
31 self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
34 ## :pencil:``COVID course feedback 2.0!``:rocket:
35 The next term is going to be another distance-learning :dl: one.
36 We want your feedback in order to find out which courses need to be improved asap to achieve the excellence we are accustomed to, or better.
37 The feedback will be aggregated, anonymised and discussed with the deans of study affairs and possibly with the vice rector for teaching matter and/or the in-house lawyers.
39 #### :point_right: This Feedback form will run up until 2021-02-07 23:59 :point_left:
42 + Feedback for this course.
43 + How did you like the modalities of this course? (Would you want it to be applied to others?)
44 + This course's modalities - describe them in a few words. (Also consider updating the info in VoWi - its a work resource for us and we use it to represent you)
45 + Feedback about this survey for :fsinf:. (This will not be shared outside of fsinf)
47 :information_source: *We are your legaly appointed representatives - we will never forward any personal info about who wrote what without explicit permission. But please dont make us read a list of profanities.* :)
51 "actions": [{"name": ":pencil: Give/edit your feedback", "integration": {"url": self.URL+"/interactive"}}]
55 request.cmd_respond_text_chan(msg, {"attachments":att})
58 def on_POST_interactive(self, request, data):
60 #print("on_POST_interactive")
63 # request.respond(200, {"ephemeral_text": "## ``The submission period ended. We are now evaluating the responses!`` :)"})
65 callback_id = "res-"+data["team_id"]+"-"+data["channel_id"]+"-"+data["user_id"]
67 feedback_course = self._response_load(self.datadir+callback_id, "-feedback_course.txt")
68 feedback_modus = self._response_load(self.datadir+callback_id, "-feedback_modus.txt")
69 feedback_modus_like = self._response_load(self.datadir+callback_id, "-feedback_modus_like.txt", "0")
70 feedback_fsinf = self._response_load(self.datadir+callback_id, "-feedback_fsinf.txt")
73 "callback_id": callback_id,
74 "title": "COVID Course feedback 2.0",
75 "submit_label":"Submit",
77 "display_name": "Your Comment/Feedback about the course (Max. 3000 characters)",
78 "placeholder": "Type here. Max. 3000 characters.",
79 "name": "feedback_course",
81 "help_text": "We will aggregate and forward your feedback to the deans of study affairs, the vice rector for teaching and possibly others that are deemed able to fix something. You can edit/blank it later at any time.",
83 "default": feedback_course
85 "display_name": "Describe the modalities in a few words (Max. 3000 characters)",
86 "placeholder": "Type here. Max. 3000 characters.",
87 "name": "feedback_modus",
89 "help_text": "You can edit/blank it later at any time.",
91 "default": feedback_modus
93 "display_name": "How did you like the modalities of this course? (Do you want it to be applied to others?)",
94 "placeholder": "Type here. Max. 3000 characters.",
95 "name": "feedback_modus_like",
98 {"text": "I loved it", "value": "2" },
99 {"text": "I liked it", "value": "1" },
100 {"text": "I'm indifferent/Don't want to answer (default)", "value": "0" },
101 {"text": "I disliked it", "value": "-1" },
102 {"text": "I hated it", "value": "-2" },
104 "help_text": "You can edit it later at any time.",
106 "default": feedback_modus_like
108 "display_name": "Feedback (about this survey) for FSInf (Max. 3000 characters)",
109 "placeholder": "Type here. Max. 3000 characters.",
110 "name": "feedback_fsinf",
112 "help_text": "We will not forward this text to anyone. You can edit/blank it later at any time.",
114 "default": feedback_fsinf
118 request.respond(200, {})
119 self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
122 def on_POST_dialog(self, request, data):
124 #print("on_POST_dialog")
127 c = self.bot.api.get_channel(data["channel_id"])
129 self._response_store(self.datadir+data["callback_id"], "-feedback_course.txt", data["submission"]["feedback_course"], c["name"])
130 self._response_store(self.datadir+data["callback_id"], "-feedback_modus.txt", data["submission"]["feedback_modus"], c["name"])
131 self._response_store(self.datadir+data["callback_id"], "-feedback_modus_like.txt", data["submission"]["feedback_modus_like"], c["name"])
132 self._response_store(self.datadir+data["callback_id"], "-feedback_fsinf.txt", data["submission"]["feedback_fsinf"], c["name"])
134 request.respond(200, {})
137 def _response_load(self, path, filename, default=""):
140 if os.path.isfile(path):
141 with open(path, "r") as f:
146 def _response_store(self, path, filename, data, channelname=""):
148 data = str(data).strip()
149 if data == "" or data == "None" or data == "0":
150 if os.path.isfile(path):
152 self.bot.debug_chan("``lva-feedback::"+channelname+filename+"`` result deleted.")
154 with open(path, "w") as f:
156 self.bot.debug_chan("``lva-feedback::"+channelname+filename+"`` result stored.\n```\n"+data+"\n```")