--[[ cmd_help.lua v0.04 by blastbeat - this script adds a command "help" - it exports also a module to reg a help text which will be shown by help - usage: [+!#]help - changelog 0.04: - updated script api - regged hubcommand - changelog 0.03: - some clean ups - changelog 0.02: - added language files and ucmd ]]-- --// settings begin //-- local scriptname = "cmd_help" local scriptversion = "0.04" local scriptlang = cfg.get "language" local cmd = "help" --// settings end //-- local utf_match = utf.match local help = { } local lang, err = cfg.loadlanguage( scriptlang, scriptname ); lang = lang or { }; err = err and hub.debug( err ) local msg_usage = lang.msg_usage or "Available commands:" local msg_commands = lang.msg_commands or "Usage: " local msg_description = lang.msg_description or "Description: " local msg_minlevel = lang.msg_minlevel or "Level: " local help_title = lang.help_title or "help" local help_usage = lang.help_usage or "[+!#]help" local help_desc = lang.help_desc or "shows help for hub commands" local help_level = 0 -- minimum level to get the help local ucmd_menu = lang.ucmd_menu or { "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 local hubcmd local onbmsg = function( user, command, parameters ) local tmp = { "\n\n" .. msg_commands } local level = user:level( ) for id, tbl in ipairs( help ) do if level >= tbl.level then tmp[ #tmp + 1 ] = "\n\n" .. tbl.title .. "\n" .. msg_usage .. tbl.usage .. "\n" .. msg_description .. tbl.desc .. "\n" .. msg_minlevel .. tbl.level end end tmp = table.concat( tmp ) user:reply( tmp, hub.getbot( ), hub.getbot( ) ) return PROCESSED end hub.setlistener( "onStart", { }, function( ) local ucmd = hub.import "etc_usercommands" -- add usercommand if ucmd then ucmd.add( ucmd_menu, cmd, { }, { "CT1" }, help_level ) end hubcmd = hub.import "etc_hubcommands" -- add hubcommand assert( hubcmd ) assert( hubcmd.add( cmd, onbmsg ) ) return nil end ) reghelp( help_title, help_usage, help_desc, help_level ) hub.debug( "** Loaded "..scriptname.." "..scriptversion.." **" ) --// public //-- return { reg = reghelp, }