mcbot/cmds/xep.lua
changeset 16 064a50911e05
parent 11 4993fc6b1108
child 22 4b360fe207e6
equal deleted inserted replaced
15:203b49c24dde 16:064a50911e05
     3 
     3 
     4 -- The caching idea is borrowed from MattJ's riddim code,
     4 -- The caching idea is borrowed from MattJ's riddim code,
     5 -- and the function parse_xeps() as well.
     5 -- and the function parse_xeps() as well.
     6 
     6 
     7 local xeplisturl = "curl http://xmpp.org/extensions/xeps.xml"
     7 local xeplisturl = "curl http://xmpp.org/extensions/xeps.xml"
       
     8 
       
     9 local xep = { ["desc"] = "Lookup XEP database" }
     8 
    10 
     9 local xeps = {}
    11 local xeps = {}
    10 
    12 
    11 -- parse_xep() from Matthew Wild (aka MattJ)
    13 -- parse_xep() from Matthew Wild (aka MattJ)
    12 local function parse_xeps(t)
    14 local function parse_xeps(t)
    30     xeps_updated_at = now
    32     xeps_updated_at = now
    31     parse_xeps(xepdata)
    33     parse_xeps(xepdata)
    32 end
    34 end
    33 
    35 
    34 -- Deeply inspired by MattJ's riddim bot
    36 -- Deeply inspired by MattJ's riddim bot
    35 local function lookup_xep (xepstr)
    37 function xep.cmd (xepstr)
    36     if (xepstr) then
    38     if (xepstr) then
    37         xepstr = xepstr:gsub("[%s%?%.%!]+$", "")
    39         xepstr = xepstr:gsub("[%s%?%.%!]+$", "")
    38         local n = xepstr:upper():match("^XEP[%-%s]?(%d+)$")
    40         local n = xepstr:upper():match("^XEP[%-%s]?(%d+)$")
    39         if n then xepstr = n end
    41         if n then xepstr = n end
    40     end
    42     end
    73     r = r:gsub("\n$", "")
    75     r = r:gsub("\n$", "")
    74     if r ~= "" then return r; end
    76     if r ~= "" then return r; end
    75     return nil, "Sorry, not matching XEP found"
    77     return nil, "Sorry, not matching XEP found"
    76 end
    78 end
    77 
    79 
    78 mcbot_register_command("xep", lookup_xep)
    80 mcbot_register_command("xep", xep)