refactor: make owner chomens bot commands auto validate

This commit is contained in:
Chayapak Supasakul 2025-09-29 15:20:23 +07:00
parent 8dcd2257f3
commit 03eb3c84f6
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA

View file

@ -73,18 +73,21 @@ public abstract class ChatScreenMixin {
ChipmunkMod.LOGGER.error("Error while trying to request TestBot webhook", e); ChipmunkMod.LOGGER.error("Error while trying to request TestBot webhook", e);
} }
}); });
} else if (ChipmunkMod.CONFIG.bots.chomens.autoValidate && chatText.startsWith(ChipmunkMod.CONFIG.bots.chomens.prefix)) { } else if (chatText.startsWith(ChipmunkMod.CONFIG.bots.chomens.prefix)) {
final List<ChomeNSBotCommand> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands; final List<ChomeNSBotCommand> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands;
final List<String> moreOrTrustedCommands = commands.stream() final List<String> moreOrTrustedCommands = new ArrayList<>();
.filter(command -> command.trustLevel() != ChomeNSBotCommand.TrustLevel.PUBLIC) final List<String> ownerCommands = new ArrayList<>();
.map(command -> command.name().toLowerCase())
.toList();
final List<String> aliases = new ArrayList<>(); final List<String> aliases = new ArrayList<>();
for (final ChomeNSBotCommand command : commands) { for (final ChomeNSBotCommand command : commands) {
if (command.trustLevel() == ChomeNSBotCommand.TrustLevel.PUBLIC) continue; if (command.trustLevel() == ChomeNSBotCommand.TrustLevel.PUBLIC) continue;
final String stringCommand = command.name().toLowerCase();
moreOrTrustedCommands.add(stringCommand);
if (command.trustLevel() == ChomeNSBotCommand.TrustLevel.OWNER) ownerCommands.add(stringCommand);
aliases.addAll(command.aliases()); aliases.addAll(command.aliases());
} }
@ -93,8 +96,13 @@ public abstract class ChatScreenMixin {
final int prefixLength = ChipmunkMod.CONFIG.bots.chomens.prefix.length(); final int prefixLength = ChipmunkMod.CONFIG.bots.chomens.prefix.length();
if ( if (
moreOrTrustedCommands.contains(chatCommand) || ownerCommands.contains(chatCommand) ||
aliases.contains(chatCommand.substring(prefixLength)) (ChipmunkMod.CONFIG.bots.chomens.autoValidate &&
(
moreOrTrustedCommands.contains(chatCommand)
|| aliases.contains(chatCommand.substring(prefixLength))
)
)
) { ) {
try { try {
BotValidationUtilities.chomens(chatText.substring(prefixLength)); BotValidationUtilities.chomens(chatText.substring(prefixLength));