author | Mikael Berthe <mikael@lilotux.net> |
Tue, 27 Nov 2012 16:36:17 +0100 | |
changeset 67 | 5c756a9d7d8c |
parent 16 | 064a50911e05 |
permissions | -rw-r--r-- |
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
1 |
|
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
2 |
local spell = { desc = "Spell checker" } |
0 | 3 |
|
4 |
local function check (text, lang) |
|
5 |
local fname = os.tmpname() |
|
6 |
local fh = io.open(fname, "w") |
|
7 |
||
8 |
fh:write(text) |
|
9 |
fh:close() |
|
10 |
||
11 |
local cmd = "/usr/bin/enchant -a "..fname |
|
12 |
if lang and not lang:match("[^_%w]") then |
|
13 |
cmd = cmd.." -d "..lang |
|
14 |
end |
|
15 |
fh = io.popen(cmd) |
|
16 |
fh:read("*l") -- skip header |
|
17 |
result = fh:read("*a") -- read spellchecker output |
|
18 |
fh:close() |
|
19 |
||
20 |
os.remove(fname) |
|
21 |
return result |
|
22 |
end |
|
23 |
||
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
24 |
function spell.cmd (args) |
0 | 25 |
if not args then return nil, "What do you want me to spellcheck?" end |
26 |
local r |
|
27 |
local l, s = string.match(args, "^%s*-d%s?([%w_]+)%s+(.*)%s*$") |
|
28 |
if l then |
|
29 |
r = check(s, l) |
|
30 |
else |
|
31 |
r = check(args) |
|
32 |
end |
|
33 |
return r:gsub("\n+$", "") |
|
34 |
end |
|
35 |
||
36 |
mcbot_register_command("spell", spell) |