--[[ cmd_help.lua v0.01 by blastbeat - this script adds a command "help" - it exports also a module to reg a help text which will be shown by help ]]-- --// settings begin //-- local cmd = "help" --// settings end //-- local utf_match = utf.match local help = { } local reghelp = function( title, usage, desc, level ) title, usage, desc = tostring( title ), tostring( usage ), tostring( desc ) level = tonumber( level ) or 0 help[ #help + 1 ] = { title = title, usage = usage, desc = desc, level = level } end hub:setListener( "onBroadcast", { }, function( user, adccmd, txt ) local command, parameters = utf_match( txt, "^[+!#](%a+) ?(.*)" ) if command == cmd then local tmp = { "\n\nAvailable commands:" } local level = user:getLevel( ) for id, tbl in ipairs( help ) do if level >= tbl.level then tmp[ #tmp + 1 ] = "\n\n" .. tbl.title .. "\nusage: " .. tbl.usage .. "\ndescription: " .. tbl.desc end end tmp = table.concat( tmp ) user:reply( tmp, hub.getbot( ) ) return PROCESSED end return nil end ) reghelp( "help", "[+!#]help", "shows help for hub commands", 0 ) hub.debug( "** Loaded cmd_help.lua **" ) --// public //-- return { reg = reghelp, }