]> git.somenet.org - pub/jan/mattermost-bot.git/blob - modules/CommandInskription.py
modules/CommandDrinkBindAccount.py
[pub/jan/mattermost-bot.git] / modules / CommandInskription.py
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
4
5
6
7 # pylint: disable=wrong-import-position
8 from AbstractCommand import AbstractCommand
9 class CommandInskription(AbstractCommand):
10     TRIGGER = "inskription"
11     CONFIG = {"display_name": "somebot-command", "auto_complete": True,
12         "auto_complete_hint": "<matrikelnummer>",
13     }
14     USEINFO = CONFIG["auto_complete_desc"] = CONFIG["description"] = "Account freischaltung nach Inskription."
15
16
17     def on_POST(self, request, data):
18         mnr = data["text"].strip().strip("e")
19
20         if len(mnr) != 8:
21             request.cmd_respond_text_temp("Deine Matrikelnummer besteht aus 8 Ziffern und optional einem vor-angestellten ``e``. Bitte versucht noch einmal.")
22             return
23
24         try:
25             int(mnr)
26         except:
27             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.")
28             return
29
30         msg = "Congratz zur Inskription!:tada:\nBist du: https://tiss.tuwien.ac.at/adressbuch/adressbuch/suche?suchtext="+mnr+" ?"
31         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"
32         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"
33         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"
34
35         att = [{
36               "text": "Um dir das durchwühlen durch die 500+ LVA-Channels zu erleichtern: Was studierst du? (Mehrfachauswahl möglich; Wird nicht gespeichert)",
37               "actions": [
38                 {
39                   "name": "Ich bin nicht die verlinkte Person :(",
40                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_not_person", "mnr":mnr, "user_id":data["user_id"] } }
41                 }, {
42                   "name": "Software-Engineering :tada:",
43                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bse", "mnr":mnr, "user_id":data["user_id"] } }
44                 }, {
45                   "name": "Medieninformatik :tada:",
46                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bme", "mnr":mnr, "user_id":data["user_id"] } }
47                 }, {
48                   "name": "Medizinische Informatik :tada:",
49                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bmz", "mnr":mnr, "user_id":data["user_id"] } }
50                 }, {
51                   "name": "Technische Informatik :tada:",
52                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bti", "mnr":mnr, "user_id":data["user_id"] } }
53                 }, {
54                   "name": "Anderes Informatik Studium :tada:",
55                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_other", "mnr":mnr, "user_id":data["user_id"] } }
56                 }, {
57                   "name": "Wirtschaftsinformatik :tada:",
58                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_bwi", "mnr":mnr, "user_id":data["user_id"] } }
59                 }
60               ]
61             },
62           ]
63
64         # Make it in_channel/persistent only of talking to self of to bot.
65         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:
66             att[0]["actions"][0]["integration"]["context"]["persistent"] = True
67             request.respond(200, {"response_type":"in_channel", "text":msg, "attachments":att})
68         else:
69             c = self.bot.api.create_dm_channel_with(data['user_id'])
70             att[0]["actions"][0]["integration"]["context"]["persistent"] = True
71             p = self.bot.api.create_post(c['id'], msg, props={"from_webhook":"true", "attachments":att})
72             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"]
73             request.cmd_respond_text_temp(msg)
74
75
76
77     def on_POST_interactive(self, request, data):
78         # /inskriprion and buttonclick were triggered by diffrent users.
79         if data["context"]["user_id"] != data["user_id"]:
80             request.respond(200, {})
81             return
82
83         team_id = 'sswtb6oqciyyfmkibh6mjz479w'
84         chans_default=["1nq6h1fuftng7c651qra5ntp3c","e1c1k3h4nbb6xmerww5fqyrffe","k6jmp4nnm7drieg74r7qzihrgy","saig8etyt7riznrryxkafcbaso","8qfbjhha17y7m8bmkwwmr7mcby"]
85         chans_ti=["1nq6h1fuftng7c651qra5ntp3c","cfce951nkb8mt8ckee3z3w6iyw","e1c1k3h4nbb6xmerww5fqyrffe","k6jmp4nnm7drieg74r7qzihrgy","ihdpxumdsjgzfdxjkih8mzpxrr","8qfbjhha17y7m8bmkwwmr7mcby","saig8etyt7riznrryxkafcbaso"]
86         chans_winf=["1nq6h1fuftng7c651qra5ntp3c","cfce951nkb8mt8ckee3z3w6iyw","e1c1k3h4nbb6xmerww5fqyrffe","k6jmp4nnm7drieg74r7qzihrgy","xt7pwj4esjbhbbm7fohboqdume","51n3wsq7hiff7yd593w6mfnorw","saig8etyt7riznrryxkafcbaso","84skhwgpqtdbmenzriyruqjxuA"]
87
88         if data["context"]["action"] == "click_not_person":
89             msg = "Oh. :( Probiers mit der korrekten Matrikelnummer erneut ``/inskription <korrekte Matrikelnummer>`` :)"
90             import pprint
91             pprint.pprint(data)
92             if "persistent" in data["context"]:
93                 request.respond(200, {"update":{"message":msg, "props":{}}})
94             else:
95                 request.respond(200, {"ephemeral_text": msg})
96
97
98         elif data["context"]["action"] == "click_bse":
99             # join user to channels.
100             msg = "Soso, Software engineering also.\n\nDu wurdest in folgende Channels geadded:"
101             for cid in chans_default:
102                 c = self.bot.api.get_channel(cid)
103                 self.bot.api.add_user_to_team(team_id, data["user_id"])
104                 self.bot.api.add_user_to_channel(c["id"], data["user_id"])
105                 msg += "\n + ~"+c["name"]
106
107             # set email addr
108             self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
109             msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
110             request.respond(200, {"ephemeral_text": msg})
111
112         elif data["context"]["action"] == "click_bme":
113             # join user to channels.
114             msg = "Aha, Medieeninformatik, sehr gut!\n\nDu wurdest in folgende Channels geadded:"
115             for cid in chans_default:
116                 c = self.bot.api.get_channel(cid)
117                 self.bot.api.add_user_to_team(team_id, data["user_id"])
118                 self.bot.api.add_user_to_channel(c["id"], data["user_id"])
119                 msg += "\n + ~"+c["name"]
120
121             # set email addr
122             self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
123             msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
124             request.respond(200, {"ephemeral_text": msg})
125
126         elif data["context"]["action"] == "click_bmz":
127             # join user to channels.
128             msg = "Yay, Medizinische Informatik ftw.\n\nDu wurdest in folgende Channels geadded:"
129             for cid in chans_default:
130                 c = self.bot.api.get_channel(cid)
131                 self.bot.api.add_user_to_team(team_id, data["user_id"])
132                 self.bot.api.add_user_to_channel(c["id"], data["user_id"])
133                 msg += "\n + ~"+c["name"]
134
135             # set email addr
136             self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
137             msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
138             request.respond(200, {"ephemeral_text": msg})
139
140         elif data["context"]["action"] == "click_bti":
141             # join user to channels.
142             msg = "Technische Informatik. 31337!\n\nDu wurdest in folgende Channels geadded:"
143             for cid in chans_ti:
144                 c = self.bot.api.get_channel(cid)
145                 self.bot.api.add_user_to_team(team_id, data["user_id"])
146                 self.bot.api.add_user_to_channel(c["id"], data["user_id"])
147                 msg += "\n + ~"+c["name"]
148
149             # set email addr
150             self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
151             msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
152             request.respond(200, {"ephemeral_text": msg})
153
154         elif data["context"]["action"] == "click_bwi":
155             # join user to channels.
156             msg = "May t3h ca$h be with you!\n\nDu wurdest in folgende Channels geadded:"
157             for cid in chans_winf:
158                 c = self.bot.api.get_channel(cid)
159                 self.bot.api.add_user_to_team(team_id, data["user_id"])
160                 self.bot.api.add_user_to_channel(c["id"], data["user_id"])
161                 msg += "\n + ~"+c["name"]
162
163             # set email addr
164             self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
165             msg += "\nDes weiteren wurde deine email-adresse wurde zu ``e"+data["context"]["mnr"]+"@student.tuwien.ac.at`` geändert. Bitte bestätige diese ASAP."
166             request.respond(200, {"ephemeral_text": msg})
167
168         elif data["context"]["action"] == "click_other":
169             # set email addr
170             self.bot.api.patch_user(data["user_id"], {"email":"e"+data["context"]["mnr"]+"@student.tuwien.ac.at"})
171
172             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."
173             self.bot.api.add_user_to_team(team_id, data["user_id"])
174
175             request.respond(200, {"ephemeral_text": msg})