Software /
code /
prosody-modules
Comparison
mod_support_room/mod_support_room.lua @ 3426:f72aa8840042
mod_support_room: Module that invites newly registered users to a room
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 03 Jan 2019 12:06:09 +0100 |
comparison
equal
deleted
inserted
replaced
3425:461429e0db58 | 3426:f72aa8840042 |
---|---|
1 local mm = require "core.modulemanager"; | |
2 local st = require "util.stanza"; | |
3 local jid_host, jid_prep = import("util.jid", "host", "prep"); | |
4 | |
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"); | |
9 | |
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); |