equal
deleted
inserted
replaced
|
1 |
|
2 local function check (text, lang) |
|
3 local fname = os.tmpname() |
|
4 local fh = io.open(fname, "w") |
|
5 |
|
6 fh:write(text) |
|
7 fh:close() |
|
8 |
|
9 local cmd = "/usr/bin/enchant -a "..fname |
|
10 if lang and not lang:match("[^_%w]") then |
|
11 cmd = cmd.." -d "..lang |
|
12 end |
|
13 fh = io.popen(cmd) |
|
14 fh:read("*l") -- skip header |
|
15 result = fh:read("*a") -- read spellchecker output |
|
16 fh:close() |
|
17 |
|
18 os.remove(fname) |
|
19 return result |
|
20 end |
|
21 |
|
22 local function spell (args) |
|
23 if not args then return nil, "What do you want me to spellcheck?" end |
|
24 local r |
|
25 local l, s = string.match(args, "^%s*-d%s?([%w_]+)%s+(.*)%s*$") |
|
26 if l then |
|
27 r = check(s, l) |
|
28 else |
|
29 r = check(args) |
|
30 end |
|
31 return r:gsub("\n+$", "") |
|
32 end |
|
33 |
|
34 mcbot_register_command("spell", spell) |