diff --git a/build-number.txt b/build-number.txt index 4dbebb27..ef20e168 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3297 \ No newline at end of file +3301 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/AuthCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/AuthCommand.java index b7e094e9..df2842b7 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/AuthCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/AuthCommand.java @@ -5,13 +5,14 @@ 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; public class AuthCommand extends Command { public AuthCommand () { super( "auth", - new String[] {}, + new String[] { "[TrustLevel]" }, new String[] {}, TrustLevel.TRUSTED ); @@ -19,16 +20,40 @@ public class AuthCommand extends Command { @Override public Component execute (final CommandContext context) throws CommandException { - context.checkOverloadArgs(0); + final boolean allowSettingOthers = context.trustLevel == TrustLevel.MAX; + + if (!allowSettingOthers) context.checkOverloadArgs(1); final Bot bot = context.bot; - context.sender.authenticatedTrustLevel = context.trustLevel; + TrustLevel trustLevel = context.getEnum(false, TrustLevel.class); + if (trustLevel == null) trustLevel = context.trustLevel; - return Component.translatable( - "commands.auth.output", - bot.colorPalette.defaultColor, - context.sender.authenticatedTrustLevel.component + if (trustLevel.level > context.trustLevel.level) throw new CommandException( + Component.translatable("commands.auth.error.privilege_escalate") ); + + final String targetString = context.getString(true, false); + + PlayerEntry target = null; + if (allowSettingOthers && !targetString.isEmpty()) target = bot.players.getEntry(targetString); + if (target == null) target = context.sender; + + target.authenticatedTrustLevel = trustLevel; + + if (target.equals(context.sender)) { + return Component.translatable( + "commands.auth.self", + bot.colorPalette.defaultColor, + target.authenticatedTrustLevel.component + ); + } else { + return Component.translatable( + "commands.auth.others", + bot.colorPalette.defaultColor, + Component.text(target.profile.getName(), bot.colorPalette.username), + target.authenticatedTrustLevel.component + ); + } } } diff --git a/src/main/resources/language-en_us.json b/src/main/resources/language-en_us.json index 2106a306..c044d8bc 100644 --- a/src/main/resources/language-en_us.json +++ b/src/main/resources/language-en_us.json @@ -35,7 +35,8 @@ "commands.generic.error.discord_disabled": "The bot's Discord integration has to be enabled to use this command", "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.self": "You been authenticated with trust level %s", + "commands.auth.others": "%s has been authenticated with trust level %s", "commands.auth.error.privilege_escalate": "You cannot escalate privileges!", "commands.botvisibility.description": "Changes the bot's visibility",