Some checks failed
Deploy to Dokku / docker (ubuntu-latest) (push) Has been cancelled
59 lines
2.6 KiB
Java
59 lines
2.6 KiB
Java
package cc.fascinated.bat.features.command;
|
|
|
|
import cc.fascinated.bat.command.BatSubCommand;
|
|
import cc.fascinated.bat.command.CommandInfo;
|
|
import cc.fascinated.bat.common.EmbedUtils;
|
|
import cc.fascinated.bat.features.Feature;
|
|
import cc.fascinated.bat.features.FeatureProfile;
|
|
import cc.fascinated.bat.model.BatGuild;
|
|
import cc.fascinated.bat.model.BatUser;
|
|
import cc.fascinated.bat.service.FeatureService;
|
|
import cc.fascinated.bat.service.GuildService;
|
|
import lombok.NonNull;
|
|
import net.dv8tion.jda.api.entities.Member;
|
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
|
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 org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
/**
|
|
* @author Fascinated (fascinated7)
|
|
*/
|
|
@Component("feature:disable.sub")
|
|
@CommandInfo(name = "disable", description = "Disables a feature")
|
|
public class DisableSubCommand extends BatSubCommand {
|
|
private final GuildService guildService;
|
|
|
|
@Autowired
|
|
public DisableSubCommand(@NonNull GuildService guildService) {
|
|
this.guildService = guildService;
|
|
super.addOption(OptionType.STRING, "feature", "The feature to disable", true);
|
|
}
|
|
|
|
@Override
|
|
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
|
|
FeatureProfile featureProfile = guild.getFeatureProfile();
|
|
OptionMapping featureOption = interaction.getOption("feature");
|
|
if (featureOption == null) {
|
|
interaction.replyEmbeds(EmbedUtils.errorEmbed().setDescription("You must provide a feature to disable").build()).queue();
|
|
return;
|
|
}
|
|
String featureName = featureOption.getAsString();
|
|
if (!FeatureService.INSTANCE.isFeature(featureName)) {
|
|
interaction.replyEmbeds(EmbedUtils.errorEmbed().setDescription("That feature does not exist").build()).queue();
|
|
return;
|
|
}
|
|
Feature feature = FeatureService.INSTANCE.getFeature(featureName);
|
|
if (featureProfile.isFeatureDisabled(feature)) {
|
|
interaction.replyEmbeds(EmbedUtils.errorEmbed().setDescription("That feature is already disabled").build()).queue();
|
|
return;
|
|
}
|
|
|
|
featureProfile.setFeatureState(feature, true);
|
|
guildService.saveGuild(guild);
|
|
interaction.replyEmbeds(EmbedUtils.successEmbed().setDescription("Successfully disabled the feature " + feature.getName()).build()).queue();
|
|
}
|
|
}
|