Bat/src/main/java/cc/fascinated/bat/birthday/command/ChannelSubCommand.java

66 lines
3.1 KiB
Java
Raw Normal View History

2024-12-27 13:04:57 +00:00
package cc.fascinated.bat.birthday.command;
2024-06-26 12:19:11 +01:00
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
2024-06-26 12:19:11 +01:00
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.TextChannelUtils;
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
2024-06-26 12:19:11 +01:00
import lombok.NonNull;
import net.dv8tion.jda.api.Permission;
2024-06-26 12:19:11 +01:00
import net.dv8tion.jda.api.entities.Member;
2024-07-16 14:35:02 +01:00
import net.dv8tion.jda.api.entities.Message;
2024-06-26 12:19:11 +01:00
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
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;
2024-06-26 12:19:11 +01:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("birthday:channel.sub")
2024-06-27 19:36:52 +01:00
@CommandInfo(name = "channel", description = "Sets the birthday notification channel", requiredPermissions = Permission.MANAGE_SERVER)
2024-07-04 08:47:32 -04:00
public class ChannelSubCommand extends BatCommand {
2024-06-26 12:19:11 +01:00
@Autowired
public ChannelSubCommand() {
2024-07-04 08:47:32 -04:00
super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel birthdays will be sent in", false));
2024-06-26 12:19:11 +01:00
}
@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 option = event.getOption("channel");
2024-06-26 12:19:11 +01:00
if (option == null) {
if (!TextChannelUtils.isValidChannel(profile.getChannelId())) {
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.errorEmbed()
2024-06-26 12:41:18 +01:00
.setDescription("There is no channel set for birthday notifications. Please provide a channel to set the birthday channel to")
2024-06-26 12:19:11 +01:00
.build()).queue();
return;
}
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.genericEmbed()
2024-06-26 12:19:11 +01:00
.setDescription("The current birthday channel is %s".formatted(TextChannelUtils.getChannelMention(profile.getChannelId())))
.build()).queue();
return;
}
GuildChannelUnion targetChannel = option.getAsChannel();
if (targetChannel.getType() != ChannelType.TEXT) {
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.errorEmbed()
2024-06-26 12:19:11 +01:00
.setDescription("Invalid channel type, please provide a text channel")
.build()).queue();
return;
}
profile.setChannelId(targetChannel.getId());
2024-07-01 15:27:39 +01:00
event.replyEmbeds(EmbedUtils.successEmbed()
2024-06-26 12:19:11 +01:00
.setDescription("Successfully set the birthday channel to %s".formatted(targetChannel.asTextChannel().getAsMention()))
.build()).queue();
}
}