From 57ae1e77b7b7cdf119063d6167df51256174220f Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 19 Jun 2020 01:32:13 +0200 Subject: [PATCH] [somebot/modules/] DialogManagedCoronaLVAFeedback. --- .../modules/DialogManagedCoronaLVAFeedback.py | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 somebot/modules/DialogManagedCoronaLVAFeedback.py diff --git a/somebot/modules/DialogManagedCoronaLVAFeedback.py b/somebot/modules/DialogManagedCoronaLVAFeedback.py new file mode 100644 index 0000000..e3bbe5b --- /dev/null +++ b/somebot/modules/DialogManagedCoronaLVAFeedback.py @@ -0,0 +1,108 @@ +# Mattermost Bot. +# Copyright (c) 2016-2020 by Someone (aka. Jan Vales ) +# published under MIT-License + +from inspect import cleandoc +import csv +import os + + +from AbstractCommand import * +class DialogManagedCoronaLVAFeedback(AbstractCommand): + TRIGGER = "corona-lva-feedback" + CONFIG = {"display_name": "somebot-command", "auto_complete": True, + "auto_complete_hint": "", + } + USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "spams all LVA-Channels and asks for feedback on Corona changes. [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(""" + ## @channel ``We want your Corona-related feedback for this course!`` + The Corona-crisis has led to many announcements of changes to courses. + We are interested to find out which courses still need to improve to achieve the excellence we are accustomed to so we can follow-up on the issues that still persist. + + We know of the following announcements: https://wiki.fsinf.at/wiki/Course_reactions_to_coronavirus/(W)Inf + If a course is missing, or outdated, please update the page, it helps us represent you! + + + This course announced: + + lectures: + + excersises: + + This course was cancelled. + + We do not have any data on this course's announcements. :( + + """) + + att = [{ + "text": "##### How well were the announced changes executed so far? Are there still issues with this course?", + "actions": [{"name": "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!`` :)"}) + +# filename_feedback = self.datadir+data["team_id"]+"-"+data["channel_id"]+"-"+data["user_id"]+"-feedback.txt" +# if os.path.isfile(filename_feedback): +# with open(filename_feedback, "r") as f: +# feedback = f.read() +# else: +# feedback = "" +# +# dialog = { +# "callback_id": data["team_id"]+"-"+data["channel_id"]+"-"+data["user_id"], +# "title": "Corona related course changes", +# "submit_label":"Submit", +# "elements":[{ +# "display_name": "Your Comment/Feedback (Max. 3000 characters)", +# "placeholder": "Type here. Max. 3000 characters.", +# "name": "feedback", +# "type": "textarea", +# "help_text": "We will not forward your feedback to teaching staff. You can edit/blank it later at any time. Your user_id is stored.", +# "optional": True, +# "default": feedback +# }] +# } + +# 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) +# +# filename_feedback = self.datadir+data["callback_id"]+"-feedback.txt" +# feedback = data["submission"]["feedback"].strip() +# if feedback == "": +# os.remove(filename_feedback) +# self.bot.debug_chan("``corona-lva-feedback`` result deleted for ``"+self.channels[data["channel_id"]][6]+"``") +# else: +# with open(filename_feedback, "w") as f: +# f.write(feedback) +# self.bot.debug_chan("``corona-lva-feedback`` result stored for ``"+self.channels[data["channel_id"]][6]+"``\n```\n"+data["submission"]["feedback"]+"\n```") +# +# request.respond(200, {}) -- 2.43.0