9 |
9 |
10 function new(stream, config) |
10 function new(stream, config) |
11 if not stream then |
11 if not stream then |
12 error("riddim.new(): Verse stream required as first parameter", 2); |
12 error("riddim.new(): Verse stream required as first parameter", 2); |
13 end |
13 end |
14 return setmetatable({ stream = stream, config = config or {} }, 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"); |
19 self:add_plugin("groupchat"); |
73 function riddim_mt:send_message(to, text, formatted_text) |
73 function riddim_mt:send_message(to, text, formatted_text) |
74 self:send(st.message({ to = to, type = "chat" }):tag("body"):text(text)); |
74 self:send(st.message({ to = to, type = "chat" }):tag("body"):text(text)); |
75 end |
75 end |
76 |
76 |
77 function riddim_mt:add_plugin(name) |
77 function riddim_mt:add_plugin(name) |
78 require("riddim.plugins."..name); |
78 if not self.plugins[name] then |
79 return riddim.plugins[name](self); |
79 self.plugins[name] = require("riddim.plugins."..name); |
|
80 return riddim.plugins[name](self); |
|
81 end |
80 end |
82 end |
81 |
83 |
82 -- Built-in bot starter |
84 -- Built-in bot starter |
83 if not (... and package.loaded[...] ~= nil) then |
85 if not (... and package.loaded[...] ~= nil) then |
84 require "verse.client"; |
86 require "verse.client"; |