print("base loaded") -- say("salut ca va\nou pas moi oui\ntruc de ouf"); function cmd(from, msg) -- say("you want me to do? okay... :"..msg) local chunk = loadstring(msg) local status, error = pcall(chunk) if (status) then -- say("succeeded!") else say(error) end end said_hooks = {} function said(from, msg) -- say("toi " ..from .." t'as dit "..msg) for k,v in pairs(said_hooks) do if (string.find(msg, k)) then v(from, msg) end end end function upon_topic(msg) data.topic = msg end function said_hook_add(hook_str, f) said_hooks[hook_str] = f end -- ===BEGIN b4l examples=== ou_manger = {ramen = 0, ["moulin a cafe"] = 0, taverne = 0, mcdo = 0, salade = 0, ramadan = 0} manger = {} function miam_labas(from, where) local value = ou_manger[where] -- print("INPUT xx"..where.."xx") -- print("VALUE xx"..value.."xx") if (not value and nil) then say("Je connais pas cet endroit "..where.." ,"..from) else manger[from] = where end end function miam_result() local t = {} local max = 0 for k,v in pairs(manger) do if (not t[v]) then t[v] = 0 end t[v] = t[v] + 1 if (t[v] > max) then max = t[v] end end if (max == 0) then say("On mange pas aujourd'hui...") return end local text for k,v in pairs(t) do if (v == max) then if (not text) then text = "On va manger a "..k else text = text.." ou a "..k end end end say(text) end function miam_purge() manger = {} end function miam_hook_mangeons(from, msg) local a, b = string.gsub(msg, "^mangeons ", "") if (b == 1) then miam_labas(from, a) end end function miam_hook_manger(from, msg) miam_result() end function miam_hook_plufaim(from, msg) miam_purge() say("Moi non plus") end said_hook_add("^mangeons ", miam_hook_mangeons) said_hook_add("^manger", miam_hook_manger) said_hook_add("^plufaim", miam_hook_plufaim) function test2() say("test ok") end function defcon_hook(from, msg) local t = { string.match(msg, "^defcon (%d) ?(.*)$") } if (not t[1]) then return end t[1] = tonumber(t[1]) if (type(t[1]) ~= "number") then return end if (not (t[1] >= 1 and t[1] <= 5)) then return end local s = data.topic if (not s) then s = "" end local t_topic = {} t_topic.a = string.match(s, "^(.+)|| ?ACTUAL DEFCON: %d") or "" t_topic.a = string.gsub(t_topic.a, "^%s*", "") t_topic.a = string.gsub(t_topic.a, "%s*$", "") s = string.gsub(s, "^.+|| ?(ACTUAL DEFCON: %d)", "%1") t_topic.b = string.match(s, "ACTUAL DEFCON: %d ?.*|| ?(.+)$") or "" t_topic.b = string.gsub(t_topic.b, "^%s*", "") t_topic.b = string.gsub(t_topic.b, "%s*$", "") s = string.gsub(s, "(ACTUAL DEFCON: %d ?.*)|| ?(.+)$", "%1") s = string.gsub(s, "^%s*", "") s = string.gsub(s, "%s*$", "") topic((t_topic.a ~= "" and t_topic.a.." || " or "").."ACTUAL DEFCON: "..t[1]..(t[2] ~= "" and " "..t[2] or "")..(t_topic.b ~= "" and " || "..t_topic.b or "")) end said_hook_add("^defcon ", defcon_hook)