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 from AbstractCommand import *
11 class DialogManagedLVAFeedback(AbstractCommand):
12 TRIGGER = "lva-feedback"
13 CONFIG = {"display_name": "somebot-command", "auto_complete": False,
14 "auto_complete_hint": "",
16 USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "preview-spams channel and asks for feedback. spam manuall!. [BOT_ADMIN]"
19 def __init__(self, team_id, datadir):
20 super().__init__(team_id)
22 self.datadir = datadir
23 self.channels = dict()
25 with open(self.datadir+'channels.csv', newline='') as csvfile:
26 self.channels = {row[0]:row for row in csv.reader(csvfile, delimiter=',', quotechar='"')}
29 def on_POST(self, request, data):
30 self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.)
33 ## :pencil:``COVID course feedback 2.0!``:rocket:
34 The next term is going to be another distance-learning :dl: one.
35 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.
36 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.
38 #### :point_right: This Feedback form will run up until 2021-02-07 23:59 :point_left:
41 + Feedback for this course.
42 + How did you like the modalities of this course? (Would you want it to be applied to others?)
43 + 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)
44 + Feedback about this survey for :fsinf:. (This will not be shared outside of fsinf)
46 :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.* :)
50 "actions": [{"name": ":pencil: Give/edit your feedback", "integration": {"url": self.URL+"/interactive"}}]
54 request.cmd_respond_text_chan(msg, {"attachments":att})
57 def on_POST_interactive(self, request, data):
59 #print("on_POST_interactive")
62 # request.respond(200, {"ephemeral_text": "## ``The submission period ended. We are now evaluating the responses!`` :)"})
64 callback_id = "res-"+data["team_id"]+"-"+data["channel_id"]+"-"+data["user_id"]
66 feedback_course = self._response_load(self.datadir+callback_id, "-feedback_course.txt")
67 feedback_modus = self._response_load(self.datadir+callback_id, "-feedback_modus.txt")
68 feedback_modus_like = self._response_load(self.datadir+callback_id, "-feedback_modus_like.txt", "0")
69 feedback_fsinf = self._response_load(self.datadir+callback_id, "-feedback_fsinf.txt")
72 "callback_id": callback_id,
73 "title": "COVID Course feedback 2.0",
74 "submit_label":"Submit",
76 "display_name": "Your Comment/Feedback about the course (Max. 3000 characters)",
77 "placeholder": "Type here. Max. 3000 characters.",
78 "name": "feedback_course",
80 "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.",
82 "default": feedback_course
84 "display_name": "Describe the modalities in a few words (Max. 3000 characters)",
85 "placeholder": "Type here. Max. 3000 characters.",
86 "name": "feedback_modus",
88 "help_text": "You can edit/blank it later at any time.",
90 "default": feedback_modus
92 "display_name": "How did you like the modalities of this course? (Do you want it to be applied to others?)",
93 "placeholder": "Type here. Max. 3000 characters.",
94 "name": "feedback_modus_like",
97 {"text": "I loved it", "value": "2" },
98 {"text": "I liked it", "value": "1" },
99 {"text": "I'm indifferent/Don't want to answer (default)", "value": "0" },
100 {"text": "I disliked it", "value": "-1" },
101 {"text": "I hated it", "value": "-2" },
103 "help_text": "You can edit it later at any time.",
105 "default": feedback_modus_like
107 "display_name": "Feedback (about this survey) for FSInf (Max. 3000 characters)",
108 "placeholder": "Type here. Max. 3000 characters.",
109 "name": "feedback_fsinf",
111 "help_text": "We will not forward this text to anyone. You can edit/blank it later at any time.",
113 "default": feedback_fsinf
117 request.respond(200, {})
118 self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
121 def on_POST_dialog(self, request, data):
123 #print("on_POST_dialog")
126 c = self.bot.api.get_channel(data["channel_id"])
128 self._response_store(self.datadir+data["callback_id"], "-feedback_course.txt", data["submission"]["feedback_course"], c["name"])
129 self._response_store(self.datadir+data["callback_id"], "-feedback_modus.txt", data["submission"]["feedback_modus"], c["name"])
130 self._response_store(self.datadir+data["callback_id"], "-feedback_modus_like.txt", data["submission"]["feedback_modus_like"], c["name"])
131 self._response_store(self.datadir+data["callback_id"], "-feedback_fsinf.txt", data["submission"]["feedback_fsinf"], c["name"])
133 request.respond(200, {})
136 def _response_load(self, path, filename, default=""):
139 if os.path.isfile(path):
140 with open(path, "r") as f:
145 def _response_store(self, path, filename, data, channelname=""):
147 data = str(data).strip()
148 if data == "" or data == "None" or data == "0":
149 if os.path.isfile(path):
151 self.bot.debug_chan("``lva-feedback::"+channelname+filename+"`` result deleted.")
153 with open(path, "w") as f:
155 self.bot.debug_chan("``lva-feedback::"+channelname+filename+"`` result stored.\n```\n"+data+"\n```")