Software /
code /
prosody-modules
Annotate
mod_support_contact/mod_support_contact.lua @ 777:e5413b66aeec
mod_support_contact: Use module:send()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 05 Aug 2012 02:33:29 +0100 |
parent | 100:999a4b3e699b |
child | 986:8b1250df82e8 |
rev | line source |
---|---|
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- mod_support_contact.lua |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- Config options: |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 -- support_contact = "support@hostname"; -- a JID |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- support_contact_nick = "Support!"; -- roster nick |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- support_contact_group = "Users being supported!"; -- the roster group in the support contact's roster |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local host = module:get_host(); |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local support_contact = module:get_option("support_contact") or "support@"..host; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local support_contact_nick = module:get_option("support_contact_nick") or "Support"; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local support_contact_group = module:get_option("support_contact_group") or "Users"; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 if not(support_contact and support_contact_nick) then return; end |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local rostermanager = require "core.rostermanager"; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local datamanager = require "util.datamanager"; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local jid_split = require "util.jid".split; |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
19 local st = require "util.stanza"; |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 module:hook("user-registered", function(event) |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 module:log("debug", "Adding support contact"); |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 local groups = support_contact_group and {[support_contact_group] = true;} or {}; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 local node, host = event.username, event.host; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local jid = node and (node..'@'..host) or host; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local roster; |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
30 roster = rostermanager.load_roster(node, host); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
31 if hosts[host] then |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
32 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
33 else |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
34 roster[support_contact] = {subscription = "from", ask = "subscribe", name = support_contact_nick, groups = {}}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
35 end |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
36 rostermanager.save_roster(node, host, roster); |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 node, host = jid_split(support_contact); |
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
40 if hosts[host] then |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
41 roster = rostermanager.load_roster(node, host); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
42 roster[jid] = {subscription = "both", groups = groups}; |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
43 rostermanager.save_roster(node, host, roster); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
44 rostermanager.roster_push(node, host, jid); |
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
45 else |
777
e5413b66aeec
mod_support_contact: Use module:send()
Matthew Wild <mwild1@gmail.com>
parents:
100
diff
changeset
|
46 module:send(st.presence({from=jid, to=support_contact, type="subscribe"})); |
100
999a4b3e699b
mod_support_contact: Added support for remote support contact.
Waqas Hussain <waqas20@gmail.com>
parents:
1
diff
changeset
|
47 end |
1
21e089282b8f
mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 end); |