change hashing check in cmd handler a bit

idk a rewrite already exist but idk idk
This commit is contained in:
ChomeNS 2023-03-13 14:57:31 +07:00
parent bade4a4b89
commit e6773a9f62
2 changed files with 40 additions and 13 deletions

View file

@ -1,16 +1,14 @@
module.exports = {
name: 'validate',
description: 'Validates hash',
alias: [],
usage: '<hash>',
description: 'Validates a hash',
alias: ['checkhash'],
usage: '<hash|ownerHash>',
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' })
}
}
}

View file

@ -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)