Files
Bat/src/main/java/cc/fascinated/bat/birthday/command/PrivateSubCommand.java

54 lines
2.3 KiB
Java
Raw Normal View History

2024-12-27 13:04:57 +00:00
package cc.fascinated.bat.birthday.command;
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
2024-12-27 13:04:57 +00:00
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;
2024-07-16 14:35:02 +01:00
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;
2024-07-04 08:47:32 -04:00
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")
2024-07-04 08:47:32 -04:00
public class PrivateSubCommand extends BatCommand {
@Autowired
public PrivateSubCommand() {
2024-07-04 08:47:32 -04:00
super.addOptions(new OptionData(OptionType.BOOLEAN, "enabled", "Whether your birthday is private or not", true));
}
@Override
2024-07-16 14:35:02 +01:00
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) {
BirthdayProfile profile = guild.getBirthdayProfile();
2024-07-01 15:27:39 +01:00
OptionMapping enabledOption = event.getOption("enabled");
2024-07-07 02:18:10 +01:00
assert enabledOption != null;
boolean enabled = enabledOption.getAsBoolean();
2024-07-07 02:18:10 +01:00
UserBirthday birthday = profile.getBirthday(user.getId());
if (birthday == null) {
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("You have not set your birthday yet")
.build()).queue();
return;
}
birthday.setHidden(enabled);
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Your birthday privacy settings have been updated\n\n**Private:** " + (enabled ? "Yes" : "No"))
.build()).queue();
}
}