package cc.fascinated.bat.birthday.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.birthday.UserBirthday; import cc.fascinated.bat.birthday.profile.BirthdayProfile; import cc.fascinated.bat.common.model.BatGuild; import cc.fascinated.bat.common.model.BatUser; import lombok.NonNull; 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("birthday:private.sub") @CommandInfo(name = "private", description = "Changes whether your birthday is private or not") public class PrivateSubCommand extends BatCommand { @Autowired public PrivateSubCommand() { super.addOptions(new OptionData(OptionType.BOOLEAN, "enabled", "Whether your birthday is private or not", true)); } @Override public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) { BirthdayProfile profile = guild.getBirthdayProfile(); OptionMapping enabledOption = event.getOption("enabled"); assert enabledOption != null; boolean enabled = enabledOption.getAsBoolean(); UserBirthday birthday = profile.getBirthday(user.getId()); if (birthday == null) { event.replyEmbeds(EmbedUtils.errorEmbed() .setDescription("You have not set your birthday yet") .build()).queue(); return; } birthday.setHidden(enabled); event.replyEmbeds(EmbedUtils.successEmbed() .setDescription("Your birthday privacy settings have been updated\n\n**Private:** " + (enabled ? "Yes" : "No")) .build()).queue(); } }