2024-08-12 05:13:32 -04:00
|
|
|
const fs = require('fs')
|
2024-09-18 03:32:18 -04:00
|
|
|
const settings = require("../settings.json")
|
2024-08-12 05:13:32 -04:00
|
|
|
const cmds = Object.create(null)
|
|
|
|
const { getMessage } = require('../util/lang.js')
|
|
|
|
|
|
|
|
const sortHelp = function sortHelp (c1, c2) {
|
2024-09-13 04:11:54 -04:00
|
|
|
const level1 = cmds[c1.with[0].text].level ? cmds[c1.with[0].text].level : 0
|
|
|
|
const level2 = cmds[c2.with[0].text].level ? cmds[c2.with[0].text].level : 0
|
2024-08-12 05:13:32 -04:00
|
|
|
return level1 - level2
|
|
|
|
}
|
|
|
|
|
|
|
|
const bpl = fs.readdirSync('./commands')
|
2024-08-22 07:34:39 -04:00
|
|
|
for (const plugin of bpl) {
|
|
|
|
if (!plugin.endsWith('.js')) {
|
2024-08-12 05:13:32 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
try {
|
2024-08-22 07:34:39 -04:00
|
|
|
const commandName = plugin.split('.js')[0]
|
2024-09-18 03:32:18 -04:00
|
|
|
if(commandName == "settings" && settings.userSettingsDisabled) continue
|
2024-08-12 05:13:32 -04:00
|
|
|
if (commandName !== 'help') {
|
2024-08-22 07:34:39 -04:00
|
|
|
cmds[commandName] = require(`./${plugin}`)
|
2024-08-12 05:13:32 -04:00
|
|
|
if (cmds[commandName].level === undefined) {
|
|
|
|
cmds[commandName].level = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) { console.log(e) }
|
|
|
|
}
|
|
|
|
|
|
|
|
const printHelp = (c) => {
|
|
|
|
const commandList = []
|
2024-09-13 04:11:54 -04:00
|
|
|
const permsN = getMessage(c.lang, 'command.help.permsNormal')
|
|
|
|
const permsT = getMessage(c.lang, 'command.help.permsTrusted')
|
|
|
|
const permsO = getMessage(c.lang, 'command.help.permsOwner')
|
|
|
|
const permList = [permsN, permsT, permsO]
|
2024-09-13 03:30:34 -04:00
|
|
|
const colorList = ["green", "red", "dark_red"]
|
2024-08-12 05:13:32 -04:00
|
|
|
for (const i in cmds) {
|
|
|
|
if (cmds[i].hidden) continue
|
|
|
|
let cmdColor
|
2024-09-13 03:30:34 -04:00
|
|
|
if(colorList[cmds[i].level]){
|
|
|
|
cmdColor = colorList[cmds[i].level]
|
|
|
|
} else {
|
|
|
|
cmdColor = colorList[0]
|
2024-08-12 05:13:32 -04:00
|
|
|
}
|
2024-09-13 04:11:54 -04:00
|
|
|
let usage = getMessage(c.lang, `command.${i}.usage`).split('||')
|
|
|
|
let desc = getMessage(c.lang, `command.${i}.desc`)
|
|
|
|
if (cmds[i].usage) {
|
|
|
|
usage = cmds[i].usage.split('||')
|
|
|
|
}
|
|
|
|
if (cmds[i].desc) {
|
|
|
|
desc = cmds[i].desc
|
|
|
|
}
|
|
|
|
hoverText = []
|
|
|
|
for (const item of usage) {
|
|
|
|
hoverText.push({
|
|
|
|
translate: getMessage(c.lang, 'command.help.commandUsage.lf'),
|
|
|
|
color: c.colors.secondary,
|
|
|
|
with: [
|
|
|
|
{
|
|
|
|
text: i,
|
|
|
|
color: c.colors.primary
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: item,
|
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
hoverText.push({
|
|
|
|
translate: getMessage(c.lang, 'command.help.commandDesc.lf'),
|
|
|
|
color: c.colors.secondary,
|
|
|
|
with: [
|
|
|
|
{
|
|
|
|
text: desc,
|
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
const rPerms = cmds[i].level ? cmds[i].level : 0
|
|
|
|
hoverText.push({
|
|
|
|
translate: getMessage(c.lang, 'command.help.commandPerms.lf'),
|
|
|
|
color: c.colors.secondary,
|
|
|
|
with: [
|
|
|
|
{
|
|
|
|
text: permList[rPerms],
|
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
hoverText.push({
|
|
|
|
translate: getMessage(c.lang, 'command.help.runCommand'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
})
|
2024-08-12 05:13:32 -04:00
|
|
|
commandList.push(
|
|
|
|
{
|
|
|
|
translate: '%s ',
|
|
|
|
color: cmdColor,
|
|
|
|
with: [
|
2024-09-13 04:11:54 -04:00
|
|
|
{
|
|
|
|
text: i,
|
|
|
|
hoverEvent: {
|
|
|
|
action: "show_text",
|
|
|
|
value: hoverText,
|
|
|
|
contents: hoverText
|
|
|
|
},
|
|
|
|
clickEvent: {
|
|
|
|
action: 'suggest_command',
|
|
|
|
value: `${c.prefix}${i}`
|
|
|
|
}
|
|
|
|
}
|
2024-08-12 05:13:32 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2024-09-13 03:30:34 -04:00
|
|
|
const permListFormat = []
|
|
|
|
permList.forEach((item, i)=>{
|
|
|
|
permListFormat.push({
|
|
|
|
translate: i === permList.length - 1 ? "%s" : "%s ",
|
|
|
|
color: colorList[i],
|
|
|
|
with: [
|
|
|
|
item
|
|
|
|
]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({
|
|
|
|
translate: '%s %s',
|
|
|
|
with: [
|
2024-09-13 03:30:34 -04:00
|
|
|
{
|
|
|
|
translate: "%s (%s):",
|
|
|
|
with: [
|
|
|
|
getMessage(c.lang, 'command.help.cmdList'),
|
|
|
|
permListFormat
|
|
|
|
]
|
|
|
|
},
|
2024-08-12 05:13:32 -04:00
|
|
|
commandList.sort(sortHelp)
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const printCmdHelp = (c) => {
|
2024-09-12 00:26:36 -04:00
|
|
|
let cmd
|
|
|
|
if (c.args.length >= 1) cmd = c.args[0].toLowerCase()
|
2024-08-25 21:33:32 -04:00
|
|
|
if (!cmds[cmd] || (cmds[cmd].hidden && c.type !== 'console')) {
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({ text: getMessage(c.lang, 'command.help.noCommand') })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let usage = getMessage(c.lang, `command.${cmd}.usage`).split('||')
|
|
|
|
let desc = getMessage(c.lang, `command.${cmd}.desc`)
|
|
|
|
if (cmds[cmd].usage) {
|
|
|
|
usage = cmds[cmd].usage.split('||')
|
|
|
|
}
|
|
|
|
if (cmds[cmd].desc) {
|
|
|
|
desc = cmds[cmd].desc
|
|
|
|
}
|
|
|
|
if (cmds[cmd].alias) {
|
|
|
|
console.log(cmds[cmds[cmd].alias])
|
|
|
|
usage = getMessage(c.lang, `command.${cmds[cmd].alias}.usage`).split('||')
|
|
|
|
desc = getMessage(c.lang, 'command.help.alias', [cmds[cmd].alias])
|
|
|
|
if (cmds[cmds[cmd].alias].usage) {
|
|
|
|
usage = cmds[cmds[cmd].alias].usage.split('||')
|
|
|
|
}
|
|
|
|
if (cmds[cmds[cmd].alias].desc) {
|
|
|
|
desc = cmds[cmds[cmd].alias].desc
|
|
|
|
}
|
|
|
|
}
|
2024-08-22 07:34:39 -04:00
|
|
|
for (const item of usage) {
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({
|
|
|
|
translate: getMessage(c.lang, 'command.help.commandUsage'),
|
|
|
|
color: c.colors.secondary,
|
|
|
|
with: [
|
|
|
|
{
|
|
|
|
text: cmd,
|
|
|
|
color: c.colors.primary
|
|
|
|
},
|
|
|
|
{
|
2024-08-22 07:34:39 -04:00
|
|
|
text: item,
|
2024-08-12 05:13:32 -04:00
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
c.reply({
|
|
|
|
translate: getMessage(c.lang, 'command.help.commandDesc'),
|
|
|
|
color: c.colors.secondary,
|
|
|
|
with: [
|
|
|
|
{
|
|
|
|
text: desc,
|
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
const permsN = getMessage(c.lang, 'command.help.permsNormal')
|
|
|
|
const permsT = getMessage(c.lang, 'command.help.permsTrusted')
|
|
|
|
const permsO = getMessage(c.lang, 'command.help.permsOwner')
|
|
|
|
const rPerms = cmds[cmd].level ? cmds[cmd].level : 0
|
|
|
|
c.reply({
|
|
|
|
translate: getMessage(c.lang, 'command.help.commandPerms'),
|
|
|
|
color: c.colors.secondary,
|
|
|
|
with: [
|
|
|
|
{
|
2024-09-06 16:59:16 -04:00
|
|
|
text: [permsN, permsT, permsO][rPerms],
|
2024-08-12 05:13:32 -04:00
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
execute: (c) => {
|
|
|
|
if (c.args.length > 0) {
|
|
|
|
printCmdHelp(c)
|
|
|
|
} else {
|
|
|
|
printHelp(c)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
aliases: [
|
|
|
|
'heko' // Parker2991 request
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
cmds.help = module.exports // Placed after to ensure that the correct values are added to cmds
|
|
|
|
if (cmds.help.level === undefined) {
|
|
|
|
cmds.help.level = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const i in cmds) {
|
|
|
|
if (cmds[i].aliases) {
|
2024-08-22 13:49:42 -04:00
|
|
|
for (const alias of cmds[i].aliases) {
|
2024-08-22 07:34:39 -04:00
|
|
|
cmds[alias] = {
|
2024-08-12 05:13:32 -04:00
|
|
|
alias: i,
|
|
|
|
usage: cmds[i].usage,
|
|
|
|
level: cmds[i].level,
|
|
|
|
hidden: true,
|
|
|
|
consoleIndex: cmds[i].consoleIndex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|