From e6773a9f62bddc73ed6bc131d2de8e9cf1c3b87f Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Mon, 13 Mar 2023 14:57:31 +0700 Subject: [PATCH] change hashing check in cmd handler a bit idk a rewrite already exist but idk idk --- commands/validate.js | 8 +++----- plugins/commands.js | 45 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/commands/validate.js b/commands/validate.js index 2ba1ea3..72f40c8 100644 --- a/commands/validate.js +++ b/commands/validate.js @@ -1,16 +1,14 @@ module.exports = { name: 'validate', - description: 'Validates hash', - alias: [], - usage: '', + description: 'Validates a hash', + alias: ['checkhash'], + usage: '', trusted: 1, execute (bot, username, sender, prefix, args, config, hash, ownerhash, selector) { if (args[0] === hash) { bot.tellraw(selector, { text: 'Valid hash', color: 'green' }) } else if (args[0] === ownerhash) { bot.tellraw(selector, { text: 'Valid OwnerHash', color: 'green' }) - } else { - bot.tellraw(selector, { text: 'Invalid hash', color: 'red' }) } } } diff --git a/plugins/commands.js b/plugins/commands.js index 3ee2d53..1bbc0ca 100644 --- a/plugins/commands.js +++ b/plugins/commands.js @@ -25,20 +25,49 @@ function inject (bot, dcclient, config) { try { const alias = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase())) - if (alias) command = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase())) + if (alias) command = alias + if (prefix === '*' && message.endsWith('*') && message !== '*') return if (!command) throw new Error(`Unknown command: "${commandName}"`) - if (command.name !== 'validate' && command.trusted === 1) { - if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'Trusted')) throw new Error('You\'re not in the trusted role!') - else if (!discord && args[0] !== hash) throw new Error('Invalid hash') - } else if (command.name !== 'validate' && command.trusted === 2) { - if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'ChomeNS')) throw new Error('You\'re not in the owner of this bot!') - else if (!discord && args[0] !== ownerhash) throw new Error('Invalid OwnerHash') + if (command.trusted > 0) { + const discordRoles = message.member?.roles?.cache // do i need the "?"s ? + + // TODO: Don't hardcode the roles + + // trusted and host + // discord + if ( + discord && + command.trusted === 1 && + !discordRoles.some((role) => role.name === 'Trusted' || role.name === 'Host') + ) throw new Error('You\'re not in the trusted role!') + // in game + if ( + !discord && + command.trusted === 1 && + args[0] !== hash && + args[0] !== ownerhash + + ) throw new Error('Invalid hash') + + // host only (yup i changed, owner doesn't exist anymore (kinda, we still call it ownerHashâ„¢)) + // discord + if ( + discord && + command.trusted === 2 && + !discordRoles.some((role) => role.name === 'Host') + ) throw new Error('You\'re not in the host role!') + // in game + if ( + !discord && + command.trusted === 2 && + args[0] !== ownerhash + ) throw new Error('Invalid OwnerHash') } if (prefix === config.discord.prefix) { - if (!command.discordExecute) throw new Error('This command is not yet supported on discord!') + if (!command.discordExecute) throw new Error('This command is not yet supported on Discord!') command.discordExecute(bot, username, sender, prefix, args, channeldc, message, config) } else { command.execute(bot, username, sender, prefix, args, config, hash, ownerhash, selector)