mcabbot.lua
changeset 0 89add07d6fe4
child 1 cca972635e5e
equal deleted inserted replaced
-1:000000000000 0:89add07d6fe4
       
     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 
       
    14 function mcabbot.message_in (h)
       
    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
       
    39         local res, errmsg = process(message, mcabbot.nickname, muc)
       
    40         if res then
       
    41             msg = res
       
    42         elseif errmsg then
       
    43             msg = "! " .. errmsg
       
    44         end
       
    45         if (msg) then main.run(cmd..msg) end
       
    46     end
       
    47 end
       
    48 
       
    49 main.hook("hook-post-message-in", mcabbot.message_in)