author | Mikael Berthe <mikael@lilotux.net> |
Wed, 21 Oct 2015 19:10:04 +0200 | |
changeset 73 | 2ca07b5226c1 |
parent 66 | d9c00a9fe9d5 |
permissions | -rw-r--r-- |
66
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
1 |
|
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
2 |
-- This module is part of the McBot / mcabbot project |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
3 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
4 |
-- Copyright (C) 2010-2012 Mikael Berthe <mikael@lilotux.net> |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
5 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
6 |
-- This program is free software; you can redistribute it and/or modify |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
7 |
-- it under the terms of the GNU General Public License as published by |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
8 |
-- the Free Software Foundation; either version 2 of the License, or (at |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
9 |
-- your option) any later version. |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
10 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
11 |
-- Please check the license in the COPYING file at the root of the tree. |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
56
diff
changeset
|
12 |
-- |
54 | 13 |
|
14 |
local littre = { ["desc"] = "French Dictionnary Littré" } |
|
15 |
||
16 |
function littre.cmd (args) |
|
17 |
if not args then return nil, "Give me a word, please" end |
|
18 |
-- Be careful as we pass it as an argument to a shell command |
|
56
a7c6c2b3454b
littre: allow some more chars: space and ', -
Mikael Berthe <mikael@lilotux.net>
parents:
55
diff
changeset
|
19 |
local word = string.match(args, "^([%wàäâéèëêïîöôùüûç' -]+)[%s%?%.%!]*$") |
54 | 20 |
if not word then return nil, "Can you repeat please?" end |
21 |
||
56
a7c6c2b3454b
littre: allow some more chars: space and ', -
Mikael Berthe <mikael@lilotux.net>
parents:
55
diff
changeset
|
22 |
local cmd = '/usr/bin/sdcv --non-interactive -- "'..word..'" 2> /dev/null' |
54 | 23 |
local fh = io.popen(cmd) |
24 |
result = fh:read("*a") -- read littre output |
|
25 |
fh:close() |
|
26 |
if not result or result:match("^$") then return nil, "littre: No output" end |
|
27 |
||
28 |
-- Let's filter out whitespace. |
|
29 |
result = result:gsub("[ \t]+\n", "\n"):gsub("\n\n\n+", "\n\n") |
|
30 |
-- Trim trailing newlines |
|
31 |
result = result:gsub("\n+$", "") |
|
32 |
return result |
|
33 |
end |
|
34 |
||
35 |
mcbot_register_command("littre", littre) |