author | Mikael Berthe <mikael@lilotux.net> |
Fri, 03 Apr 2015 22:49:15 +0200 | |
changeset 71 | 63ee968309d4 |
parent 66 | d9c00a9fe9d5 |
permissions | -rw-r--r-- |
0 | 1 |
#! /usr/bin/env lua |
2 |
||
66
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
3 |
-- McBot / mcabbot project |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
4 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
5 |
-- Copyright (C) 2010-2012 Mikael Berthe <mikael@lilotux.net> |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
6 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
7 |
-- This program is free software; you can redistribute it and/or modify |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
8 |
-- 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:
64
diff
changeset
|
9 |
-- the Free Software Foundation; either version 2 of the License, or (at |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
10 |
-- your option) any later version. |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
11 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
12 |
-- 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:
64
diff
changeset
|
13 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
64
diff
changeset
|
14 |
|
0 | 15 |
local commands = {} |
16 |
||
17 |
function trim(s) |
|
18 |
return s:match("^%s*(.-)%s*$") |
|
19 |
end |
|
20 |
function rtrim(s) |
|
21 |
return s:gsub("%s+$", "") |
|
22 |
end |
|
23 |
||
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
24 |
function string.starts(String, Start) |
0 | 25 |
return string.sub(String, 1, string.len(Start)) == Start |
26 |
end |
|
27 |
||
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
28 |
function mcbot_register_command (name, object) |
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
29 |
commands[name] = object |
0 | 30 |
end |
31 |
||
18
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
32 |
function mcbot_get_command_list () |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
33 |
return commands |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
34 |
end |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
35 |
|
21 | 36 |
require "cmds.help" |
0 | 37 |
require "cmds.wtf" |
38 |
require "cmds.calc" |
|
39 |
require "cmds.spell" |
|
40 |
require "cmds.dict" |
|
54 | 41 |
require "cmds.littre" |
0 | 42 |
require "cmds.misc" |
3 | 43 |
require "cmds.xep" |
31 | 44 |
require "cmds.rfc" |
6
7cf014d0d206
Add command bts/bug (mcabber_bts)
Mikael Berthe <mikael@lilotux.net>
parents:
3
diff
changeset
|
45 |
require "cmds.mcabber_bts" |
23 | 46 |
require "cmds.bofh" |
25
788c62c29e18
Add a simple xmpp command
Mikael Berthe <mikael@lilotux.net>
parents:
23
diff
changeset
|
47 |
require "cmds.xmpp" |
35 | 48 |
require "cmds.tvcal" |
64
62248d5fbb24
Add shortenurl module, based on isbear's code
Mikael Berthe <mikael@lilotux.net>
parents:
54
diff
changeset
|
49 |
require "cmds.shortenurl" |
0 | 50 |
|
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
51 |
function process (line, botdata, muc, cmdprefix) |
0 | 52 |
local n |
53 |
line = trim(line) |
|
26
c12be727375b
Do not require ':' or ',' after the bot name
Mikael Berthe <mikael@lilotux.net>
parents:
25
diff
changeset
|
54 |
line, n = line:gsub("^"..botdata.nickname.."[,:]?%s+", "") |
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
55 |
if muc and n ~= 1 then |
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
56 |
if cmdprefix and line:starts(cmdprefix) then |
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
57 |
line = line:sub(string.len(cmdprefix)+1) |
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
58 |
line = line:gsub("^%s*", "") |
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
59 |
else |
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
60 |
return nil, nil |
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
61 |
end |
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
26
diff
changeset
|
62 |
end |
0 | 63 |
|
64 |
local cmd, arg |
|
65 |
cmd = line:match("^(%w+)%s*[!]*$") |
|
66 |
if not cmd then |
|
67 |
-- Check if there are arguments |
|
68 |
cmd, arg = line:match("^(%w+)%s+(.*)") |
|
69 |
end |
|
70 |
if cmd then |
|
18
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
71 |
local lccmd = cmd:lower() |
16
064a50911e05
Update command infrastructure
Mikael Berthe <mikael@lilotux.net>
parents:
6
diff
changeset
|
72 |
for name, obj in pairs(commands) do |
18
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
73 |
if lccmd == name then |
615c9b336207
Pass command to the callback functions
Mikael Berthe <mikael@lilotux.net>
parents:
16
diff
changeset
|
74 |
return obj.cmd(arg, botdata, cmd) |
0 | 75 |
end |
19 | 76 |
if obj.aliases then |
77 |
for i, alias in ipairs(obj.aliases) do |
|
78 |
if lccmd == alias then |
|
79 |
return obj.cmd(arg, botdata, cmd) |
|
80 |
end |
|
81 |
end |
|
82 |
end |
|
0 | 83 |
end |
84 |
else |
|
85 |
-- Ignore smileys |
|
86 |
if line:match("^[:;8]'?%-?[D()|/\\%[%]pPoO$@]+%s*$") then return nil,nil end |
|
87 |
if line:match("^^^%s*$") then return nil,nil end |
|
88 |
end |
|
89 |
return "I don't understand, Sir" |
|
90 |
end |