chomens-bot-js/commands/help.js

143 lines
5.3 KiB
JavaScript
Raw Normal View History

2022-11-15 21:33:16 -05:00
/* eslint-disable require-jsdoc */
2022-08-14 05:51:45 -04:00
/* eslint-disable no-var */
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
module.exports = {
name: 'help',
alias: ['heko', 'cmds', 'commands'],
description: 'Shows the help',
usage: '[command]',
trusted: 0,
2022-11-16 06:41:30 -05:00
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0]) {
2022-08-14 05:51:45 -04:00
for (const command of bot.command_handler.commands) {
2022-11-08 09:01:38 -05:00
function run() {
2022-08-14 05:51:45 -04:00
let alias = command.name;
2022-11-23 04:43:28 -05:00
2022-11-07 08:08:29 -05:00
if (command.alias.toString() !== '') {
2022-08-14 05:51:45 -04:00
alias = command.alias.join(', ');
}
const usage = [];
if (typeof command.usage === 'string') {
usage.push({text: `${prefix}${command.name} `, color: 'gold'});
usage.push({text: command.usage, color: 'aqua'});
} else {
command.usage.forEach((value) => {
usage.push({text: `${prefix}${command.name} `, color: 'gold'});
usage.push({text: value, color: 'aqua'});
usage.push('\n');
});
usage.pop();
}
2022-11-23 04:43:28 -05:00
const component = [];
component.push({text: prefix + command.name, color: 'gold'});
component.push({text: ` (${alias})`, color: 'white'});
component.push({text: ' - ', color: 'gray'});
component.push({text: command.description, color: 'gray'});
component.push('\n');
component.push({text: 'Trust level: ', color: 'green'});
component.push({text: command.trusted, color: 'yellow'});
component.push('\n');
component.push({text: 'Supported on Discord: ', color: 'green'});
component.push({text: command.discordExecute ? 'true' : 'false', color: 'gold'});
component.push('\n');
component.push(usage);
bot.tellraw(selector, component);
2022-08-14 05:51:45 -04:00
}
2022-11-08 09:01:38 -05:00
if (command.name === args[0]) run();
2022-08-14 05:51:45 -04:00
for (const alias of command.alias) {
2022-11-08 09:01:38 -05:00
if (alias === args[0]) run();
2022-08-14 05:51:45 -04:00
}
};
} else {
2022-11-23 04:43:28 -05:00
const generalCommands = [];
const trustedCommands = [];
const ownerCommands = [];
function component(command, color) {
return {
text: command.name + ' ',
color,
hoverEvent: {
action: 'show_text',
contents: [{
text: 'Click here to see the information for this command',
color: 'green',
}],
},
clickEvent: {
action: 'run_command',
value: `${prefix}help ${command.name}`,
},
};
};
for (const command of bot.command_handler.commands) {
if (command.trusted !== 0) continue;
generalCommands.push(component(command, 'green'));
}
for (const command of bot.command_handler.commands) {
if (command.trusted !== 1) continue;
trustedCommands.push(component(command, 'red'));
}
for (const command of bot.command_handler.commands) {
if (command.trusted !== 2) continue;
ownerCommands.push(component(command, 'dark_red'));
}
2022-11-08 09:01:38 -05:00
const pre = [{text: 'Commands ', color: 'gray'}, {text: '(', color: 'dark_gray'}, {text: 'Length: ', color: 'gray'}, {text: bot.command_handler.commands.length, color: 'green'}, {text: ') ', color: 'dark_gray'}, {text: '(', color: 'dark_gray'}, {text: '⬤ Public', color: 'green'}, {text: ' ⬤ Trusted', color: 'red'}, {text: ' ⬤ Owner', color: 'dark_red'}, {text: ') - ', color: 'dark_gray'}];
2022-11-16 06:41:30 -05:00
bot.tellraw(selector, [pre, generalCommands, trustedCommands, ownerCommands]);
2022-08-14 05:51:45 -04:00
}
},
discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc) {
if (args[0]) {
2022-08-14 05:51:45 -04:00
for (const command of bot.command_handler.commands) {
2022-11-08 09:01:38 -05:00
function run() {
2022-08-14 05:51:45 -04:00
let alias = command.name;
2022-11-23 04:43:28 -05:00
2022-11-07 08:08:29 -05:00
if (command.alias.toString() !== '') {
2022-08-14 05:51:45 -04:00
alias = command.alias.join(', ');
}
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`${prefix + command.name} (${alias}) - ${command.description}`)
2022-11-23 04:43:28 -05:00
.setDescription(`Trust level: ${command.trusted}
Supported: ${command.discordExecute ? 'true' : 'false'}
${prefix + command.name} ${command.usage}`,
);
2022-08-14 05:51:45 -04:00
channeldc.send({embeds: [Embed]});
}
2022-10-14 04:46:41 -04:00
2022-11-08 09:01:38 -05:00
if (command.name === args[0]) run();
for (const alias of command.alias) {
2022-11-08 09:01:38 -05:00
if (alias === args[0]) run();
2022-08-14 05:51:45 -04:00
}
};
} else {
let supportedCommands = '';
let unsupportedCommands = '';
for (const command of bot.command_handler.commands) {
if (!command.discordExecute) continue;
2022-08-14 05:51:45 -04:00
supportedCommands += command.name + ' ';
}
for (const command of bot.command_handler.commands) {
2022-11-26 21:08:07 -05:00
if (command.discordExecute) continue;
2022-08-14 05:51:45 -04:00
unsupportedCommands += command.name + ' ';
}
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle(`Commands (Length: ${bot.command_handler.commands.length})`)
2022-08-14 05:51:45 -04:00
.setDescription('**Supported Commands**\n' + supportedCommands + '\n**Unsupported Commands**\n' + unsupportedCommands);
channeldc.send({embeds: [Embed]});
}
},
};