local modstore = minetest.get_mod_storage() local keywords = minetest.deserialize(modstore:get_string("keywords")) or {} local cooldown = modstore:get_int("cooldown") local enabled = 0 local can_reply = true if cooldown == 0 then cooldown = 60 end -- register_on_receiving_chat_message(s) and register_on_sending_chat_message(s) backwards compatibility if not minetest.register_on_receiving_chat_message then minetest.register_on_receiving_chat_message = minetest.register_on_receiving_chat_messages end -- (Thanks ChimneySwift :P) minetest.register_on_receiving_chat_messages(function(message) local msg = minetest.strip_colors(message) local name if enabled == 0 or not (msg:find("<") and msg:find(">")) or can_reply == false then return false else name = msg:sub(2, msg:find(">")-1) end for k, word in ipairs(keywords) do if msg:find(word) then can_reply = false minetest.send_chat_message(name..": I am AFK") minetest.after(cooldown, function() can_reply = true end) break end end return false end) minetest.register_on_sending_chat_messages(function(message) if enabled == 1 then enabled = 0 end return false end) if minetest.registered_chatcommands["afk"] then minetest.unregister_chatcommand("afk") end minetest.register_chatcommand("afk", { description = "Command for the afk_bot CSM.\n.afk help", func = function(param) minetest.log("Localplayer runs command: .afk "..dump(param)) if param == "help" or parm == "h" then minetest.display_chat_message(minetest.colorize("cyan", ".afk | Keywords the bot searches the chat for\n".. ".afk cooldown