Comparison

plugins/mod_watchregistrations.lua @ 1201:9d5c1b2cf89c

mod_watchregistrations: New plugin to send a message to admins when a new user registers
author Matthew Wild <mwild1@gmail.com>
date Tue, 26 May 2009 04:51:05 +0100
child 1206:3ec37e678b46
comparison
equal deleted inserted replaced
1200:57a72472e1bc 1201:9d5c1b2cf89c
1
2 local host = module:get_host();
3
4 local config = require "core.configmanager";
5
6 local registration_watchers = config.get(host, "core", "registration_watchers")
7 or config.get(host, "core", "admin") or {};
8
9 local registration_alert = config.get(host, "core", "registration_notification") or "User $username just registered on $host from $ip";
10
11 local st = require "util.stanza";
12
13 module:add_event_hook("user-registered", function (user)
14 module:log("debug", "Notifying of new registration");
15 local message = st.message{ type = "chat", from = host }
16 :tag("body")
17 :text(registration_alert:gsub("%$(%w+)",
18 function (v) return user[v] or user.session and user.session[v] or nil; end));
19
20 for _, jid in ipairs(registration_watchers) do
21 module:log("debug", "Notifying %s", jid);
22 message.attr.to = jid;
23 core_route_stanza(hosts[host], message);
24 end
25 end);