25 end |
25 end |
26 end); |
26 end); |
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 not tonumber(xepnum) then -- Search for an XEP |
33 if xepnum:match("^(%d+) ex%S* (%d+)$") then |
33 if xepnum:match("^(%d+) ex%S* (%d+)$") then |
34 local num, example = xepnum:match("^(%d+) ex%S* (%d+)$"); |
34 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); |
35 return "http://xmpp.org/extensions/xep-"..string.rep("0", 4-num:len())..num..".html#example-"..tostring(example); |
36 end |
36 end |
37 local results = {}; |
37 local results = {}; |
38 for x, xep in pairs(xeps) do |
38 for x, xep in pairs(xeps) do |
39 name = " "..xep.name:lower().." "; |
39 name = " "..xep.name:lower().." "; |
40 if name:match(xepnum:lower():gsub("%-", "%%-")) then |
40 if name:match(xepnum:lower():gsub("%-", "%%-")) then |
41 table.insert(results, x); |
41 table.insert(results, x); |
42 --return commands.xep(msg, x); |
42 --return commands.xep(msg, x); |
43 end |
|
44 end |
|
45 if #results == 0 then |
|
46 return "Sorry, I couldn't find a match"; |
|
47 elseif #results == 1 then |
|
48 command.param = results[1]; |
|
49 return handle_xep_command(command); |
|
50 else |
|
51 -- We have more than one match |
|
52 local ret = "Multiple matches:"; |
|
53 for _, x in ipairs(results) do |
|
54 local xepnum = tostring(tonumber(x)); |
|
55 xepnum = string.rep("0", 4-x:len())..x; |
|
56 local xep = xeps[tostring(x)]; |
|
57 ret = string.format("%s XEP-%s: %s%s", ret, xep.number, xep.name, ((_ < #results) and ",") or ""); |
|
58 if _ > 5 then ret = ret .. " " .. (#results - 5) .. " more"; break; end |
|
59 end |
|
60 return ret; |
|
61 end |
|
62 end |
43 end |
63 -- Check that xepnum is a valid number |
44 end |
64 xepnum = tostring(tonumber(xepnum)); |
45 if #results == 0 then |
65 if not xepnum then return "What XEP? or enter a search string."; end |
46 return "Sorry, I couldn't find a match"; |
66 -- Expand to full 4 char number |
47 elseif #results == 1 then |
67 xepnum = string.rep("0", 4-xepnum:len())..xepnum; |
48 command.param = results[1]; |
68 xep = xeps[tostring(xepnum)]; |
49 return handle_xep_command(command); |
69 if not xep then return "Sorry, I don't think there is a XEP-"..xepnum; end |
50 else |
70 return "XEP-"..xep.number..": "..xep.name.." is "..xep.type.." ("..xep.status..", "..xep.updated..") See: http://xmpp.org/extensions/xep-"..xep.number..".html"; |
51 -- We have more than one match |
|
52 local ret = "Multiple matches:"; |
|
53 for _, x in ipairs(results) do |
|
54 local xepnum = tostring(tonumber(x)); |
|
55 xepnum = string.rep("0", 4-x:len())..x; |
|
56 local xep = xeps[tostring(x)]; |
|
57 ret = string.format("%s XEP-%s: %s%s", ret, xep.number, xep.name, ((_ < #results) and ",") or ""); |
|
58 if _ > 5 then ret = ret .. " " .. (#results - 5) .. " more"; break; end |
|
59 end |
|
60 return ret; |
|
61 end |
|
62 end |
|
63 -- Check that xepnum is a valid number |
|
64 xepnum = tostring(tonumber(xepnum)); |
|
65 if not xepnum then return "What XEP? or enter a search string."; end |
|
66 -- Expand to full 4 char number |
|
67 xepnum = string.rep("0", 4-xepnum:len())..xepnum; |
|
68 xep = xeps[tostring(xepnum)]; |
|
69 if not xep then return "Sorry, I don't think there is a XEP-"..xepnum; end |
|
70 return "XEP-"..xep.number..": "..xep.name.." is "..xep.type.." ("..xep.status..", "..xep.updated..") See: http://xmpp.org/extensions/xep-"..xep.number..".html"; |
71 end |
71 end |
72 |
72 |
73 function parse_xeps(t) |
73 function parse_xeps(t) |
74 if not t then return nil; end |
74 if not t then return nil; end |
75 local currxep = {}; |
75 local currxep = {}; |
76 for b in string.gmatch(t,"<xep>(.-)</xep>") do |
76 for b in string.gmatch(t,"<xep>(.-)</xep>") do |
77 for k,v in string.gmatch(b,"<(%w+)>(.-)</%1>") do |
77 for k,v in string.gmatch(b,"<(%w+)>(.-)</%1>") do |
78 currxep[k] = v; |
78 currxep[k] = v; |
79 end |
79 end |
80 xeps[currxep.number] = { }; |
80 xeps[currxep.number] = { }; |
81 for k, v in pairs(currxep) do xeps[currxep.number][k] = v end |
81 for k, v in pairs(currxep) do xeps[currxep.number][k] = v end |
82 end |
82 end |
83 xeps["0028"] = { number = "0028", name = "XSF Plans for World Domination", type="Top Secret", status = "Hidden", updated = "Work ongoing" }; |
83 xeps["0028"] = { number = "0028", name = "XSF Plans for World Domination", type="Top Secret", status = "Hidden", updated = "Work ongoing" }; |
84 return true; |
84 return true; |
85 end |
85 end |