comparison 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
comparison
equal deleted inserted replaced
0:010452cfaf53 1:21e089282b8f
1 -- mod_support_contact.lua
2 --
3 -- Config options:
4 -- support_contact = "support@hostname"; -- a JID
5 -- support_contact_nick = "Support!"; -- roster nick
6 -- support_contact_group = "Users being supported!"; -- the roster group in the support contact's roster
7
8 local host = module:get_host();
9
10 local support_contact = module:get_option("support_contact") or "support@"..host;
11 local support_contact_nick = module:get_option("support_contact_nick") or "Support";
12 local support_contact_group = module:get_option("support_contact_group") or "Users";
13
14 if not(support_contact and support_contact_nick) then return; end
15
16 local rostermanager = require "core.rostermanager";
17 local datamanager = require "util.datamanager";
18 local jid_split = require "util.jid".split;
19
20 module:hook("user-registered", function(event)
21 module:log("debug", "Adding support contact");
22
23 local groups = support_contact_group and {[support_contact_group] = true;} or {};
24
25 local node, host = event.username, event.host;
26 local jid = node and (node..'@'..host) or host;
27 local roster;
28
29 roster = rostermanager.load_roster(node, host) or {};
30 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}};
31 datamanager.store(node, host, "roster", roster);
32
33 node, host = jid_split(support_contact);
34
35 roster = rostermanager.load_roster(node, host) or {};
36 roster[jid] = {subscription = "both", groups = groups};
37 datamanager.store(node, host, "roster", roster);
38 rostermanager.roster_push(node, host, jid);
39 end);