import * as Discord from 'discord.js'; import { BotCommand } from 'psyduck-contracts'; import commandLineArgs from 'command-line-args'; const optionsDefinition = [ { name: 'verbose', alias: 'v', type: Boolean }, { name: 'command', alias: 'c', type: String } ]; export class HelpCommand implements BotCommand { public commandCodes: Array; public commandPrefix: string; private userDefinedHelpCode?: string; constructor(userDefinedHelpCode?: string) { this.commandPrefix = '!'; this.commandCodes = ['help', 'h']; this.userDefinedHelpCode = userDefinedHelpCode; } executeCommand(message: Discord.Message, parameters: string[]) { const options = commandLineArgs(optionsDefinition, { argv: parameters.map(p => p.trim()), partial: true }); if (options.verbose) { const embed = { 'description': 'Hey! I heard you needed some help. Check out the commands below to see what I can do.', 'url': 'https://github.com/galactic0wl/psyduck', 'color': 10347089, 'author': { 'name': 'Psyduck', 'url': 'https://github.com/galactic0wl/psyduck', 'icon_url': 'https://s3-us-west-2.amazonaws.com/psyduck-assets/assets/psyduck.png' }, 'fields': [ { 'name': 'Help', 'value': '```css\nRecognized Codes: [\'h\', \'help\']\nParameters:[verbose, v], [command, c]\nExamples:\n !help -v\n !help --verbose\n !help -c about```' } ] }; message.channel.send({embed}); if (this.userDefinedHelpCode) { message.channel.send(`In addition, you can run \`!${this.userDefinedHelpCode}\` to view additional commands.`); } } else { if (options.command) { } else { message.channel.send('Verbose set to false requires a command. Try again with `!help -c ` or `!help -v` for a list of all default commands.'); } if (this.userDefinedHelpCode) { message.channel.send(`In addition, you can run \`!${this.userDefinedHelpCode}\` to view additional commands.`); } } } }