Software /
code /
prosody
Annotate
plugins/mod_watchregistrations.lua @ 2706:c2dde8bda3fe
prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 22 Feb 2010 01:48:07 +0000 |
parent | 1654:0ae73e3d306f |
child | 2923:b7049746bd29 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
1 -- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
4 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1251
diff
changeset
|
8 |
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
|
9 |
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 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
|
11 |
1654
0ae73e3d306f
mod_watchregistrations: Updated to use module:get_option instead of configmanager
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
12 local registration_watchers = module:get_option("registration_watchers") |
0ae73e3d306f
mod_watchregistrations: Updated to use module:get_option instead of configmanager
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
13 or module:get_option("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
|
14 |
1654
0ae73e3d306f
mod_watchregistrations: Updated to use module:get_option instead of configmanager
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
15 local registration_alert = module:get_option("registration_notification") or "User $username just registered on $host from $ip"; |
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
|
16 |
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 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
|
18 |
1251
302582b827ed
mod_watchregistrations: Use module:hook instead of module:add_event_hook
Waqas Hussain <waqas20@gmail.com>
parents:
1206
diff
changeset
|
19 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
|
20 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
|
21 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
|
22 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
|
23 :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
|
24 :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
|
25 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
|
26 |
9d5c1b2cf89c
mod_watchregistrations: New plugin to send a message to admins when a new user registers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 end); |