Skip to content

Commit

Permalink
More info on help command
Browse files Browse the repository at this point in the history
  • Loading branch information
aeristhy committed Jun 7, 2021
1 parent f887ff2 commit a0d4ed3
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "random-cat",
"version": "4.0",
"version": "4.1.0",
"description": "A basic bot to help you get started with using the random.cat API.",
"main": "./src/bot.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ client.on('message', async message => {
if (!command) return;

if (command.guildOnly && message.channel.type === 'dm') {
return message.reply('I can\'t execute that command inside DMs!');
return message.channel.send('I can\'t execute that command inside DMs!');
}

if (command.permissions) {
const authorPerms = message.channel.permissionsFor(message.author);
if (!authorPerms || !authorPerms.has(command.permissions)) {
return message.reply('You can not do this!');
return message.channel.send('You can not do this!');
}
}

Expand All @@ -108,7 +108,7 @@ client.on('message', async message => {

if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return message.reply(`Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
return message.channel.send(`Please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/cats/cat1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
cooldown: 5,
permissions: 'ATTACH_FILES',
description: 'Sends cats with file attachment!',
category: 'Cats',
execute(message, args) {
try{
get('https://aws.random.cat/meow').then(res => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/cats/cat2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
cooldown: 5,
permissions: 'EMBED_LINKS',
description: 'Sends cats with links!',
category: 'Cats',
execute(message, args) {
try{
get('https://aws.random.cat/meow').then(res => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/cats/cats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
cooldown: 5,
permissions: ['ATTACH_FILES', 'EMBED_LINKS'],
description: 'Sends cats with Discord Buttons!',
category: 'Cats',
execute(message, args) {

const ping1 = new MessageButton()
Expand Down
1 change: 1 addition & 0 deletions src/commands/cats/ecat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
cooldown: 5,
permissions: 'EMBED_LINKS',
description: 'Sends cats with Embed!',
category: 'Cats',
execute(message, args) {
try{
get('https://aws.random.cat/meow').then(res => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/developer/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
name: 'reload',
description: 'Reloads a command',
args: true,
category: 'Developer',
execute(message, args) {
const commandName = args[0].toLowerCase();
const command = message.client.commands.get(commandName)
Expand Down
56 changes: 31 additions & 25 deletions src/commands/utility/help.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
const prefix = '!'
const prefix = '!';

module.exports = {
name: 'help',
description: 'List all of my commands or info about a specific command.',
aliases: ['cmd', 'cmds'],
usage: '[command name]',
category: 'Utility',
execute(message, args) {
const data = [];
const { commands } = message.client;


if (!args.length) {
data.push('Here\'s a list of all my commands:');
data.push(commands.map(command => command.name).join(', '));
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);

return message.channel.send(data, { split: true })
.catch(error => {
message.channel.send('An error has occured!' + error);
});
}
const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));

if (!command) {
return message.reply('that\'s not a valid command!');
const command = commands || commands.find(c => c.aliases && c.aliases);
let currentCategory = "";
let output = `**Use ${prefix}help <commandName> for details**`;
const sorted = command.array().sort((p, c) => p.category > c.category ? 1 : p.name > c.name && p.category === c.category ? 1 : -1 );

sorted.forEach( c => {
const cat = c.category || "None";
if (currentCategory !== cat) {
output += `\u200b\n\n**${cat}**\n`;
currentCategory = cat;
}
output += `\`${prefix}${c.name}\` `;
});
message.channel.send(output);
} else {
const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));
if (!command) {
return message.channel.send('Command not found.');
}

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:** ${prefix}${command.name} ${command.usage}`);
if (command.category) data.push(`**Category:** ${command.category}` || "None");
data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);
message.channel.send(data, { split: true });
}

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:** ${prefix}${command.name} ${command.usage}`);

data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);

message.channel.send(data, { split: true });
},
};
1 change: 1 addition & 0 deletions src/commands/utility/ping.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
name: 'ping',
description: 'Pong!',
category: 'Utility',
execute(message, args) {
message.channel.send('Pong!');
},
Expand Down
4 changes: 3 additions & 1 deletion src/commands/utility/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module.exports = {
args: true,
aliases: ['xd'],
usage: '<test>',
guildOnly: false,
guildOnly: true,
permissions: 'ADMINISTRATOR',
description: 'test!',
category: 'Utility',
execute(message, args) {
message.channel.send(args.join(" "));
},
Expand Down

0 comments on commit a0d4ed3

Please sign in to comment.