fix: limit AuthCommand a bit... it seem dumb idea :(

This commit is contained in:
ChomeNS
2025-05-22 20:35:51 +07:00
parent ad5e203417
commit 8c8a058f38
3 changed files with 7 additions and 28 deletions

View File

@@ -1 +1 @@
3278
3281

View File

@@ -5,11 +5,8 @@ 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.data.player.PlayerEntry;
import net.kyori.adventure.text.Component;
import java.util.Arrays;
public class AuthCommand extends Command {
public AuthCommand () {
super(
@@ -18,38 +15,20 @@ public class AuthCommand extends Command {
new String[] {},
TrustLevel.TRUSTED
);
final String trustLevels = String.join(" | ", Arrays.stream(TrustLevel.values()).map(Enum::name).toList());
this.usages = new String[] { "[player] [" + trustLevels + "]" };
}
@Override
public Component execute (final CommandContext context) throws CommandException {
context.checkOverloadArgs(0);
final Bot bot = context.bot;
final String playerString = context.getString(false, false);
PlayerEntry player = null;
if (!playerString.isEmpty()) player = bot.players.getEntry(playerString);
if (player == null) player = context.sender;
TrustLevel trustLevel = context.getEnum(false, TrustLevel.class);
if (trustLevel == null) trustLevel = context.trustLevel;
if (trustLevel.level > context.trustLevel.level) throw new CommandException(
Component.translatable(
"commands.auth.error.privilege_escalate"
)
);
player.authenticatedTrustLevel = trustLevel;
context.sender.authenticatedTrustLevel = context.trustLevel;
return Component.translatable(
"commands.auth.output",
bot.colorPalette.defaultColor,
Component.text(player.profile.getName(), bot.colorPalette.username),
player.authenticatedTrustLevel.component
context.sender.authenticatedTrustLevel.component
);
}
}

View File

@@ -34,8 +34,8 @@
"commands.generic.error.database_disabled": "Database is not enabled in the bot's configuration",
"commands.generic.error.discord_disabled": "The bot's Discord integration has to be enabled to use this command",
"commands.auth.description": "Authenticates yourself or a player so you don't have to input the hash every time you use the bot",
"commands.auth.output": "Player %s has been authenticated with trust level %s",
"commands.auth.description": "Authenticates yourself so you don't have to input the hash every time you use the bot",
"commands.auth.output": "You been authenticated with trust level %s",
"commands.auth.error.privilege_escalate": "You cannot escalate privileges!",
"commands.botvisibility.description": "Changes the bot's visibility",