1 local mm
= require
"core.modulemanager";
2 local st
= require
"util.stanza";
3 local jid_host
, jid_prep
= import("util.jid", "host", "prep");
5 local invite_to_room
= assert(jid_prep(module
:get_option_string(module
.name
)),
6 "The option " .. module
.name
.. " must be set");
7 local inviter
= module
:get_option_string(module
.name
.. "_inviter", module
.host
);
8 local invite_reason
= module
:get_option_string(module
.name
.. "_reason");
10 module
:hook("user-registered", function (event
)
11 local user_jid
= event
.username
.. "@" .. event
.host
;
12 local muc
= mm
.get_module(jid_host(invite_to_room
), "muc");
14 module
:log("error", "There is no MUC service '%s'", jid_host(invite_to_room
));
17 local room
= muc
.get_room_from_jid(invite_to_room
);
19 room
:set_affiliation(true, user_jid
, "member", invite_reason
, { reserved_nickname
= event
.username
});
20 -- Invite them to the room too
21 module
:send(st
.message({ from
= inviter
, to
= user_jid
})
22 :tag("x", { xmlns
= "jabber:x:conference", jid
= invite_to_room
, reason
= invite_reason
}):up());
24 module
:log("error", "The room %s does not exist, can't invite newly registered user", invite_to_room
);