Improving the dynamic help
This commit is contained in:
parent
ab0f4b316d
commit
5236462efe
@ -14,6 +14,7 @@ let options = {
|
||||
module.exports = {
|
||||
name: 'airport',
|
||||
description: 'Get airport information by IATA code.',
|
||||
usage: '<IATA>',
|
||||
execute(message, file) {
|
||||
options.params.airport_id = file.name;
|
||||
axios.request(options).then(function (response) {
|
||||
|
@ -10,6 +10,7 @@ const tenor = require('tenorjs').client({
|
||||
module.exports = {
|
||||
name: 'gif',
|
||||
description: 'Send a GIF',
|
||||
usage: '<GIF name or Search Query>',
|
||||
execute(message, file) {
|
||||
const client = message.client;
|
||||
if (!client.gifs.has(file.name)) {
|
||||
|
@ -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));
|
||||
},
|
||||
};
|
@ -4,6 +4,6 @@ module.exports = {
|
||||
name: 'mapcommands',
|
||||
description: '',
|
||||
execute(message, file) {
|
||||
console.log(functions.mapCommands(message.client));
|
||||
console.log(functions.mapCommands(message));
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ const functions = require('../functions.js');
|
||||
module.exports = {
|
||||
name: 'pasta',
|
||||
description: 'Send a copypasta.',
|
||||
usage: '<Copypasta Name>',
|
||||
execute(message, file) {
|
||||
const client = message.client;
|
||||
const replyHeader = `\'${file.name}\' requested by: ${message.author.username}\n`;
|
||||
|
@ -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: '<search query>',
|
||||
execute(message, file) {
|
||||
const query = file.name;
|
||||
|
@ -2,8 +2,8 @@ const functions = require('../functions.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'savepasta',
|
||||
description: 'Adds a given copypasta to the hardcoded list.',
|
||||
usage: '<Copy Pasta Text> <pasta_name>',
|
||||
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: '<Pasta Name>',
|
||||
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 => {
|
||||
|
@ -3,7 +3,7 @@ const functions = require('../functions.js');
|
||||
module.exports = {
|
||||
name: 'spongebob',
|
||||
description: 'SpOnGeBoB-iFy AnYtHiNg AuToMaTiCaLly',
|
||||
usage: '<text you want spongebob-ified',
|
||||
usage: '<text to convert>',
|
||||
execute(message, file) {
|
||||
let flipper = 0;
|
||||
let newText = '';
|
||||
|
@ -14,6 +14,7 @@ var options = {
|
||||
module.exports = {
|
||||
name: 'weather',
|
||||
description: 'Get the current weather by ZIP code or city name.',
|
||||
usage: '<ZIP code, City Name, etc>',
|
||||
execute(message, file) {
|
||||
options.params.q = file.name;
|
||||
axios.request(options).then(function (response) {
|
||||
|
51
functions.js
51
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user