local home = os.getenv("HOME")
package.path = package.path..
";"..home.."/.mcabber/lua/?.lua"..
";"..home.."/.mcabber/lua/mcbot/?.lua"
home = nil
require "mcbot.mcbot_engine"
local mcabbot = {}
mcabbot.nickname = "McBot"
mcabbot.jid = "mcbot@lilotux.net"
mcabbot.cmdprefix = "%%"
local function hk_subscription (h)
if h.type == "subscribe" then
-- Let's authorize them...
main.run("authorization allow "..h.jid)
-- ... and subscribe to their own presence
main.run("authorization request "..h.jid)
return 1
elseif h.type == "unsubscribe" or h.type == "unsubscribed" then
main.run("authorization cancel "..h.jid)
end
return 0
end
local function hk_message_in (h)
local perso = false
local muc = false
local message = h.message
if h.error and h.error == "true" then return end
if h.groupchat and h.groupchat == "true" then
muc = true
end
if muc == true then
if h.delayed == "" then
if mcabbot.cmdprefix and message:starts(mcabbot.cmdprefix) then
perso = true
elseif h.attention and h.attention == "true" and
h.resource and h.resource ~= mcabbot.nickname then
perso = true
end
end
else
if h.jid ~= mcabbot.jid then
perso = true
end
end
if perso == true then
local cmd, msg
if muc == true then
cmd = "say_to -q "..h.jid.." "..h.resource..": "
else
cmd = "say_to -q "..h.jid.."/"..h.resource.." "
end
mcabbot.message = h
local res, errmsg = process(message, mcabbot, muc, mcabbot.cmdprefix)
mcabbot.message = nil
if res then
msg = res
elseif errmsg then
msg = "! " .. errmsg
end
if (msg) then main.run(cmd..msg) end
end
end
main.hook("hook-post-message-in", hk_message_in)
main.hook("hook-subscription", hk_subscription)