diff --git a/build-number.txt b/build-number.txt index a01282d2..d0cc93ed 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1270 \ No newline at end of file +1274 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java b/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java index 36da7902..5c146c76 100644 --- a/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java +++ b/src/main/java/me/chayapak1/chomens_bot/command/CommandContext.java @@ -19,6 +19,8 @@ public class CommandContext { public final boolean inGame; + public TrustLevel trustLevel = TrustLevel.PUBLIC; + public String commandName = null; public String userInputCommandName = null; diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java index 57691454..75fd3014 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java @@ -1,10 +1,6 @@ package me.chayapak1.chomens_bot.commands; -import me.chayapak1.chomens_bot.Bot; -import me.chayapak1.chomens_bot.command.Command; -import me.chayapak1.chomens_bot.command.CommandContext; -import me.chayapak1.chomens_bot.command.CommandException; -import me.chayapak1.chomens_bot.command.TrustLevel; +import me.chayapak1.chomens_bot.command.*; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -12,7 +8,7 @@ public class ValidateCommand extends Command { public ValidateCommand () { super( "validate", - "Validates a hash", + "Validates/shows your trust level", new String[] { "" }, new String[] { "checkhash" }, TrustLevel.TRUSTED, @@ -22,18 +18,16 @@ public class ValidateCommand extends Command { @Override public Component execute(CommandContext context) throws CommandException { - final Bot bot = context.bot; - - final String[] fullArgs = context.fullArgs; - - if (fullArgs.length == 0) return null; - - final String hash = fullArgs[0]; - - if (bot.hashing.isCorrectHash(hash, context.userInputCommandName, context.sender)) return Component.text("Valid trusted hash").color(NamedTextColor.GREEN); - else if (bot.hashing.isCorrectAdminHash(hash, context.userInputCommandName, context.sender)) return Component.text("Valid admin hash").color(NamedTextColor.GREEN); - else if (bot.hashing.isCorrectOwnerHash(hash, context.userInputCommandName, context.sender)) return Component.text("Valid owner hash").color(NamedTextColor.GREEN); - - return null; + if (context instanceof DiscordCommandContext) return Component + .translatable("You are trusted! (%s)") + .arguments(Component.text(context.trustLevel.name())) + .color(NamedTextColor.GREEN); + else if (context instanceof ConsoleCommandContext) return Component + .text("You are the console! You have no trust level") + .color(NamedTextColor.GREEN); + else return Component + .translatable("Valid hash (%s)") + .arguments(Component.text(context.trustLevel.name())) + .color(NamedTextColor.GREEN); } } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java index 468cee16..b0c07fa6 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java @@ -124,45 +124,59 @@ public class CommandHandlerPlugin { final List roles = member.getRoles(); - final String trustedRoleName = bot.config.discord.trustedRoleName; - final String adminRoleName = bot.config.discord.adminRoleName; - final String ownerRoleName = bot.config.discord.ownerRoleName; + final boolean hasTrustedRole = roles.stream().anyMatch(role -> role.getName().equalsIgnoreCase(bot.config.discord.trustedRoleName)); + final boolean hasAdminRole = roles.stream().anyMatch(role -> role.getName().equalsIgnoreCase(bot.config.discord.adminRoleName)); + final boolean hasOwnerRole = roles.stream().anyMatch(role -> role.getName().equalsIgnoreCase(bot.config.discord.ownerRoleName)); if ( command.trustLevel == TrustLevel.TRUSTED && - roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(trustedRoleName)) && - roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(adminRoleName)) && - roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(ownerRoleName)) + !hasTrustedRole && + !hasAdminRole && + !hasOwnerRole ) return Component.text("You're not in the trusted role!").color(NamedTextColor.RED); if ( command.trustLevel == TrustLevel.ADMIN && - roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(adminRoleName)) && - roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(ownerRoleName)) + !hasAdminRole && + !hasOwnerRole ) return Component.text("You're not in the admin role!").color(NamedTextColor.RED); if ( command.trustLevel == TrustLevel.OWNER && - roles.stream().noneMatch(role -> role.getName().equalsIgnoreCase(ownerRoleName)) + !hasOwnerRole ) return Component.text("You're not in the owner role!").color(NamedTextColor.RED); + + context.trustLevel = hasOwnerRole ? TrustLevel.OWNER : + hasAdminRole ? TrustLevel.ADMIN : + hasTrustedRole ? TrustLevel.TRUSTED : + TrustLevel.PUBLIC; } else { + final boolean correctHash = bot.hashing.isCorrectHash(userHash, splitInput[0], context.sender); + final boolean correctAdminHash = bot.hashing.isCorrectAdminHash(userHash, splitInput[0], context.sender); + final boolean correctOwnerHash = bot.hashing.isCorrectOwnerHash(userHash, splitInput[0], context.sender); + if ( command.trustLevel == TrustLevel.TRUSTED && - !bot.hashing.isCorrectHash(userHash, splitInput[0], context.sender) && - !bot.hashing.isCorrectAdminHash(userHash, splitInput[0], context.sender) && - !bot.hashing.isCorrectOwnerHash(userHash, splitInput[0], context.sender) + !correctHash && + !correctAdminHash && + !correctOwnerHash ) return Component.text("Invalid hash").color(NamedTextColor.RED); if ( command.trustLevel == TrustLevel.ADMIN && - !bot.hashing.isCorrectAdminHash(userHash, splitInput[0], context.sender) && - !bot.hashing.isCorrectOwnerHash(userHash, splitInput[0], context.sender) + !correctAdminHash && + !correctOwnerHash ) return Component.text("Invalid admin hash").color(NamedTextColor.RED); if ( command.trustLevel == TrustLevel.OWNER && - !bot.hashing.isCorrectOwnerHash(userHash, splitInput[0], context.sender) + !correctOwnerHash ) return Component.text("Invalid owner hash").color(NamedTextColor.RED); + + context.trustLevel = correctOwnerHash ? TrustLevel.OWNER : + correctAdminHash ? TrustLevel.ADMIN : + correctHash ? TrustLevel.TRUSTED : + TrustLevel.PUBLIC; } }