82 lines
3.5 KiB
Java
82 lines
3.5 KiB
Java
package cc.fascinated.bat.counter.command;
|
|
|
|
import cc.fascinated.bat.Emojis;
|
|
import cc.fascinated.bat.common.oldcommand.BatCommand;
|
|
import cc.fascinated.bat.common.oldcommand.CommandInfo;
|
|
import cc.fascinated.bat.common.EmbedUtils;
|
|
import cc.fascinated.bat.counter.CounterChannel;
|
|
import cc.fascinated.bat.counter.CounterProfile;
|
|
import cc.fascinated.bat.common.model.BatGuild;
|
|
import cc.fascinated.bat.common.model.BatUser;
|
|
import lombok.NonNull;
|
|
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.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.stereotype.Component;
|
|
|
|
/**
|
|
* @author Fascinated (fascinated7)
|
|
*/
|
|
@Component("counter.set:sub")
|
|
@CommandInfo(name = "set", description = "Set the current count in a channel")
|
|
public class SetSubCommand extends BatCommand {
|
|
public SetSubCommand() {
|
|
super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel to set the count in", true));
|
|
super.addOptions(new OptionData(OptionType.INTEGER, "count", "The count to set", true));
|
|
}
|
|
|
|
@Override
|
|
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) {
|
|
OptionMapping channelOption = event.getOption("channel");
|
|
assert channelOption != null;
|
|
OptionMapping countOption = event.getOption("count");
|
|
assert countOption != null;
|
|
|
|
GuildChannelUnion targetChannel = channelOption.getAsChannel();
|
|
if (targetChannel.getType() != ChannelType.TEXT) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("%s The channel must be a text channel".formatted(Emojis.CROSS_MARK_EMOJI))
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
TextChannel textChannel = targetChannel.asTextChannel();
|
|
int count = countOption.getAsInt();
|
|
|
|
CounterProfile profile = guild.getCounterProfile();
|
|
if (profile == null) {
|
|
return;
|
|
}
|
|
|
|
// Check if the channel is a counter channel
|
|
CounterChannel counterChannel = profile.getCounterChannel(textChannel.getId());
|
|
if (counterChannel == null) {
|
|
event.replyEmbeds(EmbedUtils.errorEmbed()
|
|
.setDescription("%s The channel %s is not a counter channel".formatted(
|
|
Emojis.CROSS_MARK_EMOJI,
|
|
textChannel.getAsMention()
|
|
))
|
|
.build()).queue();
|
|
return;
|
|
}
|
|
|
|
counterChannel.setCurrentCount(count);
|
|
event.replyEmbeds(EmbedUtils.successEmbed()
|
|
.setDescription("%s Successfully set the count in %s to %d".formatted(
|
|
Emojis.CHECK_MARK_EMOJI,
|
|
textChannel.getAsMention(),
|
|
count
|
|
))
|
|
.build()).queue();
|
|
counterChannel.getChannel().sendMessage("The count has been set to `%s`".formatted(
|
|
count
|
|
)).queue();
|
|
}
|
|
}
|