# HG changeset patch # User Kim Alvefur # Date 1314232226 -7200 # Node ID 5a573f1d75928d4a06dd727ba9f7273434e2b049 # Parent b7f628541981908afdc7d6d5a3339b94727f8de1# Parent 00ad6fe8975e8d273c744d2d7ea820cdf0426b0a Merge diff -r 00ad6fe8975e -r 5a573f1d7592 plugins/invited.lua --- a/plugins/invited.lua Sun Jul 17 02:03:21 2011 +0200 +++ b/plugins/invited.lua Thu Aug 25 02:30:26 2011 +0200 @@ -1,13 +1,17 @@ +local xmlns_muc = "http://jabber.org/protocol/muc"; +local xmlns_muc_user = xmlns_muc .. "#user"; +local xmlns_jxc = "jabber:x:conference"; + function riddim.plugins.invited(bot) bot:hook("message", function(event) - local x = event.stanza:get_child("x", "http://jabber.org/protocol/muc#user"); + local x = event.stanza:get_child("x", xmlns_muc_user); if x then -- XEP 45 local invite = x:get_child("invite"); if invite then bot:join_room(event.stanza.attr.from); end else -- try XEP 249 - x = event.stanza:get_child("x", "jabber:x:conference"); + x = event.stanza:get_child("x", xmlns_jxc); if x and x.attr.jid then bot:join_room(x.attr.jid); end diff -r 00ad6fe8975e -r 5a573f1d7592 plugins/pubsub.lua --- a/plugins/pubsub.lua Sun Jul 17 02:03:21 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function riddim.plugins.pubsub(bot) - bot.stream:add_plugin("pubsub"); - bot.pubsub = bot.stream.pubsub; - - -- Maybe pubsub/event/ns/element or something? - bot.stream:hook("pubsub/event", function(event) - return bot:event("pubsub/event", event); - end); -end diff -r 00ad6fe8975e -r 5a573f1d7592 plugins/pubsub2room.lua --- a/plugins/pubsub2room.lua Sun Jul 17 02:03:21 2011 +0200 +++ b/plugins/pubsub2room.lua Thu Aug 25 02:30:26 2011 +0200 @@ -23,6 +23,11 @@ n = t.stanza; end for x in k:gmatch("[^.]+") do + local m, a = x:match("^([^@]*)@(.*)$"); + if m and a then + m = n:get_child(m); + return m and m.attr[a] or nil; + end n = n:get_child(x); if not n then return end end @@ -38,10 +43,10 @@ function riddim.plugins.pubsub2room(bot) local bare_jid = require "util.jid".bare; - bot:add_plugin("pubsub"); + bot.stream:add_plugin("pubsub"); local config = bot.config.pubsub2room; - bot:hook("pubsub/event", function(event) + bot.stream:hook("pubsub/event", function(event) local conf = config[event.from .. "#" .. event.node]; local room = bot.rooms[conf.room]; local data = st.stanza(""):tag("id"):text(event.item.attr.id); @@ -67,7 +72,7 @@ local jid = bare_jid(bot.stream.jid); for hostnode in pairs(config) do local host, node = hostnode:match("^([^#]+)#(.*)"); - bot.pubsub:subscribe(host, node, jid, print); + bot.stream.pubsub:subscribe(host, node, jid, print); end end); end diff -r 00ad6fe8975e -r 5a573f1d7592 plugins/topic.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/topic.lua Thu Aug 25 02:30:26 2011 +0200 @@ -0,0 +1,15 @@ +function riddim.plugins.topic(bot) + bot:hook("commands/topic", function(cmd) + local room = cmd.room; + if not room then return "This isn't a room!"; end + if not cmd.param then return room.subject or "No topic here"; end + room:set_subject(cmd.param); + end); + + bot:hook("commands/addtopic", function(cmd) + local room = cmd.room; + if not room then return "This isn't a room!"; end + if not cmd.param then return "What do you want me do add?"; end + room:set_subject((#room.subject>0 and room.subject .. cmd.param) or cmd.param) + end); +end diff -r 00ad6fe8975e -r 5a573f1d7592 plugins/xeps.lua --- a/plugins/xeps.lua Sun Jul 17 02:03:21 2011 +0200 +++ b/plugins/xeps.lua Thu Aug 25 02:30:26 2011 +0200 @@ -1,5 +1,5 @@ local parse_xeps, xeps_updated_at; -local xeps = {}; +local xeps, xeps_short = {}, {}; function riddim.plugins.xeps(bot) require "net.httpclient_listener"; @@ -27,59 +27,68 @@ end function handle_xep_command(command) - local xepnum = command.param; - if not xepnum then return "Please supply an XEP number or a search string :)"; end - if not tonumber(xepnum) then -- Search for an XEP - if xepnum:match("^(%d+) ex%S* (%d+)$") then - local num, example = xepnum:match("^(%d+) ex%S* (%d+)$"); - return "http://xmpp.org/extensions/xep-"..string.rep("0", 4-num:len())..num..".html#example-"..tostring(example); - end - local results = {}; - for x, xep in pairs(xeps) do - name = " "..xep.name:lower().." "; - if name:match(xepnum:lower():gsub("%-", "%%-")) then - table.insert(results, x); - --return commands.xep(msg, x); - end - end - if #results == 0 then - return "Sorry, I couldn't find a match"; - elseif #results == 1 then - command.param = results[1]; - return handle_xep_command(command); - else - -- We have more than one match - local ret = "Multiple matches:"; - for _, x in ipairs(results) do - local xepnum = tostring(tonumber(x)); - xepnum = string.rep("0", 4-x:len())..x; - local xep = xeps[tostring(x)]; - ret = string.format("%s XEP-%s: %s%s", ret, xep.number, xep.name, ((_ < #results) and ",") or ""); - if _ > 5 then ret = ret .. " " .. (#results - 5) .. " more"; break; end - end - return ret; - end + local xepnum = command.param; + if not xepnum then return "Please supply an XEP number or a search string :)"; end + if xeps_short[xepnum:lower()] then + xepnum = xeps_short[xepnum:lower()]; + elseif not tonumber(xepnum) then -- Search for an XEP + if xepnum:match("^(%d+) ex%S* (%d+)$") then + local num, example = xepnum:match("^(%d+) ex%S* (%d+)$"); + return "http://xmpp.org/extensions/xep-"..string.rep("0", 4-num:len())..num..".html#example-"..tostring(example); + end + local results = {}; + for x, xep in pairs(xeps) do + name = " "..xep.name:lower().." "; + if name:match(xepnum:lower():gsub("%-", "%%-")) then + table.insert(results, x); + --return commands.xep(msg, x); end - -- Check that xepnum is a valid number - xepnum = tostring(tonumber(xepnum)); - if not xepnum then return "What XEP? or enter a search string."; end - -- Expand to full 4 char number - xepnum = string.rep("0", 4-xepnum:len())..xepnum; - xep = xeps[tostring(xepnum)]; - if not xep then return "Sorry, I don't think there is a XEP-"..xepnum; end - return "XEP-"..xep.number..": "..xep.name.." is "..xep.type.." ("..xep.status..", "..xep.updated..") See: http://xmpp.org/extensions/xep-"..xep.number..".html"; + end + if #results == 0 then + return "Sorry, I couldn't find a match"; + elseif #results == 1 then + command.param = results[1]; + return handle_xep_command(command); + else + -- We have more than one match + local ret = "Multiple matches:"; + for _, x in ipairs(results) do + local xepnum = tostring(tonumber(x)); + xepnum = string.rep("0", 4-x:len())..x; + local xep = xeps[tostring(x)]; + ret = string.format("%s XEP-%s: %s%s", ret, xep.number, xep.name, ((_ < #results) and ",") or ""); + if _ > 5 then ret = ret .. " " .. (#results - 5) .. " more"; break; end + end + return ret; + end + end + -- Check that xepnum is a valid number + xepnum = tostring(tonumber(xepnum)); + if not xepnum then return "What XEP? or enter a search string."; end + -- Expand to full 4 char number + xepnum = string.rep("0", 4-xepnum:len())..xepnum; + xep = xeps[tostring(xepnum)]; + if not xep then return "Sorry, I don't think there is a XEP-"..xepnum; end + return "XEP-"..xep.number..": "..xep.name.." is "..xep.type.." ("..xep.status..", "..xep.updated..") See: http://xmpp.org/extensions/xep-"..xep.number..".html"; end function parse_xeps(t) -if not t then return nil; end -local currxep = {}; - for b in string.gmatch(t,"(.-)") do - for k,v in string.gmatch(b,"<(%w+)>(.-)") do - currxep[k] = v; - end + if not t then return nil; end + local currxep = {}; + for b in string.gmatch(t,"(.-)") do + for k,v in string.gmatch(b,"<(%w+)>(.-)") do + currxep[k] = v; + end + if xeps_short[currxep.shortname] == nil then + xeps_short[currxep.shortname] = currxep.number; + elseif xeps_short[currxep.shortname] then + xeps_short[currxep.shortname] = false; -- kill dupes + end xeps[currxep.number] = { }; - for k, v in pairs(currxep) do xeps[currxep.number][k] = v end - end + for k, v in pairs(currxep) do + xeps[currxep.number][k] = v; + end + end xeps["0028"] = { number = "0028", name = "XSF Plans for World Domination", type="Top Secret", status = "Hidden", updated = "Work ongoing" }; return true; end