init.lua

changeset 14
3df63aaba9e3
parent 11
7bb53dcf93d4
child 15
22e6c003a83a
equal deleted inserted replaced
11:7bb53dcf93d4 14:3df63aaba9e3
14 return setmetatable({ stream = stream, config = config or {}, plugins = {} }, riddim_mt); 14 return setmetatable({ stream = stream, config = config or {}, plugins = {} }, riddim_mt);
15 end 15 end
16 16
17 -- self.conn is ready for stanzas 17 -- self.conn is ready for stanzas
18 function riddim_mt:start() 18 function riddim_mt:start()
19 self:add_plugin("groupchat");
20 self:add_plugin("commands");
21 self:add_plugin("ping");
22 self:add_plugin("tell");
23 self:event("started"); 19 self:event("started");
24 self.stream:hook("stanza", function (stanza) 20 self.stream:hook("stanza", function (stanza)
25 local body = stanza:get_child("body"); 21 local body = stanza:get_child("body");
26 local event = { 22 local event = {
27 sender = { jid = stanza.attr.from }; 23 sender = { jid = stanza.attr.from };
118 114
119 if config.debug then 115 if config.debug then
120 c:hook("incoming-raw", print); 116 c:hook("incoming-raw", print);
121 end 117 end
122 118
123 for _, plugin in ipairs(config.plugins or {"ping"}) do 119 for _, plugin in ipairs(config.plugins or {}) do
124 b:add_plugin(plugin); 120 b:add_plugin(plugin);
125 end 121 end
126 122
127 b:hook("started", function () 123 b:hook("started", function ()
128 local presence = verse.presence() 124 local presence = verse.presence()
129 if b.caps then 125 if b.caps then
130 presence:add_child(b:caps()) 126 presence:add_child(b:caps())
131 end 127 end
132 b:send(presence); 128 b:send(presence);
133 for k, v in pairs(config.autojoin or {}) do
134 if type(k) == "number" then
135 b:join_room(v);
136 elseif type(k) == "string" then
137 if type(v) == "string" then
138 b:join_room(k, v);
139 end
140 end
141 end
142 end); 129 end);
143 130
144 c:hook("binding-success", function () b:start(); end) 131 c:hook("binding-success", function () b:start(); end)
145 132
146 if config.connect_host then 133 if config.connect_host then

mercurial