Bat/src/main/java/cc/fascinated/bat/leveling/command/ResetSubCommand.java
Lee b3a6284e40
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m42s
cleanup
2024-12-27 13:04:57 +00:00

53 lines
2.0 KiB
Java

package cc.fascinated.bat.leveling.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.leveling.LevelingProfile;
import cc.fascinated.bat.leveling.UserLevel;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import lombok.NonNull;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("leveling.reset:sub")
@CommandInfo(
name = "reset",
description = "Resets the level and xp of the user",
requiredPermissions = Permission.MANAGE_SERVER
)
public class ResetSubCommand extends BatCommand {
public ResetSubCommand() {
super.addOptions(
new OptionData(OptionType.USER, "user", "The user to reset", true)
);
}
@Override
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) {
OptionMapping userOption = event.getOption("user");
assert userOption != null;
User target = userOption.getAsUser();
LevelingProfile profile = guild.getLevelingProfile();
UserLevel level = profile.getUserLevel(target.getId());
level.reset();
event.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Reset Level and XP for %s!".formatted(target.getAsMention()))
.build()).queue();
}
}