# HG changeset patch # User Chris # Date 1274362341 -3600 # Node ID 3df63aaba9e31f3c83a067d4bd8aeb24093f66a5 # Parent 7bb53dcf93d413e96d5c5d43ed1199ecc94f0673 Decouple plugins from base implementation (in particular no plugins are now loaded by default) diff -r 7bb53dcf93d4 -r 3df63aaba9e3 init.lua --- a/init.lua Fri May 14 14:23:03 2010 +0100 +++ b/init.lua Thu May 20 14:32:21 2010 +0100 @@ -16,10 +16,6 @@ -- self.conn is ready for stanzas function riddim_mt:start() - self:add_plugin("groupchat"); - self:add_plugin("commands"); - self:add_plugin("ping"); - self:add_plugin("tell"); self:event("started"); self.stream:hook("stanza", function (stanza) local body = stanza:get_child("body"); @@ -120,7 +116,7 @@ c:hook("incoming-raw", print); end - for _, plugin in ipairs(config.plugins or {"ping"}) do + for _, plugin in ipairs(config.plugins or {}) do b:add_plugin(plugin); end @@ -130,15 +126,6 @@ presence:add_child(b:caps()) end b:send(presence); - for k, v in pairs(config.autojoin or {}) do - if type(k) == "number" then - b:join_room(v); - elseif type(k) == "string" then - if type(v) == "string" then - b:join_room(k, v); - end - end - end end); c:hook("binding-success", function () b:start(); end) diff -r 7bb53dcf93d4 -r 3df63aaba9e3 plugins/commands.lua --- a/plugins/commands.lua Fri May 14 14:23:03 2010 +0100 +++ b/plugins/commands.lua Thu May 20 14:32:21 2010 +0100 @@ -1,16 +1,12 @@ require "util.xstanza" function riddim.plugins.commands(bot) - local function handle_message(message) - -- Parse message body - end - local command_pattern = "^%"..(bot.config.command_prefix or "@").."([%a%-%_%d]+)(%s?)(.*)$"; local function process_command(event) - local body, sender = event.body, event.sender; + local body = event.body; if not body then return; end - if event.delay then return; end -- Don't process old messages + if event.delay then return; end -- Don't process old messages from groupchat local command, hasparam, param = body:match(command_pattern); @@ -24,10 +20,10 @@ local command_event = { command = command, param = param, - sender = sender, + sender = event.sender, stanza = event.stanza, reply = event.reply, - room = event.room, + room = event.room, -- groupchat support }; local ret = bot:event("commands/"..command, command_event); if type(ret) == "string" then @@ -37,9 +33,10 @@ end end - -- Hook messages to bot and from rooms, fire a command event on the bot + -- Hook messages sent to bot, fire a command event on the bot bot:hook("message", process_command); + -- Support groupchat plugin: Hook messages from rooms that the bot joins bot:hook("groupchat/joining", function (room) room:hook("message", process_command); end); diff -r 7bb53dcf93d4 -r 3df63aaba9e3 plugins/groupchat.lua --- a/plugins/groupchat.lua Fri May 14 14:23:03 2010 +0100 +++ b/plugins/groupchat.lua Thu May 20 14:32:21 2010 +0100 @@ -8,6 +8,18 @@ function riddim.plugins.groupchat(bot) bot.rooms = {}; + + bot:hook("started", function () + for k, v in pairs(bot.config.autojoin or {}) do + if type(k) == "number" then + bot:join_room(v); + elseif type(k) == "string" then + if type(v) == "string" then + bot:join_room(k, v); + end + end + end + end); bot.stream:hook("stanza", function (stanza) local room_jid = jid.bare(stanza.attr.from);