All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m42s
77 lines
3.4 KiB
Java
77 lines
3.4 KiB
Java
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 cc.fascinated.bat.service.UserService;
|
|
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:view.sub")
|
|
@CommandInfo(name = "view", description = "Add your birthday to this guild")
|
|
public class ViewSubCommand extends BatCommand {
|
|
private final UserService userService;
|
|
|
|
@Autowired
|
|
public ViewSubCommand(@NonNull UserService userService) {
|
|
this.userService = userService;
|
|
super.addOptions(new OptionData(OptionType.USER, "user", "The user to view the birthday of", false));
|
|
}
|
|
|
|
@Override
|
|
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) {
|
|
BirthdayProfile profile = guild.getBirthdayProfile();
|
|
if (!profile.hasChannelSetup()) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("Birthdays have not been enabled in this guild. Please ask an administrator to enable them.")
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
|
|
OptionMapping birthdayOption = event.getOption("user");
|
|
BatUser target = birthdayOption == null ? user : userService.getUser(birthdayOption.getAsUser().getId());
|
|
if (target == null) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("You must provide a valid user")
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
UserBirthday birthday = profile.getBirthday(target.getId());
|
|
if (birthday == null) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("%s does not have a birthday set".formatted(target.getDiscordUser().getAsMention()))
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
if (birthday.isHidden() && !user.getId().equals(target.getId())) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("%s has their birthday set to private".formatted(target.getDiscordUser().getAsMention()))
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
|
|
event.replyEmbeds(EmbedUtils.successEmbed()
|
|
.setDescription("%s was born on <t:%s:D> they are `%s` years old!".formatted(
|
|
target.getDiscordUser().getAsMention(), birthday.getBirthday().toInstant().toEpochMilli()/1000,
|
|
birthday.calculateAge()
|
|
))
|
|
.build()).queue();
|
|
}
|
|
}
|