All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m42s
66 lines
3.1 KiB
Java
66 lines
3.1 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.common.TextChannelUtils;
|
|
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.Permission;
|
|
import net.dv8tion.jda.api.entities.Member;
|
|
import net.dv8tion.jda.api.entities.Message;
|
|
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;
|
|
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:channel.sub")
|
|
@CommandInfo(name = "channel", description = "Sets the birthday notification channel", requiredPermissions = Permission.MANAGE_SERVER)
|
|
public class ChannelSubCommand extends BatCommand {
|
|
@Autowired
|
|
public ChannelSubCommand() {
|
|
super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel birthdays will be sent in", 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();
|
|
OptionMapping option = event.getOption("channel");
|
|
if (option == null) {
|
|
if (!TextChannelUtils.isValidChannel(profile.getChannelId())) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("There is no channel set for birthday notifications. Please provide a channel to set the birthday channel to")
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
event.replyEmbeds(EmbedUtils.genericEmbed()
|
|
.setDescription("The current birthday channel is %s".formatted(TextChannelUtils.getChannelMention(profile.getChannelId())))
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
|
|
GuildChannelUnion targetChannel = option.getAsChannel();
|
|
if (targetChannel.getType() != ChannelType.TEXT) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("Invalid channel type, please provide a text channel")
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
|
|
profile.setChannelId(targetChannel.getId());
|
|
event.replyEmbeds(EmbedUtils.successEmbed()
|
|
.setDescription("Successfully set the birthday channel to %s".formatted(targetChannel.asTextChannel().getAsMention()))
|
|
.build()).queue();
|
|
}
|
|
}
|