From 3b86be1941e051d47deb027828f765e172a3542b Mon Sep 17 00:00:00 2001 From: Someone Date: Sat, 1 Apr 2023 23:41:47 +0200 Subject: [PATCH] modules/WSGuestControl.py --- modules/WSGuestControl.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/WSGuestControl.py b/modules/WSGuestControl.py index cc99c67..8ab628f 100644 --- a/modules/WSGuestControl.py +++ b/modules/WSGuestControl.py @@ -9,16 +9,18 @@ from inspect import cleandoc # pylint: disable=wrong-import-position +from AbstractPublicWS import AbstractPublicWS from AbstractWSHandler import AbstractWSHandler -class WSGuestControl(AbstractWSHandler): - NAME = "guestcontrol" +class WSGuestControl(AbstractWSHandler, AbstractPublicWS): + TRIGGER=NAME = "guestcontrol" - def __init__(self, email_rex_str, guest_teams_and_channels): + def __init__(self, email_rex_str, guest_teams_and_channels, primary_teamid): super().__init__() self.email_rex = re.compile(email_rex_str) self.guest_teams_and_channels = guest_teams_and_channels + self.primary_teamid = primary_teamid def on_WS_EVENT(self, data): @@ -46,10 +48,9 @@ class WSGuestControl(AbstractWSHandler): self.bot.api.demote_a_user(user["id"]) for team_id, chan_ids in self.guest_teams_and_channels.items(): - for chan_id, excluded_user_ids in chan_ids.items(): - if not user["id"] in excluded_user_ids: - self.bot.api.add_user_to_team(team_id, user["id"], exc=False) - self.bot.api.add_user_to_channel(chan_id, user["id"], exc=False) + for chan_id in chan_ids: + self.bot.api.add_user_to_team(team_id, user["id"], exc=False) + self.bot.api.add_user_to_channel(chan_id, user["id"], exc=False) chan = self.bot.api.create_dm_channel_with(user["id"]) self.bot.api.create_post(chan["id"], cleandoc(""" @@ -65,3 +66,14 @@ class WSGuestControl(AbstractWSHandler): else: print("WSGuestControl: Profile change we dont care about.") + + + def on_public_POST(self, request, data): + import pprint + pprint.pprint(data) + + # todo: test if email seems valid. + + channels = [ch_id for tid,ch_id_set in self.guest_teams_and_channels.items() for ch_id in ch_id_set] + message = "Welcome to FSInf-Mattermost. Guest accounts are very limited due to privacy, copyright and licencing reasons and are deleted after 30 das of inactivity. Set your student's eMail address (eXXXXXXXX@student.tuwien.ac.at) as soon as possible." + request.respond_public(200, self.bot.api.invite_guests_to_team_by_email(self.primary_teamid, data["email"], channels, message)) -- 2.43.0