# HG changeset patch # User Matthew Wild # Date 1299926140 0 # Node ID 22670e551879927267a8d25466e051ca7004e03d # Parent 2d7c29310a28aa764edb58cdb545d942abfcf1d4 plugins.pubsub2room: Fix reliance on Atom payloads, and add an extra 'data' parameter for additional non-payload data diff -r 2d7c29310a28 -r 22670e551879 plugins/pubsub2room.lua --- a/plugins/pubsub2room.lua Fri Mar 11 22:37:06 2011 +0100 +++ b/plugins/pubsub2room.lua Sat Mar 12 10:35:40 2011 +0000 @@ -10,10 +10,18 @@ }; --]] +local st = require "util.stanza"; + -- FIXME Should this really be here? local extractor_mt = { __index = function (t, k) - local n = t.stanza; + local n; + if k:match("^data%.") then + k = k:gsub("^data.", ""); + n = t.data; + else + n = t.stanza; + end for x in k:gmatch("[^.]+") do n = n:get_child(x); if not n then return end @@ -22,9 +30,8 @@ end }; -local function new_extractor(stanza, ...) - local st = stanza:get_child(...) - return st and setmetatable({ stanza = st }, extractor_mt) or nil; +local function new_extractor(stanza, data) + return stanza and setmetatable({ stanza = stanza, data = data }, extractor_mt) or nil; end function riddim.plugins.pubsub2room(bot) @@ -35,8 +42,8 @@ bot:hook("pubsub/event", function(event) local conf = config[event.from .. "#" .. event.node]; local room = bot.rooms[conf.room]; - local entry = event.item and new_extractor(event.item, "entry", "http://www.w3.org/2005/Atom") - -- FIXME or forever be limited to Atom! + local data = st.stanza(""):tag("id"):text(event.item.attr.id); + local entry = event.item and new_extractor(event.item.tags[1], data) if not conf or not entry or not room then return end local message = conf.template:gsub("%${([^}]+)}", entry);