import { Message , RichEmbed , Guild } from 'discord.js' ; import { commandInterface } from '../commands' ; import { permLevels } from '../utils/permissions' ; import { Bot } from '..' ; import { sendError } from '../utils/messages' ; import { permToString } from '../utils/parsers' ; param { Guild } guild param { Message } message param { * } strucObject param { string } path param { [ number , number ] } requestTime async function sendCommandList ( guild , message , strucObject , path , requestTime ) { var output = new RichEmbed ( ) ; output . setAuthor ( 'Command List:' , Bot . client . user . displayAvatarURL ) ; if ( path ) output . setFooter ( 'Path: ~' + path ) ; output . setColor ( Bot . database . settingsDB . cache . embedColors . help ) ; var categories = Object . keys ( strucObject ) . filter ( x => strucObject [ x ] . _categoryName ) ; if ( categories . length != 0 ) { var cat_text = strucObject [ categories [ 0 ] ] . _categoryName ; for ( i = 1 ; i < categories . length ; i ++ ) { cat_text += '\n' + strucObject [ categories [ i ] ] . _categoryName ; } output . addField ( 'Subcategories:' , cat_text ) ; } var commands = Object . keys ( strucObject ) . filter ( x => strucObject [ x ] . help ) ; for ( var i = 0 ; i < commands . length ; i ++ ) { var f = Bot . commands . get ( commands [ i ] ) ; if ( f . permLevel == permLevels . botMaster ) continue ; output . addField ( ( await Bot . database . getPrefix ( guild ) ) + f . name , f . help . shortDescription ) ; } Bot . mStats . logResponseTime ( command . name , requestTime ) ; message . channel . send ( output ) ; Bot . mStats . logMessageSend ( ) ; Bot . mStats . logCommandUsage ( command . name , 'commandList' ) ; } var command = { name : 'help' , path : '' , dm : true , permLevel : permLevels . member , togglable : false , help : { shortDescription : 'Gives a command list and help' , longDescription : 'Lists all commands/categories and can get detailed help for command' , usages : [ '{command}' , '{command} [command name/category]\nuse `category/subcategory` to get list from subcategory' ] , examples : [ '{command}' , '{command} whois' ] } , run : async ( message , args , permLevel , dm , requestTime ) => { try { if ( args . length == 0 ) { sendCommandList ( message . guild , message , Bot . commands . structure , undefined , requestTime ) ; return false ; } var command = Bot . commands . get ( args . toLowerCase ( ) ) ; if ( command == undefined ) { if ( typeof ( Bot . commands . structure [ args . split ( '/' ) [ 0 ] . toLowerCase ( ) ] ) != 'undefined' ) { var strucObject = Bot . commands . structure ; var keys = args . split ( '/' ) ; for ( var i = 0 ; i < keys . length ; i ++ ) { if ( typeof ( strucObject [ keys [ i ] . toLowerCase ( ) ] ) === 'undefined' ) { message . channel . send ( 'Couldn\'t find specified category' ) ; Bot . mStats . logMessageSend ( ) ; return false ; } else { strucObject = strucObject [ keys [ i ] . toLowerCase ( ) ] ; } } sendCommandList ( message . guild , message , strucObject , args , requestTime ) ; return false ; } else { message . channel . send ( 'Couldn\'t find specified command' ) ; Bot . mStats . logMessageSend ( ) ; return false ; } } Bot . mStats . logResponseTime ( command . name , requestTime ) ; message . channel . send ( await Bot . commands . getHelpEmbed ( command , message . guild ) ) ; Bot . mStats . logMessageSend ( ) ; Bot . mStats . logCommandUsage ( 'help' , 'commandHelp' ) ; } catch ( e ) { sendError ( message . channel , e ) ; Bot . mStats . logError ( e , command . name ) ; } } } ; export default command ;