From b583bc88a67b3f22da79e63ddfe5283b19e40c39 Mon Sep 17 00:00:00 2001 From: Someone Date: Mon, 10 Jan 2022 17:05:06 +0100 Subject: [PATCH] modules/DialogManagedLVAFeedback.py --- modules/DialogManagedLVAFeedback.py | 156 ---------------------------- 1 file changed, 156 deletions(-) delete mode 100644 modules/DialogManagedLVAFeedback.py diff --git a/modules/DialogManagedLVAFeedback.py b/modules/DialogManagedLVAFeedback.py deleted file mode 100644 index b456a97..0000000 --- a/modules/DialogManagedLVAFeedback.py +++ /dev/null @@ -1,156 +0,0 @@ -# Mattermost Bot module. -# Copyright (c) 2016-2022 by Someone (aka. Jan Vales ) -# published under MIT-License - -from inspect import cleandoc -import csv -import os - - -# pylint: disable=wrong-import-position -from AbstractCommand import AbstractCommand -class DialogManagedLVAFeedback(AbstractCommand): - TRIGGER = "lva-feedback" - CONFIG = {"display_name": "somebot-command", "auto_complete": False, - "auto_complete_hint": "", - } - USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "preview-spams channel and asks for feedback. spam manuall!. [BOT_ADMIN]" - - - def __init__(self, team_id, datadir): - super().__init__(team_id) - - self.datadir = datadir - self.channels = dict() - - with open(self.datadir+'channels.csv', newline='') as csvfile: - self.channels = {row[0]:row for row in csv.reader(csvfile, delimiter=',', quotechar='"')} - - - def on_POST(self, request, data): - self._require_bot_admin(data) # will throw an exception if not. (Dont try-except: Its handled up the stack.) - - msg = cleandoc(""" - ## :pencil:``COVID course feedback 2.0!``:rocket: - The next term is going to be another distance-learning :dl: one. - 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. - 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. - - #### :point_right: This Feedback form will run up until 2021-02-07 23:59 :point_left: - - What we want to know: - + Feedback for this course. - + How did you like the modalities of this course? (Would you want it to be applied to others?) - + 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) - + Feedback about this survey for :fsinf:. (This will not be shared outside of fsinf) - - :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.* :) - """) - - att = [{ - "actions": [{"name": ":pencil: Give/edit your feedback", "integration": {"url": self.URL+"/interactive"}}] - }] - - print(self.URL) - request.cmd_respond_text_chan(msg, {"attachments":att}) - - - def on_POST_interactive(self, request, data): - #import pprint - #print("on_POST_interactive") - #pprint.pprint(data) - -# request.respond(200, {"ephemeral_text": "## ``The submission period ended. We are now evaluating the responses!`` :)"}) - - callback_id = "res-"+data["team_id"]+"-"+data["channel_id"]+"-"+data["user_id"] - - feedback_course = self._response_load(self.datadir+callback_id, "-feedback_course.txt") - feedback_modus = self._response_load(self.datadir+callback_id, "-feedback_modus.txt") - feedback_modus_like = self._response_load(self.datadir+callback_id, "-feedback_modus_like.txt", "0") - feedback_fsinf = self._response_load(self.datadir+callback_id, "-feedback_fsinf.txt") - - dialog = { - "callback_id": callback_id, - "title": "COVID Course feedback 2.0", - "submit_label":"Submit", - "elements":[{ - "display_name": "Your Comment/Feedback about the course (Max. 3000 characters)", - "placeholder": "Type here. Max. 3000 characters.", - "name": "feedback_course", - "type": "textarea", - "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.", - "optional": True, - "default": feedback_course - },{ - "display_name": "Describe the modalities in a few words (Max. 3000 characters)", - "placeholder": "Type here. Max. 3000 characters.", - "name": "feedback_modus", - "type": "textarea", - "help_text": "You can edit/blank it later at any time.", - "optional": True, - "default": feedback_modus - },{ - "display_name": "How did you like the modalities of this course? (Do you want it to be applied to others?)", - "placeholder": "Type here. Max. 3000 characters.", - "name": "feedback_modus_like", - "type": "radio", - "options": [ - {"text": "I loved it", "value": "2" }, - {"text": "I liked it", "value": "1" }, - {"text": "I'm indifferent/Don't want to answer (default)", "value": "0" }, - {"text": "I disliked it", "value": "-1" }, - {"text": "I hated it", "value": "-2" }, - ], - "help_text": "You can edit it later at any time.", - "optional": True, - "default": feedback_modus_like - },{ - "display_name": "Feedback (about this survey) for FSInf (Max. 3000 characters)", - "placeholder": "Type here. Max. 3000 characters.", - "name": "feedback_fsinf", - "type": "textarea", - "help_text": "We will not forward this text to anyone. You can edit/blank it later at any time.", - "optional": True, - "default": feedback_fsinf - }] - } - - request.respond(200, {}) - self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog) - - - def on_POST_dialog(self, request, data): - #import pprint - #print("on_POST_dialog") - #pprint.pprint(data) - - c = self.bot.api.get_channel(data["channel_id"]) - - self._response_store(self.datadir+data["callback_id"], "-feedback_course.txt", data["submission"]["feedback_course"], c["name"]) - self._response_store(self.datadir+data["callback_id"], "-feedback_modus.txt", data["submission"]["feedback_modus"], c["name"]) - self._response_store(self.datadir+data["callback_id"], "-feedback_modus_like.txt", data["submission"]["feedback_modus_like"], c["name"]) - self._response_store(self.datadir+data["callback_id"], "-feedback_fsinf.txt", data["submission"]["feedback_fsinf"], c["name"]) - - request.respond(200, {}) - - - def _response_load(self, path, filename, default=""): - path = path+filename - ret = default - if os.path.isfile(path): - with open(path, "r") as f: - ret = f.read() - return ret - - - def _response_store(self, path, filename, data, channelname=""): - path = path+filename - data = str(data).strip() - if data == "" or data == "None" or data == "0": - if os.path.isfile(path): - os.remove(path) - self.bot.debug_chan("``lva-feedback::"+channelname+filename+"`` result deleted.") - else: - with open(path, "w") as f: - f.write(data) - self.bot.debug_chan("``lva-feedback::"+channelname+filename+"`` result stored.\n```\n"+data+"\n```") -- 2.43.0