4 function riddim.plugins.xeps(bot) |
4 function riddim.plugins.xeps(bot) |
5 local http = require("net.http"); |
5 local http = require("net.http"); |
6 bot:hook("commands/xep", function(command) |
6 bot:hook("commands/xep", function(command) |
7 -- Cache XEP list for an hour |
7 -- Cache XEP list for an hour |
8 if os.difftime(os.time(), xeps_updated_at) > (60 * 60) then -- Not refreshed within 1 hour |
8 if os.difftime(os.time(), xeps_updated_at) > (60 * 60) then -- Not refreshed within 1 hour |
9 http.request('http://xmpp.org/extensions/xeps.xml', nil, function (data, code) |
9 http.request('https://xmpp.org/extensions/xeplist.xml', nil, function (data, code) |
10 if code ~= 200 then |
10 if code ~= 200 then |
11 if code > 0 then |
11 if code > 0 then |
12 command:reply("Received HTTP "..code.." error trying to fetch the XEP list"); |
12 command:reply("Received HTTP "..code.." error trying to fetch the XEP list"); |
13 else |
13 else |
14 command:reply("Unable to fetch the XEP list from xmpp.org: "..data:gsub("%-", " ")); |
14 command:reply("Unable to fetch the XEP list from xmpp.org: "..data:gsub("%-", " ")); |
31 if xeps_short[xepnum:lower()] then |
31 if xeps_short[xepnum:lower()] then |
32 xepnum = xeps_short[xepnum:lower()]; |
32 xepnum = xeps_short[xepnum:lower()]; |
33 elseif not tonumber(xepnum) then -- Search for an XEP |
33 elseif not tonumber(xepnum) then -- Search for an XEP |
34 if xepnum:match("^(%d+) ex%S* (%d+)$") then |
34 if xepnum:match("^(%d+) ex%S* (%d+)$") then |
35 local num, example = xepnum:match("^(%d+) ex%S* (%d+)$"); |
35 local num, example = xepnum:match("^(%d+) ex%S* (%d+)$"); |
36 return "http://xmpp.org/extensions/xep-"..string.rep("0", 4-num:len())..num..".html#example-"..tostring(example); |
36 return "https://xmpp.org/extensions/xep-"..string.rep("0", 4-num:len())..num..".html#example-"..tostring(example); |
37 end |
37 end |
38 local results = {}; |
38 local results = {}; |
39 for x, xep in pairs(xeps) do |
39 for x, xep in pairs(xeps) do |
40 name = " "..xep.name:lower().." "; |
40 name = " "..xep.name:lower().." "; |
41 if name:match(xepnum:lower():gsub("%-", "%%-")) then |
41 if name:match(xepnum:lower():gsub("%-", "%%-")) then |
66 if not xepnum then return "What XEP? or enter a search string."; end |
66 if not xepnum then return "What XEP? or enter a search string."; end |
67 -- Expand to full 4 char number |
67 -- Expand to full 4 char number |
68 xepnum = string.rep("0", 4-xepnum:len())..xepnum; |
68 xepnum = string.rep("0", 4-xepnum:len())..xepnum; |
69 xep = xeps[tostring(xepnum)]; |
69 xep = xeps[tostring(xepnum)]; |
70 if not xep then return "Sorry, I don't think there is a XEP-"..xepnum; end |
70 if not xep then return "Sorry, I don't think there is a XEP-"..xepnum; end |
71 return "XEP-"..xep.number..": "..xep.name.." is "..xep.type.." ("..xep.status..", "..xep.updated..") See: http://xmpp.org/extensions/xep-"..xep.number..".html"; |
71 return "XEP-"..xep.number..": "..xep.name.." is "..xep.type.." ("..xep.status..", "..xep.updated..") See: https://xmpp.org/extensions/xep-"..xep.number..".html"; |
72 end |
72 end |
73 |
73 |
74 function parse_xeps(t) |
74 function parse_xeps(t) |
75 if not t then return nil; end |
75 if not t then return nil; end |
76 local currxep = {}; |
76 local currxep = {}; |