All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m42s
85 lines
3.8 KiB
Java
85 lines
3.8 KiB
Java
package cc.fascinated.bat.counter.command;
|
|
|
|
import cc.fascinated.bat.Emojis;
|
|
import cc.fascinated.bat.common.command.BatCommand;
|
|
import cc.fascinated.bat.common.command.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.setbreaking:sub")
|
|
@CommandInfo(name = "setbreaking", description = "Updates if the counter should break")
|
|
public class SetBreakingSubCommand extends BatCommand {
|
|
public SetBreakingSubCommand() {
|
|
super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel to set the count in", true));
|
|
super.addOptions(new OptionData(OptionType.BOOLEAN, "breakable", "Should the channel break on a invalid or wrong number", 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 breakableOption = event.getOption("breakable");
|
|
assert breakableOption != 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();
|
|
boolean breakable = breakableOption.getAsBoolean();
|
|
|
|
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.setBreakable(breakable);
|
|
event.replyEmbeds(EmbedUtils.successEmbed()
|
|
.setDescription("%s The counter in %s will %s break on an invalid or wrong number".formatted(
|
|
Emojis.CHECK_MARK_EMOJI,
|
|
textChannel.getAsMention(),
|
|
breakable ? "now" : "no longer"
|
|
))
|
|
.build()).queue();
|
|
if (channel.getId().equals(textChannel.getId())) { // Don't send in the same channel
|
|
return;
|
|
}
|
|
counterChannel.getChannel().sendMessage("The counter will %s break on an invalid or wrong number".formatted(
|
|
breakable ? "now" : "no longer"
|
|
)).queue();
|
|
}
|
|
}
|