mod_watchregistrations: Fixed an undefined global access (thanks Medics).
[prosody.git] / plugins / mod_watchregistrations.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9
10 local host = module:get_host();
11
12 local registration_watchers = module:get_option("registration_watchers", module:get_option("admins", {}));
13 local registration_notification = module:get_option("registration_notification", "User $username just registered on $host from $ip");
14
15 local st = require "util.stanza";
16
17 module:hook("user-registered", function (user)
18         module:log("debug", "Notifying of new registration");
19         local message = st.message{ type = "chat", from = host }
20                 :tag("body")
21                         :text(registration_notification:gsub("%$(%w+)", function (v)
22                                 return user[v] or user.session and user.session[v] or nil;
23                         end));
24         for _, jid in ipairs(registration_watchers) do
25                 module:log("debug", "Notifying %s", jid);
26                 message.attr.to = jid;
27                 core_route_stanza(hosts[host], message);
28         end
29 end);