# HG changeset patch # User Kim Alvefur # Date 1546513569 -3600 # Node ID f72aa88400421d34253274d1f7b0105432ff1131 # Parent 461429e0db58d8a238d5d68b2375f311f54158c4 mod_support_room: Module that invites newly registered users to a room diff -r 461429e0db58 -r f72aa8840042 mod_support_room/README.markdown --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_support_room/README.markdown Thu Jan 03 12:06:09 2019 +0100 @@ -0,0 +1,24 @@ +# Introduction + +This module adds newly registered users as members to a specified MUC +room and sends them an invite. In a way, this is similar in purpose to +[mod_support_contact] and [mod_default_bookmarks]. + +# Example + + VirtualHost"example.com" + modules_enabled = { "support_room" } + support_room = "room@muc.example.com" + support_room_inviter = "support@example.com" + support_room_reason = "Invite new users to the support room" + + Component "muc.example.com" + +# Compatibility + +This module + + Version Works + --------- ------- + 0.11.x Yes + 0.10.x No diff -r 461429e0db58 -r f72aa8840042 mod_support_room/mod_support_room.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_support_room/mod_support_room.lua Thu Jan 03 12:06:09 2019 +0100 @@ -0,0 +1,26 @@ +local mm = require "core.modulemanager"; +local st = require "util.stanza"; +local jid_host, jid_prep = import("util.jid", "host", "prep"); + +local invite_to_room = assert(jid_prep(module:get_option_string(module.name)), + "The option " .. module.name .. " must be set"); +local inviter = module:get_option_string(module.name .. "_inviter", module.host); +local invite_reason = module:get_option_string(module.name .. "_reason"); + +module:hook("user-registered", function (event) + local user_jid = event.username .. "@" .. event.host; + local muc = mm.get_module(jid_host(invite_to_room), "muc"); + if not muc then + module:log("error", "There is no MUC service '%s'", jid_host(invite_to_room)); + return; + end + local room = muc.get_room_from_jid(invite_to_room); + if room then + room:set_affiliation(true, user_jid, "member", invite_reason, { reserved_nickname = event.username }); + -- Invite them to the room too + module:send(st.message({ from = inviter, to = user_jid }) + :tag("x", { xmlns = "jabber:x:conference", jid = invite_to_room, reason = invite_reason }):up()); + else + module:log("error", "The room %s does not exist, can't invite newly registered user", invite_to_room); + end +end);