Software /
code /
prosody
Comparison
plugins/mod_watchregistrations.lua @ 4391:71083327f608
mod_watchregistrations: Update to pass default options to module:get_option(), and reformat the code a little
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 12 Oct 2011 03:48:48 +0100 |
parent | 3540:bc139431830b |
child | 4453:7dc743378e1e |
comparison
equal
deleted
inserted
replaced
4390:5e84fb3c4ba0 | 4391:71083327f608 |
---|---|
7 -- | 7 -- |
8 | 8 |
9 | 9 |
10 local host = module:get_host(); | 10 local host = module:get_host(); |
11 | 11 |
12 local registration_watchers = module:get_option("registration_watchers") | 12 local registration_watchers = module:get_option("registration_watchers", module:get_option("admins", {})); |
13 or module:get_option("admins") or {}; | 13 local registration_notification = module:get_option("registration_notification", "User $username just registered on $host from $ip"); |
14 | |
15 local registration_alert = module:get_option("registration_notification") or "User $username just registered on $host from $ip"; | |
16 | 14 |
17 local st = require "util.stanza"; | 15 local st = require "util.stanza"; |
18 | 16 |
19 module:hook("user-registered", | 17 module:hook("user-registered", function (user) |
20 function (user) | 18 module:log("debug", "Notifying of new registration"); |
21 module:log("debug", "Notifying of new registration"); | 19 local message = st.message{ type = "chat", from = host } |
22 local message = st.message{ type = "chat", from = host } | 20 :tag("body") |
23 :tag("body") | 21 :text(registration_alert:gsub("%$(%w+)", function (v) |
24 :text(registration_alert:gsub("%$(%w+)", | 22 return user[v] or user.session and user.session[v] or nil; |
25 function (v) return user[v] or user.session and user.session[v] or nil; end)); | 23 end)); |
26 | 24 for _, jid in ipairs(registration_watchers) do |
27 for _, jid in ipairs(registration_watchers) do | 25 module:log("debug", "Notifying %s", jid); |
28 module:log("debug", "Notifying %s", jid); | 26 message.attr.to = jid; |
29 message.attr.to = jid; | 27 core_route_stanza(hosts[host], message); |
30 core_route_stanza(hosts[host], message); | 28 end |
31 end | 29 end); |
32 end); |