mcbot/cmds/littre.lua
changeset 56 a7c6c2b3454b
parent 55 7f235c928661
child 66 d9c00a9fe9d5
equal deleted inserted replaced
55:7f235c928661 56:a7c6c2b3454b
     2 local littre = { ["desc"] = "French Dictionnary Littré" }
     2 local littre = { ["desc"] = "French Dictionnary Littré" }
     3 
     3 
     4 function littre.cmd (args)
     4 function littre.cmd (args)
     5     if not args then return nil, "Give me a word, please" end
     5     if not args then return nil, "Give me a word, please" end
     6     -- Be careful as we pass it as an argument to a shell command
     6     -- Be careful as we pass it as an argument to a shell command
     7     local word = string.match(args, "^([%wàäâéèëêïîöôùüûç]+)[%s%?%.%!]*$")
     7     local word = string.match(args, "^([%wàäâéèëêïîöôùüûç' -]+)[%s%?%.%!]*$")
     8     if not word then return nil, "Can you repeat please?" end
     8     if not word then return nil, "Can you repeat please?" end
     9 
     9 
    10     local cmd = "/usr/bin/sdcv "..word.." 2> /dev/null"
    10     local cmd = '/usr/bin/sdcv --non-interactive -- "'..word..'" 2> /dev/null'
    11     local fh = io.popen(cmd)
    11     local fh = io.popen(cmd)
    12     result = fh:read("*a")  -- read littre output
    12     result = fh:read("*a")  -- read littre output
    13     fh:close()
    13     fh:close()
    14     if not result or result:match("^$") then return nil, "littre: No output" end
    14     if not result or result:match("^$") then return nil, "littre: No output" end
    15 
    15