[somebot] /inskription <mnr>
authorSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
committerSomeone <someone@somenet.org>
Wed, 8 Dec 2021 18:38:38 +0000 (19:38 +0100)
modules/CommandInskription.py [new file with mode: 0644]

diff --git a/modules/CommandInskription.py b/modules/CommandInskription.py
new file mode 100644 (file)
index 0000000..f7c05dc
--- /dev/null
@@ -0,0 +1,174 @@
+# Mattermost Bot module.
+#  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+#  published under MIT-License
+
+
+
+from AbstractCommand import AbstractCommand
+class CommandInskription(AbstractCommand):
+    TRIGGER = "inskription"
+    CONFIG = {"display_name": "somebot-command", "auto_complete": True,
+        "auto_complete_hint": "<matrikelnummer>",
+    }
+    USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Account freischaltung nach Inskription."
+
+
+    def on_POST(self, request, data):
+        mnr = data["text"].strip().strip("e")
+
+        if len(mnr) != 8:
+            request.cmd_respond_text_temp("Deine Matrikelnummer besteht aus 8 Ziffern und optional einem vor-angestellten ``e``. Bitte versucht noch einmal.")
+            return
+
+        try:
+            int(mnr)
+        except:
+            request.cmd_respond_text_temp("Dies scheint keine Gültige Matrikelnummer zu sein. :(\nDeine Matrikelnummer besteht aus 8 Ziffern und optional einem vor-angestellten ``e``. Bitte versucht noch einmal.")
+            return
+
+        msg = "Congratz zur Inskription!:tada:\nBist du: https://tiss.tuwien.ac.at/adressbuch/adressbuch/suche?suchtext="+mnr+" ?"
+        msg += "\n\n---\nMit der Auswahl eines oder mehrer Studien wird deine eMail-Adresse dieses Accounts auf deine Studi-email-adresse (**``e"+mnr+"@student.tuwien.ac.at``**) geändert. Bestätige diese bitte so schnell wie möglich.\n"
+        msg += "(Wir sind deine Studienvertretung und geben deine Daten selbstverständlich nicht weiter und schon garnicht an die Profs oder Tutor_innen - wir brauchen deine eMail-Adresse nur aus lizenztechnischen und organisatorischen Gründen (Mattermost education-enterprise; 1 Account pro Person; Wir geben deine eMail-adresse auch nicht an Mattermost Inc. weiter!))\n"
+        msg += "Falls du noch nicht weißt, wie du deine Studi-eMails abfragst: https://mail.student.tuwien.ac.at/webmail/ (user: ``e"+mnr+"``; Das Passwort ist dein übliches TU-passwort)\n"
+
+        att = [{
+              "text": "Um dir das durchwühlen durch die 500+ LVA-Channels zu erleichtern: Was studierst du? (Mehrfachauswahl möglich; Wird nicht gespeichert)",
+              "actions": [
+                {
+                  "name": "Ich bin nicht die verlinkte Person :(",
+                  "integration": { "url": self.URL+"/interactive", "context": { "action": "click_not_person", "mnr":mnr, "user_id":data["user_id"] } }
+                }, {
+                  "name": "Software-Engineering :tada:",
+                  "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bse", "mnr":mnr, "user_id":data["user_id"] } }
+                }, {
+                  "name": "Medieninformatik :tada:",
+                  "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bme", "mnr":mnr, "user_id":data["user_id"] } }
+                }, {
+                  "name": "Medizinische Informatik :tada:",
+                  "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bmz", "mnr":mnr, "user_id":data["user_id"] } }
+                }, {
+                  "name": "Technische Informatik :tada:",
+                  "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bti", "mnr":mnr, "user_id":data["user_id"] } }
+                }, {
+                  "name": "Anderes Informatik Studium :tada:",
+                  "integration": { "url": self.URL+"/interactive", "context": { "action": "click_other", "mnr":mnr, "user_id":data["user_id"] } }
+                }, {
+                  "name": "Wirtschaftsinformatik :tada:",
+                  "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bwi", "mnr":mnr, "user_id":data["user_id"] } }
+                }
+              ]
+            },
+          ]
+
+        # Make it in_channel/persistent only of talking to self of to bot.
+        if data["channel_name"] == data["user_id"]+"__"+data["user_id"] or data["channel_name"] == self.bot.api.my_user_id+"__"+data["user_id"] or data["channel_name"] == data["user_id"]+"__"+self.bot.api.my_user_id:
+            att[0]["actions"][0]["integration"]["context"]["persistent"] = True
+            request.respond(200, {"response_type":"in_channel", "text":msg, "attachments":att})
+        else:
+            c = self.bot.api.create_dm_channel_with(data['user_id'])
+            att[0]["actions"][0]["integration"]["context"]["persistent"] = True
+            p = self.bot.api.create_post(c['id'], msg, props={"from_webhook":"true", "attachments":att})
+            msg = "Damit deine Matrikelnummer nicht öffentlich wird, wurdest du von @bot in einem sicheren Channel angeschrieben.\n:arrow_right: https://mattermost.fsinf.at/"+data["team_domain"]+"/pl/"+p["id"]
+            request.cmd_respond_text_temp(msg)
+
+
+
+    def on_POST_interactive(self, request, data):
+        # /inskriprion and buttonclick were triggered by diffrent users.
+        if data["context"]["user_id"] != data["user_id"]:
+            request.respond(200, {})
+            return
+
+        team_id = 'sswtb6oqciyyfmkibh6mjz479w'
+        chans_default=["1nq6h1fuftng7c651qra5ntp3c","e1c1k3h4nbb6xmerww5fqyrffe","k6jmp4nnm7drieg74r7qzihrgy","saig8etyt7riznrryxkafcbaso","8qfbjhha17y7m8bmkwwmr7mcby"]
+        chans_ti=["1nq6h1fuftng7c651qra5ntp3c","cfce951nkb8mt8ckee3z3w6iyw","e1c1k3h4nbb6xmerww5fqyrffe","k6jmp4nnm7drieg74r7qzihrgy","ihdpxumdsjgzfdxjkih8mzpxrr","8qfbjhha17y7m8bmkwwmr7mcby","saig8etyt7riznrryxkafcbaso"]
+        chans_winf=["1nq6h1fuftng7c651qra5ntp3c","cfce951nkb8mt8ckee3z3w6iyw","e1c1k3h4nbb6xmerww5fqyrffe","k6jmp4nnm7drieg74r7qzihrgy","xt7pwj4esjbhbbm7fohboqdume","51n3wsq7hiff7yd593w6mfnorw","saig8etyt7riznrryxkafcbaso","84skhwgpqtdbmenzriyruqjxuA"]
+
+        if data["context"]["action"] == "click_not_person":
+            msg = "Oh. :( Probiers mit der korrekten Matrikelnummer erneut ``/inskription <korrekte Matrikelnummer>`` :)"
+            import pprint
+            pprint.pprint(data)
+            if "persistent" in data["context"]:
+                request.respond(200, {"update":{"message":msg, "props":{}}})
+            else:
+                request.respond(200, {"ephemeral_text": msg})
+
+
+        elif data["context"]["action"] == "click_bse":
+            # join user to channels.
+            msg = "Soso, Software engineering also.\n\nDu wurdest in folgende Channels geadded:"
+            for cid in chans_default:
+                c = self.bot.api.get_channel(cid)
+                self.bot.api.add_user_to_team(team_id, data["user_id"])
+                self.bot.api.add_user_to_channel(c["id"], data["user_id"])
+                msg += "\n + ~"+c["name"]
+
+            # set email addr
+            self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
+            msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
+            request.respond(200, {"ephemeral_text": msg})
+
+        elif data["context"]["action"] == "click_bme":
+            # join user to channels.
+            msg = "Aha, Medieeninformatik, sehr gut!\n\nDu wurdest in folgende Channels geadded:"
+            for cid in chans_default:
+                c = self.bot.api.get_channel(cid)
+                self.bot.api.add_user_to_team(team_id, data["user_id"])
+                self.bot.api.add_user_to_channel(c["id"], data["user_id"])
+                msg += "\n + ~"+c["name"]
+
+            # set email addr
+            self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
+            msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
+            request.respond(200, {"ephemeral_text": msg})
+
+        elif data["context"]["action"] == "click_bmz":
+            # join user to channels.
+            msg = "Yay, Medizinische Informatik ftw.\n\nDu wurdest in folgende Channels geadded:"
+            for cid in chans_default:
+                c = self.bot.api.get_channel(cid)
+                self.bot.api.add_user_to_team(team_id, data["user_id"])
+                self.bot.api.add_user_to_channel(c["id"], data["user_id"])
+                msg += "\n + ~"+c["name"]
+
+            # set email addr
+            self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
+            msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
+            request.respond(200, {"ephemeral_text": msg})
+
+        elif data["context"]["action"] == "click_bti":
+            # join user to channels.
+            msg = "Technische Informatik. 31337!\n\nDu wurdest in folgende Channels geadded:"
+            for cid in chans_ti:
+                c = self.bot.api.get_channel(cid)
+                self.bot.api.add_user_to_team(team_id, data["user_id"])
+                self.bot.api.add_user_to_channel(c["id"], data["user_id"])
+                msg += "\n + ~"+c["name"]
+
+            # set email addr
+            self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
+            msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
+            request.respond(200, {"ephemeral_text": msg})
+
+        elif data["context"]["action"] == "click_bwi":
+            # join user to channels.
+            msg = "May t3h ca$h be with you!\n\nDu wurdest in folgende Channels geadded:"
+            for cid in chans_winf:
+                c = self.bot.api.get_channel(cid)
+                self.bot.api.add_user_to_team(team_id, data["user_id"])
+                self.bot.api.add_user_to_channel(c["id"], data["user_id"])
+                msg += "\n + ~"+c["name"]
+
+            # set email addr
+            self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
+            msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
+            request.respond(200, {"ephemeral_text": msg})
+
+        elif data["context"]["action"] == "click_other":
+            # set email addr
+            self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
+
+            msg = "Ein Master-Studium also?\n\nDu wurdest in keine Channels geadded. Deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
+            self.bot.api.add_user_to_team(team_id, data["user_id"])
+
+            request.respond(200, {"ephemeral_text": msg})