Software /
code /
prosody
Annotate
plugins/mod_watchregistrations.lua @ 1251:302582b827ed
mod_watchregistrations: Use module:hook instead of module:add_event_hook
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 31 May 2009 01:14:57 +0500 |
parent | 1206:3ec37e678b46 |
child | 1522:569d58d21612 |
rev | line source |
---|---|
1201
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local host = module:get_host(); |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local config = require "core.configmanager"; |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local registration_watchers = config.get(host, "core", "registration_watchers") |
1206
3ec37e678b46
mod_watchregistrations: admin -> admins
Matthew Wild <mwild1@gmail.com>
parents:
1201
diff
changeset
|
7 or config.get(host, "core", "admins") or {}; |
1201
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local registration_alert = config.get(host, "core", "registration_notification") or "User $username just registered on $host from $ip"; |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local st = require "util.stanza"; |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
1251
302582b827ed
mod_watchregistrations: Use module:hook instead of module:add_event_hook
Waqas Hussain <waqas20@gmail.com>
parents:
1206
diff
changeset
|
13 module:hook("user-registered", |
302582b827ed
mod_watchregistrations: Use module:hook instead of module:add_event_hook
Waqas Hussain <waqas20@gmail.com>
parents:
1206
diff
changeset
|
14 function (user) |
1201
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 module:log("debug", "Notifying of new registration"); |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local message = st.message{ type = "chat", from = host } |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 :tag("body") |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 :text(registration_alert:gsub("%$(%w+)", |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 function (v) return user[v] or user.session and user.session[v] or nil; end)); |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 for _, jid in ipairs(registration_watchers) do |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 module:log("debug", "Notifying %s", jid); |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 message.attr.to = jid; |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 core_route_stanza(hosts[host], message); |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end); |