feat: add more stuff to AuthCommand but restrict setting other player's level to TrustLevel.MAX only
This commit is contained in:
@@ -1 +1 @@
|
||||
3297
|
||||
3301
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user