plugins/xeps.lua

changeset 84
ce687757ce3d
parent 83
4a25cd97711d
child 85
7ec6df0e0ed0
equal deleted inserted replaced
83:4a25cd97711d 84:ce687757ce3d
1 local parse_xeps, xeps_updated_at; 1 local parse_xeps, xeps_updated_at;
2 local xeps = {}; 2 local xeps, xeps_short = {}, {};
3 3
4 function riddim.plugins.xeps(bot) 4 function riddim.plugins.xeps(bot)
5 require "net.httpclient_listener"; 5 require "net.httpclient_listener";
6 local http = require("net.http"); 6 local http = require("net.http");
7 bot:hook("commands/xep", function(command) 7 bot:hook("commands/xep", function(command)
27 end 27 end
28 28
29 function handle_xep_command(command) 29 function handle_xep_command(command)
30 local xepnum = command.param; 30 local xepnum = command.param;
31 if not xepnum then return "Please supply an XEP number or a search string :)"; end 31 if not xepnum then return "Please supply an XEP number or a search string :)"; end
32 if not tonumber(xepnum) then -- Search for an XEP 32 if xeps_short[xepnum:lower()] then
33 xepnum = xeps_short[xepnum:lower()];
34 elseif not tonumber(xepnum) then -- Search for an XEP
33 if xepnum:match("^(%d+) ex%S* (%d+)$") then 35 if xepnum:match("^(%d+) ex%S* (%d+)$") then
34 local num, example = xepnum:match("^(%d+) ex%S* (%d+)$"); 36 local num, example = xepnum:match("^(%d+) ex%S* (%d+)$");
35 return "http://xmpp.org/extensions/xep-"..string.rep("0", 4-num:len())..num..".html#example-"..tostring(example); 37 return "http://xmpp.org/extensions/xep-"..string.rep("0", 4-num:len())..num..".html#example-"..tostring(example);
36 end 38 end
37 local results = {}; 39 local results = {};
76 for b in string.gmatch(t,"<xep>(.-)</xep>") do 78 for b in string.gmatch(t,"<xep>(.-)</xep>") do
77 for k,v in string.gmatch(b,"<(%w+)>(.-)</%1>") do 79 for k,v in string.gmatch(b,"<(%w+)>(.-)</%1>") do
78 currxep[k] = v; 80 currxep[k] = v;
79 end 81 end
80 xeps[currxep.number] = { }; 82 xeps[currxep.number] = { };
81 for k, v in pairs(currxep) do xeps[currxep.number][k] = v end 83 for k, v in pairs(currxep) do
84 xeps[currxep.number][k] = v;
85 if xeps_short[currxep.shortname] == nil then
86 xeps_short[currxep.shortname] = currxep.number;
87 elseif xeps_short[currxep.shortname] then
88 xeps_short[currxep.shortname] = false; -- kill dupes
89 end
90 end
82 end 91 end
83 xeps["0028"] = { number = "0028", name = "XSF Plans for World Domination", type="Top Secret", status = "Hidden", updated = "Work ongoing" }; 92 xeps["0028"] = { number = "0028", name = "XSF Plans for World Domination", type="Top Secret", status = "Hidden", updated = "Work ongoing" };
84 return true; 93 return true;
85 end 94 end

mercurial