local spell = { desc = "Spell checker" }
local function check (text, lang)
local fname = os.tmpname()
local fh = io.open(fname, "w")
fh:write(text)
fh:close()
local cmd = "/usr/bin/enchant -a "..fname
if lang and not lang:match("[^_%w]") then
cmd = cmd.." -d "..lang
end
fh = io.popen(cmd)
fh:read("*l") -- skip header
result = fh:read("*a") -- read spellchecker output
fh:close()
os.remove(fname)
return result
end
function spell.cmd (args)
if not args then return nil, "What do you want me to spellcheck?" end
local r
local l, s = string.match(args, "^%s*-d%s?([%w_]+)%s+(.*)%s*$")
if l then
r = check(s, l)
else
r = check(args)
end
return r:gsub("\n+$", "")
end
mcbot_register_command("spell", spell)