chomens-bot-js/commands/help.js

142 lines
5.3 KiB
JavaScript
Raw Normal View History

2022-08-14 05:51:45 -04:00
/* eslint-disable no-var */
2022-11-27 02:35:28 -05:00
const { MessageEmbed } = require('discord.js')
2022-08-14 05:51:45 -04:00
module.exports = {
name: 'help',
alias: ['heko', 'cmds', 'commands'],
description: 'Shows the help',
usage: '[command]',
trusted: 0,
execute (bot, username, 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-27 02:35:28 -05:00
function run () {
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-11-27 02:35:28 -05:00
alias = command.alias.join(', ')
2022-08-14 05:51:45 -04:00
}
2022-11-27 02:35:28 -05:00
const usage = []
if (typeof command.usage === 'string') {
2022-11-27 02:35:28 -05:00
usage.push({ text: `${prefix}${command.name} `, color: 'gold' })
usage.push({ text: command.usage, color: 'aqua' })
} else {
command.usage.forEach((value) => {
2022-11-27 02:35:28 -05:00
usage.push({ text: `${prefix}${command.name} `, color: 'gold' })
usage.push({ text: value, color: 'aqua' })
usage.push('\n')
})
usage.pop()
}
2022-11-27 02:35: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' })
2022-11-23 04:43:28 -05:00
2022-11-27 02:35:28 -05:00
component.push('\n')
2022-11-23 04:43:28 -05:00
2022-11-27 02:35:28 -05:00
component.push({ text: 'Trust level: ', color: 'green' })
component.push({ text: command.trusted, color: 'yellow' })
2022-11-23 04:43:28 -05:00
2022-11-27 02:35:28 -05:00
component.push('\n')
2022-11-23 04:43:28 -05:00
2022-11-27 02:35:28 -05:00
component.push({ text: 'Supported on Discord: ', color: 'green' })
component.push({ text: command.discordExecute ? 'true' : 'false', color: 'gold' })
2022-11-23 04:43:28 -05:00
2022-11-27 02:35:28 -05:00
component.push('\n')
2022-11-23 04:43:28 -05:00
2022-11-27 02:35:28 -05:00
component.push(usage)
2022-11-23 04:43:28 -05:00
2022-11-27 02:35:28 -05:00
bot.tellraw(selector, component)
2022-08-14 05:51:45 -04:00
}
2022-11-27 02:35:28 -05:00
if (command.name === args[0]) run()
2022-08-14 05:51:45 -04:00
for (const alias of command.alias) {
2022-11-27 02:35:28 -05:00
if (alias === args[0]) run()
2022-08-14 05:51:45 -04:00
}
};
} else {
2022-11-27 02:35:28 -05:00
const generalCommands = []
const trustedCommands = []
const ownerCommands = []
function component (command, color) {
2022-11-23 04:43:28 -05:00
return {
text: command.name + ' ',
color,
hoverEvent: {
action: 'show_text',
contents: [{
text: 'Click here to see the information for this command',
2022-11-27 02:35:28 -05:00
color: 'green'
}]
2022-11-23 04:43:28 -05:00
},
clickEvent: {
action: 'run_command',
2022-11-27 02:35:28 -05:00
value: `${prefix}help ${command.name}`
}
}
2022-11-23 04:43:28 -05:00
};
for (const command of bot.command_handler.commands) {
if (command.trusted !== 0 || command.proxy) continue
2022-11-27 02:35:28 -05:00
generalCommands.push(component(command, 'green'))
2022-11-23 04:43:28 -05:00
}
for (const command of bot.command_handler.commands) {
if (command.trusted !== 1 || command.proxy) continue
2022-11-27 02:35:28 -05:00
trustedCommands.push(component(command, 'red'))
2022-11-23 04:43:28 -05:00
}
for (const command of bot.command_handler.commands) {
if (command.trusted !== 2 || command.proxy) continue
2022-11-27 02:35:28 -05:00
ownerCommands.push(component(command, 'dark_red'))
2022-11-23 04:43:28 -05:00
}
2022-11-27 02:35:28 -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' }]
bot.tellraw(selector, [pre, generalCommands, trustedCommands, ownerCommands])
2022-08-14 05:51:45 -04:00
}
},
discordExecute: async function (bot, username, sender, prefix, args, channeldc, message, config) {
if (args[0]) {
2022-08-14 05:51:45 -04:00
for (const command of bot.command_handler.commands) {
2022-11-27 02:35:28 -05:00
function run () {
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-11-27 02:35:28 -05:00
alias = command.alias.join(', ')
2022-08-14 05:51:45 -04:00
}
const Embed = new MessageEmbed()
2022-12-01 05:15:30 -05:00
.setColor(config.discord.embedsColors.normal)
2022-11-27 02:35:28 -05:00
.setTitle(`${prefix + command.name} (${alias}) - ${command.description}`)
.setDescription(`Trust level: ${command.trusted}
2022-11-23 04:43:28 -05:00
Supported: ${command.discordExecute ? 'true' : 'false'}
2022-11-27 02:35:28 -05:00
${prefix + command.name} ${command.usage}`
)
channeldc.send({ embeds: [Embed] })
}
2022-10-14 04:46:41 -04:00
2022-11-27 02:35:28 -05:00
if (command.name === args[0]) run()
for (const alias of command.alias) {
2022-11-27 02:35:28 -05:00
if (alias === args[0]) run()
2022-08-14 05:51:45 -04:00
}
};
} else {
2022-11-27 02:35:28 -05:00
let supportedCommands = ''
let unsupportedCommands = ''
2022-08-14 05:51:45 -04:00
for (const command of bot.command_handler.commands) {
2022-11-27 02:35:28 -05:00
if (!command.discordExecute) continue
supportedCommands += command.name + ' '
2022-08-14 05:51:45 -04:00
}
for (const command of bot.command_handler.commands) {
if (command.discordExecute || command.proxy) continue
2022-11-27 02:35:28 -05:00
unsupportedCommands += command.name + ' '
2022-08-14 05:51:45 -04:00
}
const Embed = new MessageEmbed()
2022-12-01 05:15:30 -05:00
.setColor(config.discord.embedsColors.normal)
2022-11-27 02:35:28 -05:00
.setTitle(`Commands (Length: ${bot.command_handler.commands.length})`)
.setDescription('**Supported Commands**\n' + supportedCommands + '\n**Unsupported Commands**\n' + unsupportedCommands)
channeldc.send({ embeds: [Embed] })
2022-08-14 05:51:45 -04:00
}
2022-11-27 02:35:28 -05:00
}
}