]> git.somenet.org - pub/jan/mattermost.git/blob - somebot/modules/DialogManagedCoronaLVAFeedback.py
[somebot/modules/] DialogManagedCoronaLVAFeedback.
[pub/jan/mattermost.git] / somebot / modules / DialogManagedCoronaLVAFeedback.py
1 # Mattermost Bot.
2 #  Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 #  published under MIT-License
4
5 from inspect import cleandoc
6 import csv
7 import os
8
9
10 from AbstractCommand import *
11 class DialogManagedCoronaLVAFeedback(AbstractCommand):
12     TRIGGER = "corona-lva-feedback"
13     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
14               "auto_complete_hint": "",
15              }
16     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "spams all LVA-Channels and asks for feedback on Corona changes. [BOT_ADMIN]"
17
18
19     def __init__(self, team_id, datadir):
20         super().__init__(team_id)
21
22         self.datadir = datadir
23         self.channels = dict()
24         
25         with open(self.datadir+'channels.csv', newline='') as csvfile:
26             self.channels = {row[0]:row for row in csv.reader(csvfile, delimiter=',', quotechar='"')}
27
28
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.)
31
32         msg = cleandoc("""
33             ## @channel ``We want your Corona-related feedback for this course!``
34             The Corona-crisis has led to many announcements of changes to courses.
35             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.
36             
37             We know of the following announcements: https://wiki.fsinf.at/wiki/Course_reactions_to_coronavirus/(W)Inf
38             If a course is missing, or outdated, please update the page, it helps us represent you!
39
40             <dynamisch>
41             This course announced:
42             + lectures: 
43             + excersises: 
44             <dynamisch>
45             This course was cancelled.
46             <dynamisch>
47             We do not have any data on this course's announcements. :(
48             </dynamisch>
49             """)
50
51         att = [{
52             "text": "##### How well were the announced changes executed so far? Are there still issues with this course?",
53             "actions": [{"name": "Give/edit your feedback", "integration": {"url": self.URL+"/interactive"}}]
54             }]
55
56         print(self.URL)
57         request.cmd_respond_text_chan(msg, {"attachments":att})
58
59
60     def on_POST_interactive(self, request, data):
61         #import pprint
62         #print("on_POST_interactive")
63         #pprint.pprint(data)
64
65         request.respond(200, {"ephemeral_text": "## ``The submission period ended. We are now evaluating the responses!`` :)"})
66
67 #        filename_feedback = self.datadir+data["team_id"]+"-"+data["channel_id"]+"-"+data["user_id"]+"-feedback.txt"
68 #        if os.path.isfile(filename_feedback):
69 #            with open(filename_feedback, "r") as f:
70 #                feedback = f.read()
71 #        else:
72 #            feedback = ""
73 #
74 #        dialog = {
75 #            "callback_id": data["team_id"]+"-"+data["channel_id"]+"-"+data["user_id"],
76 #            "title": "Corona related course changes",
77 #            "submit_label":"Submit",
78 #            "elements":[{
79 #                "display_name": "Your Comment/Feedback (Max. 3000 characters)",
80 #                "placeholder": "Type here. Max. 3000 characters.",
81 #                "name": "feedback",
82 #                "type": "textarea",
83 #                "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.",
84 #                "optional": True,
85 #                "default": feedback
86 #            }]
87 #        }
88
89 #        request.respond(200, {})
90 #        self.bot.api.open_dialog(data["trigger_id"], self.URL+"/dialog", dialog)
91
92
93 #    def on_POST_dialog(self, request, data):
94 #        #import pprint
95 #        #print("on_POST_dialog")
96 #        #pprint.pprint(data)
97 #
98 #        filename_feedback = self.datadir+data["callback_id"]+"-feedback.txt"
99 #        feedback = data["submission"]["feedback"].strip()
100 #        if feedback == "":
101 #            os.remove(filename_feedback)
102 #            self.bot.debug_chan("``corona-lva-feedback`` result deleted for ``"+self.channels[data["channel_id"]][6]+"``")
103 #        else:
104 #            with open(filename_feedback, "w") as f:
105 #                f.write(feedback)
106 #            self.bot.debug_chan("``corona-lva-feedback`` result stored for ``"+self.channels[data["channel_id"]][6]+"``\n```\n"+data["submission"]["feedback"]+"\n```")
107 #
108 #        request.respond(200, {})