--- a/mcabbot.lua Sun Apr 11 18:13:18 2010 +0200
+++ b/mcabbot.lua Sun Apr 11 22:03:12 2010 +0200
@@ -11,7 +11,7 @@
mcabbot.nickname = "McBot"
mcabbot.jid = "mcabbot@lilotux.net"
-function mcabbot.message_in (h)
+local function hk_message_in (h)
local perso = false
local muc = false
local message = h.message
@@ -36,7 +36,9 @@
else
cmd = "say_to -q "..h.jid.."/"..h.resource.." "
end
- local res, errmsg = process(message, mcabbot.nickname, muc)
+ mcabbot.message = h
+ local res, errmsg = process(message, mcabbot, muc)
+ mcabbot.message = nil
if res then
msg = res
elseif errmsg then
@@ -46,4 +48,4 @@
end
end
-main.hook("hook-post-message-in", mcabbot.message_in)
+main.hook("hook-post-message-in", hk_message_in)
--- a/mcbot/mcbot_engine.lua Sun Apr 11 18:13:18 2010 +0200
+++ b/mcbot/mcbot_engine.lua Sun Apr 11 22:03:12 2010 +0200
@@ -23,10 +23,10 @@
require "cmds.dict"
require "cmds.misc"
-function process (line, botname, muc)
+function process (line, botdata, muc)
local n
line = trim(line)
- line, n = line:gsub("^"..botname.."[,: ]%s+", "")
+ line, n = line:gsub("^"..botdata.nickname.."[,: ]%s+", "")
if muc and n ~= 1 then return nil, nil end
local cmd, arg
@@ -38,7 +38,7 @@
if cmd then
for name, f in pairs(commands) do
if cmd and cmd:lower() == name then
- return f(arg)
+ return f(arg, botdata)
end
end
else
--- a/mcbot/mcbot_shell.lua Sun Apr 11 18:13:18 2010 +0200
+++ b/mcbot/mcbot_shell.lua Sun Apr 11 22:03:12 2010 +0200
@@ -3,10 +3,11 @@
require "mcbot_engine"
local function mcbot_mainloop (BotName)
+ local data = { ["nickname"] = BotName }
while true do
local l = io.stdin:read'*l'
if l == nil then break end
- local res, errmsg = process(l, BotName, false)
+ local res, errmsg = process(l, data, false)
if res then
print(res)
else