package cc.fascinated.bat.moderation.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.moderation.punish.Punishment; import cc.fascinated.bat.moderation.punish.PunishmentProfile; import cc.fascinated.bat.moderation.punish.PunishmentType; import cc.fascinated.bat.common.model.BatGuild; import cc.fascinated.bat.common.model.BatUser; import cc.fascinated.bat.service.UserService; 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.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.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * @author Fascinated (fascinated7) */ @Component @CommandInfo( name = "unmute", description = "Un-mutes a member", requiredPermissions = Permission.MANAGE_CHANNEL ) public class UnmuteCommand extends BatCommand { private final UserService userService; @Autowired public UnmuteCommand(@NonNull UserService userService) { this.userService = userService; super.addOptions( new OptionData(OptionType.USER, "member", "The member you want to un-mute", true), new OptionData(OptionType.STRING, "reason", "The reason for the un-mute", false) ); } @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) { OptionMapping memberOption = event.getOption("member"); OptionMapping reasonOption = event.getOption("reason"); assert memberOption != null; BatUser targetUser = userService.getUser(memberOption.getAsUser().getId()); if (targetUser == null) { event.replyEmbeds(EmbedUtils.errorEmbed() .setDescription("User not found") .build() ).queue(); return; } String reason = reasonOption == null ? null : reasonOption.getAsString(); PunishmentProfile profile = guild.getPunishmentProfile(); if (!profile.canPunish(guild, user, targetUser)) { event.replyEmbeds(EmbedUtils.errorEmbed() .setDescription("You cannot unmute this user") .build() ).queue(); return; } Punishment punishment = profile.removePunishment(targetUser, user, guild, PunishmentType.MUTE, reason); if (punishment == null) { event.replyEmbeds(EmbedUtils.errorEmbed() .setDescription("This user is not muted") .build() ).queue(); return; } profile.punishmentResponse(event, PunishmentType.MUTE, targetUser, reason, true, -1); } }