author | Mikael Berthe <mikael@lilotux.net> |
Thu, 15 Apr 2010 18:35:13 +0200 | |
changeset 15 | 203b49c24dde |
parent 1 | cca972635e5e |
child 24 | 77a72b227d59 |
permissions | -rw-r--r-- |
0 | 1 |
|
2 |
local home = os.getenv("HOME") |
|
3 |
package.path = package.path.. |
|
4 |
";"..home.."/.mcabber/lua/?.lua".. |
|
5 |
";"..home.."/.mcabber/lua/mcbot/?.lua" |
|
6 |
home = nil |
|
7 |
||
8 |
require "mcbot.mcbot_engine" |
|
9 |
||
10 |
local mcabbot = {} |
|
11 |
mcabbot.nickname = "McBot" |
|
12 |
mcabbot.jid = "mcabbot@lilotux.net" |
|
13 |
||
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
14 |
local function hk_message_in (h) |
0 | 15 |
local perso = false |
16 |
local muc = false |
|
17 |
local message = h.message |
|
18 |
if h.groupchat and h.groupchat == "true" then |
|
19 |
muc = true |
|
20 |
end |
|
21 |
if muc == true then |
|
22 |
if h.delayed == "" and h.attention and h.attention == "true" then |
|
23 |
if h.resource and h.resource ~= mcabbot.nickname then |
|
24 |
perso = true |
|
25 |
end |
|
26 |
end |
|
27 |
else |
|
28 |
if h.jid ~= mcabbot.jid then |
|
29 |
perso = true |
|
30 |
end |
|
31 |
end |
|
32 |
if perso == true then |
|
33 |
local cmd, msg |
|
34 |
if muc == true then |
|
35 |
cmd = "say_to -q "..h.jid.." "..h.resource..": " |
|
36 |
else |
|
37 |
cmd = "say_to -q "..h.jid.."/"..h.resource.." " |
|
38 |
end |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
39 |
mcabbot.message = h |
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
40 |
local res, errmsg = process(message, mcabbot, muc) |
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
41 |
mcabbot.message = nil |
0 | 42 |
if res then |
43 |
msg = res |
|
44 |
elseif errmsg then |
|
45 |
msg = "! " .. errmsg |
|
46 |
end |
|
47 |
if (msg) then main.run(cmd..msg) end |
|
48 |
end |
|
49 |
end |
|
50 |
||
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
51 |
main.hook("hook-post-message-in", hk_message_in) |