From 894488cb1fefc5ce293a10f82a7223faf7c066cd Mon Sep 17 00:00:00 2001 From: Someone Date: Wed, 8 Dec 2021 19:38:38 +0100 Subject: [PATCH] [somebot] WS:GuestControl --- modules/WSGuestControl.py | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 modules/WSGuestControl.py diff --git a/modules/WSGuestControl.py b/modules/WSGuestControl.py new file mode 100644 index 0000000..b04dc50 --- /dev/null +++ b/modules/WSGuestControl.py @@ -0,0 +1,64 @@ +# Mattermost Bot module. +# Copyright (c) 2016-2021 by Someone (aka. Jan Vales ) +# published under MIT-License + +import pprint +import re + +from inspect import cleandoc + + +from AbstractWSHandler import * +class WSGuestControl(AbstractWSHandler): + NAME = "guestcontrol" + + + def __init__(self, email_rex_str, guest_teams_and_channels): + super().__init__() + + self.email_rex = re.compile(email_rex_str) + self.guest_teams_and_channels = guest_teams_and_channels + + + def on_WS_EVENT(self, data): + user = self.bot.api.get_user(data["data"]["user"]["id"]) + + # promote guest with correct email + if self.email_rex.match(user["email"]) and "system_guest" in user["roles"]: + print("WSGuestControl: Promoting guest.") + self.bot.api.promote_a_guest(user["id"]) + + c = self.bot.api.create_dm_channel_with(user["id"]) + self.bot.api.create_post(c["id"], cleandoc(""" + ### ``Your account has been converted to a FULL-USER account!`` + You are now able to use all the features mattermost and this instance has to offer! + # :thumbsup: + """)) + + # demote user with incorrect email (email no longer changable to invalid - delete this?) + elif not self.email_rex.match(user["email"]) and not "system_guest" in user["roles"]: + print("WSGuestControl: Demoting user.") + pprint.pprint(user) + self.bot.command_stats_inc("WSGuestControl: demote user -- should not happen?") + 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) + + c = self.bot.api.create_dm_channel_with(user["id"]) + self.bot.api.create_post(c["id"], cleandoc(""" + ## ``Confirm your student email to get full access to Mattermost`` + Your account is currently a [guest account](https://docs.mattermost.com/deployment/guest-accounts.html), which means your user expirience is limited due to privacy, copyright and licencing reasons and you are restricted to these channels: + * Beratung (Consultation) + * Guest-Talk + + Guest accounts are deleted after 30 days of inactivity. + + To gain full access to all channels and features you need to go to your Account Settings and change your email to ``eXXXXXXXX@student.tuwien.ac.at`` and then click on the link in the confirmation email. You will then get full access within an hour. + """)) + + else: + print("WSGuestControl: Profile change we dont care about.") -- 2.43.0