comparison mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua @ 4772:85d4ab318d66

mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
author Matthew Wild <mwild1@gmail.com>
date Tue, 16 Nov 2021 15:08:09 +0000
parents
children c83bc703825d
comparison
equal deleted inserted replaced
4771:e227af629736 4772:85d4ab318d66
1 local jid = require "util.jid";
2 local set = require "util.set";
3
4 local active_affiliations = set.new({ "member", "admin", "owner" });
5
6 module:hook("muc-occupant-joined", function (event)
7 local room, occupant = event.room, event.occupant;
8 local user_jid = occupant.bare_jid;
9 local user_affiliation = room:get_affiliation(user_jid);
10 if not active_affiliations:contains(user_affiliation) then
11 return;
12 end
13 local aff_data = event.room:get_affiliation_data(user_jid);
14 if not aff_data then
15 local reserved_nick = jid.resource(occupant.nick);
16 module:log("debug", "Automatically reserving nickname '%s' for <%s>", reserved_nick, user_jid);
17 room:set_affiliation_data(user_jid, "reserved_nickname", reserved_nick);
18 end
19 end);