Mercurial > prosody-hg
comparison plugins/mod_watchregistrations.lua @ 4909:01bfb9a76660
mod_watchregistrations: Convert JID list to a set, and prep before use to fix traceback on invalid JIDs (thanks sMi)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 24 May 2012 18:52:47 +0100 |
| parents | 7dc743378e1e |
| children | b2006c1cfa85 |
comparison
equal
deleted
inserted
replaced
| 4908:8c5b5ebaacb0 | 4909:01bfb9a76660 |
|---|---|
| 6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
| 7 -- | 7 -- |
| 8 | 8 |
| 9 | 9 |
| 10 local host = module:get_host(); | 10 local host = module:get_host(); |
| 11 local jid_prep = require "util.jid".prep; | |
| 11 | 12 |
| 12 local registration_watchers = module:get_option("registration_watchers", module:get_option("admins", {})); | 13 local registration_watchers = module:get_option_set("registration_watchers", module:get_option("admins", {})) / jid_prep; |
| 13 local registration_notification = module:get_option("registration_notification", "User $username just registered on $host from $ip"); | 14 local registration_notification = module:get_option("registration_notification", "User $username just registered on $host from $ip"); |
| 14 | 15 |
| 15 local st = require "util.stanza"; | 16 local st = require "util.stanza"; |
| 16 | 17 |
| 17 module:hook("user-registered", function (user) | 18 module:hook("user-registered", function (user) |
| 19 local message = st.message{ type = "chat", from = host } | 20 local message = st.message{ type = "chat", from = host } |
| 20 :tag("body") | 21 :tag("body") |
| 21 :text(registration_notification:gsub("%$(%w+)", function (v) | 22 :text(registration_notification:gsub("%$(%w+)", function (v) |
| 22 return user[v] or user.session and user.session[v] or nil; | 23 return user[v] or user.session and user.session[v] or nil; |
| 23 end)); | 24 end)); |
| 24 for _, jid in ipairs(registration_watchers) do | 25 for jid in registration_watchers do |
| 25 module:log("debug", "Notifying %s", jid); | 26 module:log("debug", "Notifying %s", jid); |
| 26 message.attr.to = jid; | 27 message.attr.to = jid; |
| 27 core_route_stanza(hosts[host], message); | 28 core_route_stanza(hosts[host], message); |
| 28 end | 29 end |
| 29 end); | 30 end); |
