mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 19:56: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);
|
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));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue