annotate mod_support_contact/mod_support_contact.lua @ 1:21e089282b8f

mod_support_contact: Initial commit.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 11 Sep 2009 01:23:19 +0500
parents
children 999a4b3e699b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 module:hook("user-registered", function(event)
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 module:log("debug", "Adding support contact");
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 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
24
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 local node, host = event.username, event.host;
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 local jid = node and (node..'@'..host) or host;
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local roster;
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 roster = rostermanager.load_roster(node, host) or {};
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}};
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 datamanager.store(node, host, "roster", roster);
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 node, host = jid_split(support_contact);
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 roster = rostermanager.load_roster(node, host) or {};
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 roster[jid] = {subscription = "both", groups = groups};
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 datamanager.store(node, host, "roster", roster);
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 rostermanager.roster_push(node, host, jid);
21e089282b8f mod_support_contact: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 end);