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

53 lines
2.2 KiB
Java
Raw Normal View History

2024-12-27 13:04:57 +00:00
package cc.fascinated.bat.leveling.command;
2024-07-06 04:04:38 +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-07-06 04:04:38 +01:00
import cc.fascinated.bat.common.EmbedUtils;
2024-12-27 13:04:57 +00:00
import cc.fascinated.bat.leveling.LevelingProfile;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
2024-07-06 04:04:38 +01:00
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;
2024-07-06 04:04:38 +01:00
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
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("leveling.channel:sub")
@CommandInfo(
name = "channel",
description = "Sets the notification channel for leveling"
)
public class ChannelSubCommand extends BatCommand {
@Autowired
public ChannelSubCommand() {
super.addOptions(
new OptionData(OptionType.CHANNEL, "channel", "The channel to set as the notification channel", 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) {
2024-07-06 04:04:38 +01:00
OptionMapping channelOption = event.getOption("channel");
2024-07-07 02:18:10 +01:00
assert channelOption != null;
2024-07-06 04:04:38 +01:00
GuildChannelUnion channelUnion = channelOption.getAsChannel();
TextChannel textChannel = channelUnion.asTextChannel();
LevelingProfile profile = guild.getLevelingProfile();
profile.setNotificationChannelId(textChannel.getId());
event.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Successfully set the notification channel to %s".formatted(textChannel.getAsMention()))
.build()).queue();
}
}