From 5236462efeb74f7f97cfd6015595b1398052f74d Mon Sep 17 00:00:00 2001 From: = Date: Sun, 18 Jul 2021 22:23:40 -0400 Subject: [PATCH] Improving the dynamic help --- commands/airport.js | 1 + commands/gif.js | 1 + commands/help.js | 55 ++++++----------------------------------- commands/mapcommands.js | 2 +- commands/pasta.js | 1 + commands/savegif.js | 2 +- commands/savepasta.js | 4 +-- commands/spongebob.js | 2 +- commands/weather.js | 1 + functions.js | 49 ++++++++++++++++++++++++------------ 10 files changed, 49 insertions(+), 69 deletions(-) diff --git a/commands/airport.js b/commands/airport.js index d0033fa..cb89fd9 100644 --- a/commands/airport.js +++ b/commands/airport.js @@ -14,6 +14,7 @@ let options = { module.exports = { name: 'airport', description: 'Get airport information by IATA code.', + usage: '', execute(message, file) { options.params.airport_id = file.name; axios.request(options).then(function (response) { diff --git a/commands/gif.js b/commands/gif.js index fd8ab35..1183d64 100644 --- a/commands/gif.js +++ b/commands/gif.js @@ -10,6 +10,7 @@ const tenor = require('tenorjs').client({ module.exports = { name: 'gif', description: 'Send a GIF', + usage: '', execute(message, file) { const client = message.client; if (!client.gifs.has(file.name)) { diff --git a/commands/help.js b/commands/help.js index 8c3cee9..19e24cb 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,54 +1,13 @@ +const functions = require('../functions.js'); + module.exports = { name: 'help', description: 'Shows the help page.', execute(message, file) { - const data = []; - const { commands } = message.client; - - if (!file.name) { - // const helpStructure = { - // commands = [ - // { - // name: commandName, - // aliases: commandAliases, - // description: commandDescription, - // usage: commandUsage, - // cooldown: commandCooldown - // } - // ] - // }; - - - - data.push('Here\'s a list of all my commands:'); - data.push(commands.map(command => command.name).join(', ')); - data.push('\nYou can send `[command name].help` to get info on a specific command!'); - - return message.author.send(data, { split: true }) - .then(() => { - if (message.channel.type === 'dm') return; - message.reply('I\'ve sent you a DM with all my commands!'); - }) - .catch(error => { - console.error(`Could not send help DM to ${message.author.tag}.\n`, error); - message.reply('It seems like I can\'t DM you! Do you have DMs disabled?'); - }); - } - - const command = commands.get(file.name) || commands.find(c => c.aliases && c.aliases.includes(file.name)); - - if (!command) { - return message.reply('That\'s not a valid command!'); - } - - data.push(`**Name:** ${command.name}`); - - if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`); - if (command.description) data.push(`**Description:** ${command.description}`); - if (command.usage) data.push(`**Usage:** \`${command.usage}.${command.name}\``); - - data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`); - - message.channel.send(data, { split: true }); + message.author.createDM() + .then(dmChannel => { + dmChannel.send(functions.createHelpEmbed(message)).then().catch(err => console.error(err)); + message.reply('I\'ve DM\'d you a copy of my help message!'); + }).catch(err => console.error(err)); }, }; \ No newline at end of file diff --git a/commands/mapcommands.js b/commands/mapcommands.js index 4977a8f..f9a0278 100644 --- a/commands/mapcommands.js +++ b/commands/mapcommands.js @@ -4,6 +4,6 @@ module.exports = { name: 'mapcommands', description: '', execute(message, file) { - console.log(functions.mapCommands(message.client)); + console.log(functions.mapCommands(message)); } } \ No newline at end of file diff --git a/commands/pasta.js b/commands/pasta.js index 7d8dfe3..6083358 100644 --- a/commands/pasta.js +++ b/commands/pasta.js @@ -3,6 +3,7 @@ const functions = require('../functions.js'); module.exports = { name: 'pasta', description: 'Send a copypasta.', + usage: '', execute(message, file) { const client = message.client; const replyHeader = `\'${file.name}\' requested by: ${message.author.username}\n`; diff --git a/commands/savegif.js b/commands/savegif.js index 20b5f43..3647138 100644 --- a/commands/savegif.js +++ b/commands/savegif.js @@ -10,7 +10,7 @@ const { emoji } = require('../config.json'); module.exports = { name: 'savegif', - description: 'Adds a given gif to the hardcoded list.', + description: 'Saves a gif selected from a search to a given filename.', usage: '', execute(message, file) { const query = file.name; diff --git a/commands/savepasta.js b/commands/savepasta.js index 91242c5..848ad4b 100644 --- a/commands/savepasta.js +++ b/commands/savepasta.js @@ -2,8 +2,8 @@ const functions = require('../functions.js'); module.exports = { name: 'savepasta', - description: 'Adds a given copypasta to the hardcoded list.', - usage: ' ', + description: 'Saves a copypasta as pasta_name.pasta, just send the pasta name on the first message, and the bot will ask for the actual pasta afterwards.', + usage: '', execute(message, file) { message.channel.send(`I'll be saving the next message you send as ${file.name}.pasta\nWhat is the content of the copypasta?`) .then(promptMessage => { diff --git a/commands/spongebob.js b/commands/spongebob.js index 48645c7..727558a 100644 --- a/commands/spongebob.js +++ b/commands/spongebob.js @@ -3,7 +3,7 @@ const functions = require('../functions.js'); module.exports = { name: 'spongebob', description: 'SpOnGeBoB-iFy AnYtHiNg AuToMaTiCaLly', - usage: '', execute(message, file) { let flipper = 0; let newText = ''; diff --git a/commands/weather.js b/commands/weather.js index 123ad9b..1000c93 100644 --- a/commands/weather.js +++ b/commands/weather.js @@ -14,6 +14,7 @@ var options = { module.exports = { name: 'weather', description: 'Get the current weather by ZIP code or city name.', + usage: '', execute(message, file) { options.params.q = file.name; axios.request(options).then(function (response) { diff --git a/functions.js b/functions.js index afeef46..7e380e8 100644 --- a/functions.js +++ b/functions.js @@ -115,22 +115,39 @@ module.exports = { .setTimestamp() .setFooter(`@${author.username}#${author.discriminator}`); }, - mapCommands(client) { - const { commands } = client; - // return new Promise((resolve, reject) => { - // let commandMap = [] - // for (const [key, value] of commands.map()) { - // // commandMap.push({ - // // name: command.name, - // // aliases: command.aliases, - // // description: command.description, - // // usage: command.usage, - // // cooldown: 0 // Set to 0 for now for the sake of simple code, will add cooldowns later - // // }); - // } - // }); - for (const entry of commands.map(command => [command.name, command.description, command.syntax])) { - console.log(entry); + createHelpEmbed(message) { + const { commands } = message.client; + let fields = []; + for (const entry of commands.map(command => [command.name, command.description, command.usage])) { + const name = entry[0]; + const description = entry[1]; + let usage; + if (entry[2] == undefined) { + usage = ''; + } else { + usage = entry[2]; + } + const excludeList = [ + 'kill', + 'mapcommands', + 'newgif', + 'newpng', + 'oldgif', + 'strain', + 'stonk', + 'wrongbad' + ]; + if (excludeList.includes(name)) continue; + fields.push({ + name: name, + value: `${description}\n**Usage:** \`${usage}.${name}\`` + }); } + + return new Discord.MessageEmbed() + .setAuthor('NodBot Help') + .setDescription('All commands are provided as "file extensions" instead of prefixes to the message.') + .addFields(fields) + .setTimestamp(); } } \ No newline at end of file