import { Command , CommandoClient , CommandoMessage } from 'discord.js-commando' ; import { Message , Util } from 'discord.js' ; import { PermissionsManager } from '../../managers/permission.manager' ; module . exports = class HelpCommand extends Command { constructor ( client ) { super ( client , { name : 'help' , group : 'general' , memberName : 'help' , description : 'Displays a list of available commands, or detailed information for a specified command.' , examples : [ 'help' , 'help about' ] , args : [ { key : 'command' , prompt : 'For which command help information should be for.' , type : 'string' , default : '' , } , ] , } ) ; } async run ( message , args ) { const prefix = message . guild ? message . guild . commandPrefix : this . client . commandPrefix ; const msg = < Message > < unknown > message ; const isAdministrator = message . member && PermissionsManager . isGuildManager ( message . member ) ; if ( args . command === '' ) { const text = [ ] ; text . push ( '= Command List = \n' ) ; text . push ( `*You can use ${ prefix }help [command] to get more information about each command.*` ) ; if ( ! message . guild ) { text . push ( '*Some commands might be missing. To get more information, use this command in a guild.*' ) ; } text . push ( '' ) ; let activeCategory ; this . client . registry . commands . clone ( ) . sort ( this . sortCommands ) . forEach ( ( command ) => { if ( ! command . isUsable ( msg ) || ( command . hidden && ! this . client . isOwner ( message . author ) ) ) { return ; } if ( command . group . id !== activeCategory ) { activeCategory = command . group . id ; text . push ( `[${ command . group . name }]` ) ; } text . push ( `   ${ prefix }${ command . name } - ${ Util . cleanContent ( command . description , msg ) }` ) ; } ) ; return message . say ( text , { code : 'asciidoc' , split : true } ) ; } const commands = this . client . registry . findCommands ( args . command , true ) ; const command = commands . length > 0 ? commands [ 0 ] : null ; if ( command && command . isUsable ( msg ) && ( ! command . hidden || this . client . isOwner ( message . author ) ) ) { const text = [ `__**Group:**__ ${ command . group . name } (\`${ command . groupID }\`)` , `__**Command:**__ ${ command . name }` , `${ command . description }` , ] ; if ( command . details ) { text . push ( command . details ) ; } text . push ( '' ) ; if ( command . examples && command . examples . length > 0 ) { text . push ( `**Examples:** ${ command . examples . join ( ', ' ) }` ) ; } if ( command . aliases && command . aliases . length > 0 ) { text . push ( `**Aliases:** ${ command . aliases . join ( ', ' ) }` ) ; } const throttling = command . throttling ; if ( throttling ) { if ( throttling . usages > 1 ) { text . push ( `**Throttling:** ${ throttling . duration } seconds (${ throttling . usages } usages)` ) ; } else { text . push ( `**Throttling:** ${ throttling . duration } seconds` ) ; } } const userPermissions = command . userPermissions ; if ( userPermissions && userPermissions . length > 0 && isAdministrator ) { text . push ( `**User permissions:** \`${ userPermissions . join ( '`, `' ) }\`` ) ; } const clientPermissions = command . clientPermissions ; if ( clientPermissions && clientPermissions . length > 0 && isAdministrator ) { const permissionEmoji = message . guild . me . hasPermission ( clientPermissions ) ? '✅' : '❌' ; text . push ( `**Required permissions:** \`${ clientPermissions . join ( '`, `' ) }\` (${ permissionEmoji })` ) ; } if ( command . nsfw ) { text . push ( '*This command can be used in NSFW channels only.*' ) ; } if ( command . guildOnly ) { text . push ( '*This command can be used only in a server.*' ) ; } if ( command . ownerOnly ) { text . push ( '*Only the bot owners can use this command.*' ) ; } return message . say ( text ) ; } return message . say ( `Unable to identify command. Use \`${ prefix }help\` to view the list of all commands.` ) ; } param first param second protected sortCommands ( first , second ) { if ( first . group . name < second . group . name ) { return - 1 ; } if ( first . group . name > second . group . name ) { return 1 ; } if ( first . name < second . name ) { return - 1 ; } if ( first . name > second . name ) { return 1 ; } return 0 ; } } ;