# HG changeset patch # User Mikael Berthe # Date 1319370857 -7200 # Node ID be04d7241ef66b98f76a441b4073a074d82c37bc # Parent 0e29690ab5d93357e910168d792f0c7415253fb2 New command: littre diff -r 0e29690ab5d9 -r be04d7241ef6 mcbot/cmds/littre.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcbot/cmds/littre.lua Sun Oct 23 13:54:17 2011 +0200 @@ -0,0 +1,23 @@ + +local littre = { ["desc"] = "French Dictionnary Littré" } + +function littre.cmd (args) + if not args then return nil, "Give me a word, please" end + -- Be careful as we pass it as an argument to a shell command + local word = string.match(args, "^([%wàäâéèëêïîöôùüû]+)[%s%?%.%!]*$") + if not word then return nil, "Can you repeat please?" end + + local cmd = "/usr/bin/sdcv "..word.." 2> /dev/null" + local fh = io.popen(cmd) + result = fh:read("*a") -- read littre output + fh:close() + if not result or result:match("^$") then return nil, "littre: No output" end + + -- Let's filter out whitespace. + result = result:gsub("[ \t]+\n", "\n"):gsub("\n\n\n+", "\n\n") + -- Trim trailing newlines + result = result:gsub("\n+$", "") + return result +end + +mcbot_register_command("littre", littre) diff -r 0e29690ab5d9 -r be04d7241ef6 mcbot/mcbot_engine.lua --- a/mcbot/mcbot_engine.lua Sun Oct 23 13:45:29 2011 +0200 +++ b/mcbot/mcbot_engine.lua Sun Oct 23 13:54:17 2011 +0200 @@ -26,6 +26,7 @@ require "cmds.calc" require "cmds.spell" require "cmds.dict" +require "cmds.littre" require "cmds.misc" require "cmds.xep" require "cmds.rfc"