author | Mikael Berthe <mikael@lilotux.net> |
Thu, 15 Apr 2010 06:56:28 +0200 | |
changeset 14 | 5c3ef7c5ba6c |
parent 6 | 7cf014d0d206 |
child 16 | 064a50911e05 |
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 |
function mcbot_register_command (name, callback) |
|
17 |
commands[name] = callback |
|
18 |
end |
|
19 |
||
20 |
require "cmds.wtf" |
|
21 |
require "cmds.calc" |
|
22 |
require "cmds.spell" |
|
23 |
require "cmds.dict" |
|
24 |
require "cmds.misc" |
|
3 | 25 |
require "cmds.xep" |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
3
diff
changeset
|
26 |
require "cmds.mcabber_bts" |
0 | 27 |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
28 |
function process (line, botdata, muc) |
0 | 29 |
local n |
30 |
line = trim(line) |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
31 |
line, n = line:gsub("^"..botdata.nickname.."[,: ]%s+", "") |
0 | 32 |
if muc and n ~= 1 then return nil, nil end |
33 |
||
34 |
local cmd, arg |
|
35 |
cmd = line:match("^(%w+)%s*[!]*$") |
|
36 |
if not cmd then |
|
37 |
-- Check if there are arguments |
|
38 |
cmd, arg = line:match("^(%w+)%s+(.*)") |
|
39 |
end |
|
40 |
if cmd then |
|
41 |
for name, f in pairs(commands) do |
|
42 |
if cmd and cmd:lower() == name then |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
43 |
return f(arg, botdata) |
0 | 44 |
end |
45 |
end |
|
46 |
else |
|
47 |
-- Ignore smileys |
|
48 |
if line:match("^[:;8]'?%-?[D()|/\\%[%]pPoO$@]+%s*$") then return nil,nil end |
|
49 |
if line:match("^^^%s*$") then return nil,nil end |
|
50 |
end |
|
51 |
return "I don't understand, Sir" |
|
52 |
end |