33 lines
1.2 KiB
Lua
33 lines
1.2 KiB
Lua
-- mod_vnc_muc_automember
|
|
--
|
|
|
|
-- Copyright (C) 2020 VNC - Virtual Network Consult AG
|
|
--
|
|
-- This file is MIT/X11 licensed.
|
|
--
|
|
-- A module to automatically add invited users as members
|
|
--
|
|
|
|
local st = require"util.stanza"
|
|
|
|
local muc_util = module:require "muc/util";
|
|
local valid_affiliations = muc_util.valid_affiliations;
|
|
|
|
-- When an invite is sent; add an affiliation for the invitee
|
|
module:hook("muc-invite", function(event)
|
|
local room = event.room;
|
|
local stanza = event.stanza;
|
|
local invitee = stanza.attr.to;
|
|
local affiliation = room:get_affiliation(invitee);
|
|
local invited_unaffiliated = valid_affiliations[affiliation or "none"] <= valid_affiliations.none;
|
|
if invited_unaffiliated then
|
|
local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user")
|
|
:get_child("invite").attr.from;
|
|
module:log("debug", "%s invited %s into members only room %s, granting membership",
|
|
from, invitee, room.jid);
|
|
-- This might fail; ignore for now
|
|
room:set_affiliation(true, invitee, "member", "Invited by " .. from);
|
|
room:save();
|
|
end
|
|
end);
|