author | Mikael Berthe <mikael@lilotux.net> |
Thu, 15 Apr 2010 19:21:41 +0200 | |
changeset 18 | 615c9b336207 |
parent 16 | 064a50911e05 |
child 19 | 96e08713cb6a |
permissions | -rw-r--r-- |
0 | 1 |
#! /usr/bin/env lua |
2 |
||
3 |
local commands = {} |
|
4 |
||
5 |
function trim(s) |
|
6 |
return s:match("^%s*(.-)%s*$") |
|
7 |
end |
|
8 |
function rtrim(s) |
|
9 |
return s:gsub("%s+$", "") |
|
10 |
end |
|
11 |
||
12 |
function string.starts(String,Start) |
|
13 |
return string.sub(String, 1, string.len(Start)) == Start |
|
14 |
end |
|
15 |
||
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
16 |
function mcbot_register_command (name, object) |
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
17 |
commands[name] = object |
0 | 18 |
end |
19 |
||
18
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
20 |
function mcbot_get_command_list () |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
21 |
return commands |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
22 |
end |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
23 |
|
0 | 24 |
require "cmds.wtf" |
25 |
require "cmds.calc" |
|
26 |
require "cmds.spell" |
|
27 |
require "cmds.dict" |
|
28 |
require "cmds.misc" |
|
3 | 29 |
require "cmds.xep" |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
3
diff
changeset
|
30 |
require "cmds.mcabber_bts" |
0 | 31 |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
32 |
function process (line, botdata, muc) |
0 | 33 |
local n |
34 |
line = trim(line) |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
35 |
line, n = line:gsub("^"..botdata.nickname.."[,: ]%s+", "") |
0 | 36 |
if muc and n ~= 1 then return nil, nil end |
37 |
||
38 |
local cmd, arg |
|
39 |
cmd = line:match("^(%w+)%s*[!]*$") |
|
40 |
if not cmd then |
|
41 |
-- Check if there are arguments |
|
42 |
cmd, arg = line:match("^(%w+)%s+(.*)") |
|
43 |
end |
|
44 |
if cmd then |
|
18
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
45 |
local lccmd = cmd:lower() |
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
46 |
for name, obj in pairs(commands) do |
18
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
47 |
if lccmd == name then |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
48 |
return obj.cmd(arg, botdata, cmd) |
0 | 49 |
end |
50 |
end |
|
51 |
else |
|
52 |
-- Ignore smileys |
|
53 |
if line:match("^[:;8]'?%-?[D()|/\\%[%]pPoO$@]+%s*$") then return nil,nil end |
|
54 |
if line:match("^^^%s*$") then return nil,nil end |
|
55 |
end |
|
56 |
return "I don't understand, Sir" |
|
57 |
end |