mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
refactor: make owner chomens bot commands auto validate
This commit is contained in:
parent
8dcd2257f3
commit
03eb3c84f6
1 changed files with 16 additions and 8 deletions
|
|
@ -73,18 +73,21 @@ public abstract class ChatScreenMixin {
|
|||
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<String> moreOrTrustedCommands = commands.stream()
|
||||
.filter(command -> command.trustLevel() != ChomeNSBotCommand.TrustLevel.PUBLIC)
|
||||
.map(command -> command.name().toLowerCase())
|
||||
.toList();
|
||||
|
||||
final List<String> moreOrTrustedCommands = new ArrayList<>();
|
||||
final List<String> ownerCommands = new ArrayList<>();
|
||||
final List<String> aliases = new ArrayList<>();
|
||||
|
||||
for (final ChomeNSBotCommand command : commands) {
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +96,13 @@ public abstract class ChatScreenMixin {
|
|||
final int prefixLength = ChipmunkMod.CONFIG.bots.chomens.prefix.length();
|
||||
|
||||
if (
|
||||
moreOrTrustedCommands.contains(chatCommand) ||
|
||||
aliases.contains(chatCommand.substring(prefixLength))
|
||||
ownerCommands.contains(chatCommand) ||
|
||||
(ChipmunkMod.CONFIG.bots.chomens.autoValidate &&
|
||||
(
|
||||
moreOrTrustedCommands.contains(chatCommand)
|
||||
|| aliases.contains(chatCommand.substring(prefixLength))
|
||||
)
|
||||
)
|
||||
) {
|
||||
try {
|
||||
BotValidationUtilities.chomens(chatText.substring(prefixLength));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue