mod_muc_webchat_url: Fix default url
[prosody-modules.git] / mod_support_room / mod_support_room.lua
blobab79cc2f5d67265585e18368f0fd7df16833229d
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");
13 if not muc then
14 module:log("error", "There is no MUC service '%s'", jid_host(invite_to_room));
15 return;
16 end
17 local room = muc.get_room_from_jid(invite_to_room);
18 if room then
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());
23 else
24 module:log("error", "The room %s does not exist, can't invite newly registered user", invite_to_room);
25 end
26 end);