rework command system
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.botadmin.premium;
|
||||
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -12,11 +11,13 @@ import org.springframework.stereotype.Component;
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "premiumadmin", description = "Set a guild as premium", botOwnerOnly = true, category = Category.BOT_ADMIN)
|
||||
@CommandInfo(name = "premiumadmin", description = "Set a guild as premium", botOwnerOnly = true)
|
||||
public class PremiumAdminCommand extends BatCommand {
|
||||
@Autowired
|
||||
public PremiumAdminCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(SetSubCommand.class));
|
||||
super.addSubCommand(context.getBean(RemoveSubCommand.class));
|
||||
super.addSubCommands(
|
||||
context.getBean(SetSubCommand.class),
|
||||
context.getBean(RemoveSubCommand.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.botadmin.premium;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
@ -12,6 +12,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -20,13 +21,13 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "remove", description = "Remove premium from a guild")
|
||||
public class RemoveSubCommand extends BatSubCommand {
|
||||
public class RemoveSubCommand extends BatCommand {
|
||||
private final GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
public RemoveSubCommand(GuildService guildService) {
|
||||
this.guildService = guildService;
|
||||
super.addOption(OptionType.STRING, "guild", "The guild id to set as premium", true);
|
||||
super.addOptions(new OptionData(OptionType.STRING, "guild", "The guild id to set as premium", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.botadmin.premium;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
import cc.fascinated.bat.model.BatUser;
|
||||
@ -12,6 +12,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -20,14 +21,16 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "set", description = "Adds premium to a guild")
|
||||
public class SetSubCommand extends BatSubCommand {
|
||||
public class SetSubCommand extends BatCommand {
|
||||
private final GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
public SetSubCommand(@NonNull GuildService guildService) {
|
||||
this.guildService = guildService;
|
||||
super.addOption(OptionType.STRING, "guild", "The guild id to set as premium", true);
|
||||
super.addOption(OptionType.BOOLEAN, "infinite", "Whether the premium length should be infinite", true);
|
||||
super.addOptions(
|
||||
new OptionData(OptionType.STRING, "guild", "The guild id to set as premium", true),
|
||||
new OptionData(OptionType.BOOLEAN, "infinite", "Whether the premium length should be infinite", true)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -24,7 +25,7 @@ import org.springframework.stereotype.Component;
|
||||
@CommandInfo(name = "lookupuser", description = "Lookup a user", userInstall = true)
|
||||
public class LookupUserCommand extends BatCommand {
|
||||
public LookupUserCommand() {
|
||||
super.addOption(OptionType.STRING, "id", "The id of the user", true);
|
||||
super.addOptions(new OptionData(OptionType.STRING, "id", "The id of the user", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,6 +11,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -43,7 +44,7 @@ public class EightBallCommand extends BatCommand {
|
||||
};
|
||||
|
||||
public EightBallCommand() {
|
||||
super.addOption(OptionType.STRING, "question", "The question you want to ask the 8ball", true);
|
||||
super.addOptions(new OptionData(OptionType.STRING, "question", "The question you want to ask the 8ball", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "cat", description = "Get a random cat image")
|
||||
public class CatSubCommand extends BatSubCommand {
|
||||
public class CatSubCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
CatImageToken[] responseEntity = WebRequest.getAsEntity("https://api.thecatapi.com/v1/images/search", CatImageToken[].class);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "dog", description = "Get a random dog image")
|
||||
public class DogSubCommand extends BatSubCommand {
|
||||
public class DogSubCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
RandomImage responseEntity = WebRequest.getAsEntity("https://dog.ceo/api/breeds/image/random", RandomImage.class);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "duck", description = "Get a random duck image")
|
||||
public class DuckSubCommand extends BatSubCommand {
|
||||
public class DuckSubCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
RandomDuck responseEntity = WebRequest.getAsEntity("https://random-d.uk/api/v2/random", RandomDuck.class);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.fun.image;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.common.WebRequest;
|
||||
@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "fox", description = "Get a random fox image")
|
||||
public class FoxSubCommand extends BatSubCommand {
|
||||
public class FoxSubCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
RandomFoxToken responseEntity = WebRequest.getAsEntity("https://randomfox.ca/floof/", RandomFoxToken.class);
|
||||
|
@ -16,9 +16,11 @@ import org.springframework.stereotype.Component;
|
||||
public class ImageCommand extends BatCommand {
|
||||
@Autowired
|
||||
public ImageCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(CatSubCommand.class));
|
||||
super.addSubCommand(context.getBean(DogSubCommand.class));
|
||||
super.addSubCommand(context.getBean(FoxSubCommand.class));
|
||||
super.addSubCommand(context.getBean(DuckSubCommand.class));
|
||||
super.addSubCommands(
|
||||
context.getBean(CatSubCommand.class),
|
||||
context.getBean(DogSubCommand.class),
|
||||
context.getBean(FoxSubCommand.class),
|
||||
context.getBean(DuckSubCommand.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package cc.fascinated.bat.features.base.commands.general;
|
||||
|
||||
import cc.fascinated.bat.Consts;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.Category;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
@ -17,7 +16,6 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.emoji.Emoji;
|
||||
import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||
@ -29,7 +27,6 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
@ -62,44 +59,45 @@ public class HelpCommand extends BatCommand implements EventListener {
|
||||
event.reply("Invalid category selected.").queue();
|
||||
return;
|
||||
}
|
||||
event.reply("hello this doesnt work yet").queue();
|
||||
|
||||
StringBuilder commands = new StringBuilder();
|
||||
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category, true);
|
||||
if (categoryCommands.isEmpty()) {
|
||||
commands = new StringBuilder("No commands available in this category.");
|
||||
} else {
|
||||
for (BatCommand command : categoryCommands) {
|
||||
if (!command.getSubCommands().isEmpty()) {
|
||||
for (Map.Entry<String, BatSubCommand> entry : command.getSubCommands().entrySet()) {
|
||||
BatSubCommand subCommand = entry.getValue();
|
||||
SubcommandData commandData = subCommand.getCommandData();
|
||||
commands.append("</%s %s:%s> - %s\n".formatted(
|
||||
command.getCommandInfo().name(),
|
||||
commandData.getName(),
|
||||
subCommand.getCommandSnowflake(),
|
||||
commandData.getDescription()
|
||||
));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
commands.append("</%s:%s> - %s\n".formatted(
|
||||
command.getCommandInfo().name(),
|
||||
command.getCommandSnowflake(),
|
||||
command.getCommandInfo().description()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum();
|
||||
event.editMessageEmbeds(EmbedUtils.genericEmbed()
|
||||
.setAuthor("%s Category".formatted(category.getName()))
|
||||
.setDescription("%s command%s (with %s sub-command%s)\n\n**Commands:**\n%s".formatted(
|
||||
categoryCommands.size(),
|
||||
categoryCommands.size() == 1 ? "" : "s",
|
||||
subCommands,
|
||||
subCommands == 1 ? "" : "s",
|
||||
commands.toString()
|
||||
)).build()).queue();
|
||||
// StringBuilder commands = new StringBuilder();
|
||||
// List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category, true);
|
||||
// if (categoryCommands.isEmpty()) {
|
||||
// commands = new StringBuilder("No commands available in this category.");
|
||||
// } else {
|
||||
// for (BatCommand command : categoryCommands) {
|
||||
// if (!command.getSubCommands().isEmpty()) {
|
||||
// for (Map.Entry<String, BatSubCommand> entry : command.getSubCommands().entrySet()) {
|
||||
// BatSubCommand subCommand = entry.getValue();
|
||||
// SubcommandData commandData = subCommand.getCommandData();
|
||||
// commands.append("</%s %s:%s> - %s\n".formatted(
|
||||
// command.getCommandInfo().name(),
|
||||
// commandData.getName(),
|
||||
// subCommand.getCommandSnowflake(),
|
||||
// commandData.getDescription()
|
||||
// ));
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// commands.append("</%s:%s> - %s\n".formatted(
|
||||
// command.getCommandInfo().name(),
|
||||
// command.getCommandSnowflake(),
|
||||
// command.getCommandInfo().description()
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// int subCommands = categoryCommands.stream().mapToInt(command -> command.getSubCommands().size()).sum();
|
||||
// event.editMessageEmbeds(EmbedUtils.genericEmbed()
|
||||
// .setAuthor("%s Category".formatted(category.getName()))
|
||||
// .setDescription("%s command%s (with %s sub-command%s)\n\n**Commands:**\n%s".formatted(
|
||||
// categoryCommands.size(),
|
||||
// categoryCommands.size() == 1 ? "" : "s",
|
||||
// subCommands,
|
||||
// subCommands == 1 ? "" : "s",
|
||||
// commands.toString()
|
||||
// )).build()).queue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,8 +107,8 @@ public class HelpCommand extends BatCommand implements EventListener {
|
||||
*/
|
||||
private MessageEmbed createHomeEmbed() {
|
||||
StringBuilder categories = new StringBuilder();
|
||||
for (Category category : Category.getCategories()) {
|
||||
long commandCount = commandService.getCommandsByCategory(category, true).size();
|
||||
for (Category category : Category.values()) {
|
||||
long commandCount = commandService.getCommandsByCategory(category).size();
|
||||
categories.append("➜ %s - **%s Command%s**\n".formatted(
|
||||
category.getName(),
|
||||
commandCount,
|
||||
@ -140,9 +138,9 @@ public class HelpCommand extends BatCommand implements EventListener {
|
||||
private LayoutComponent[] createHomeActions() {
|
||||
List<SelectOption> options = new ArrayList<>();
|
||||
options.add(SelectOption.of("Home", "home").withEmoji(Emoji.fromUnicode("U+1F3E0")));
|
||||
options.addAll(Category.getCategories().stream().map(category ->
|
||||
SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji()))
|
||||
.toList());
|
||||
for (Category category : Category.values()) {
|
||||
options.add(SelectOption.of(category.getName(), category.getName()).withEmoji(category.getEmoji()));
|
||||
}
|
||||
|
||||
return new LayoutComponent[]{
|
||||
ActionRow.of(
|
||||
|
@ -15,7 +15,9 @@ import org.springframework.stereotype.Component;
|
||||
public class AvatarCommand extends BatCommand {
|
||||
@Autowired
|
||||
public AvatarCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(GuildSubCommand.class));
|
||||
super.addSubCommand(context.getBean(UserSubCommand.class));
|
||||
super.addSubCommands(
|
||||
context.getBean(GuildSubCommand.class),
|
||||
context.getBean(UserSubCommand.class)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.avatar;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component("avatar:guild.sub")
|
||||
@CommandInfo(name = "guild", description = "View the avatar of the guild")
|
||||
public class GuildSubCommand extends BatSubCommand {
|
||||
public class GuildSubCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
ImageProxy icon = guild.getDiscordGuild().getIcon();
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.avatar;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
@ -12,6 +12,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -19,9 +20,9 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component("avatar:user.sub")
|
||||
@CommandInfo(name = "user", description = "View the avatar of a user", guildOnly = false)
|
||||
public class UserSubCommand extends BatSubCommand {
|
||||
public class UserSubCommand extends BatCommand {
|
||||
public UserSubCommand() {
|
||||
super.addOption(OptionType.USER, "user", "The user to view the avatar of", true);
|
||||
super.addOptions(new OptionData(OptionType.USER, "user", "The user to view the avatar of", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,9 @@ import org.springframework.stereotype.Component;
|
||||
public class BannerCommand extends BatCommand {
|
||||
@Autowired
|
||||
public BannerCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(GuildSubCommand.class));
|
||||
super.addSubCommand(context.getBean(UserSubCommand.class));
|
||||
super.addSubCommands(
|
||||
context.getBean(GuildSubCommand.class),
|
||||
context.getBean(UserSubCommand.class)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.banner;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component("banner:guild.sub")
|
||||
@CommandInfo(name = "guild", description = "View the banner of the guild")
|
||||
public class GuildSubCommand extends BatSubCommand {
|
||||
public class GuildSubCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
ImageProxy banner = guild.getDiscordGuild().getBanner();
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.general.banner;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
@ -12,6 +12,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import net.dv8tion.jda.api.utils.ImageProxy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -20,9 +21,9 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component("banner:user.sub")
|
||||
@CommandInfo(name = "user", description = "View the banner of a user", guildOnly = false)
|
||||
public class UserSubCommand extends BatSubCommand {
|
||||
public class UserSubCommand extends BatCommand {
|
||||
public UserSubCommand() {
|
||||
super.addOption(OptionType.USER, "user", "The user to view the banner of", true);
|
||||
super.addOptions(new OptionData(OptionType.USER, "user", "The user to view the banner of", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,8 +16,10 @@ import org.springframework.stereotype.Component;
|
||||
public class ChannelCommand extends BatCommand {
|
||||
@Autowired
|
||||
public ChannelCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(ViewTopicSubCommand.class));
|
||||
super.addSubCommand(context.getBean(SetTopicSubCommand.class));
|
||||
super.addSubCommand(context.getBean(RemoveTopicSubCommand.class));
|
||||
super.addSubCommands(
|
||||
context.getBean(ViewTopicSubCommand.class),
|
||||
context.getBean(SetTopicSubCommand.class),
|
||||
context.getBean(RemoveTopicSubCommand.class)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.channel;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -20,9 +21,9 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "removetopic", description = "Remove the topic of a channel", requiredPermissions = Permission.MANAGE_CHANNEL)
|
||||
public class RemoveTopicSubCommand extends BatSubCommand {
|
||||
public class RemoveTopicSubCommand extends BatCommand {
|
||||
public RemoveTopicSubCommand() {
|
||||
super.addOption(OptionType.CHANNEL, "channel", "The channel to remove the topic of", false);
|
||||
super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel to remove the topic of", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.channel;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
@ -13,22 +13,27 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
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;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Nick (okNick)
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "settopic", description = "Set the topic of a channel", requiredPermissions = Permission.MANAGE_CHANNEL)
|
||||
public class SetTopicSubCommand extends BatSubCommand {
|
||||
public class SetTopicSubCommand extends BatCommand {
|
||||
public SetTopicSubCommand() {
|
||||
super.addOption(OptionType.STRING, "topic", "The topic to set", true);
|
||||
super.addOption(OptionType.CHANNEL, "channel", "The channel to set the topic of", false);
|
||||
super.addOptions(
|
||||
new OptionData(OptionType.STRING, "topic", "The topic to set", true),
|
||||
new OptionData(OptionType.CHANNEL, "channel", "The channel to set the topic of", false)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
Channel target = event.getOption("channel") == null ? channel : event.getOption("channel").getAsChannel();
|
||||
Channel target = event.getOption("channel") == null ? channel : Objects.requireNonNull(event.getOption("channel")).getAsChannel();
|
||||
if (!(target instanceof TextChannel textChannel)) {
|
||||
event.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("<#%s> is not a text channel!".formatted(target.getId()))
|
||||
@ -37,7 +42,7 @@ public class SetTopicSubCommand extends BatSubCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
String topic = event.getOption("topic").getAsString();
|
||||
String topic = Objects.requireNonNull(event.getOption("topic")).getAsString();
|
||||
if (topic.length() > 1024) {
|
||||
event.replyEmbeds(EmbedUtils.errorEmbed()
|
||||
.setDescription("The topic must be 1024 characters or less!")
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.channel;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.model.BatGuild;
|
||||
@ -12,6 +12,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -19,9 +20,9 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
@CommandInfo(name = "viewtopic", description = "View the topic of a channel")
|
||||
public class ViewTopicSubCommand extends BatSubCommand {
|
||||
public class ViewTopicSubCommand extends BatCommand {
|
||||
public ViewTopicSubCommand() {
|
||||
super.addOption(OptionType.CHANNEL, "channel", "The channel to view the topic of", false);
|
||||
super.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel to view the topic of", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.feature;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
@ -14,6 +14,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -22,10 +23,10 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component("feature:disable.sub")
|
||||
@CommandInfo(name = "disable", description = "Disables a feature")
|
||||
public class DisableSubCommand extends BatSubCommand {
|
||||
public class DisableSubCommand extends BatCommand {
|
||||
@Autowired
|
||||
public DisableSubCommand() {
|
||||
super.addOption(OptionType.STRING, "feature", "The feature to disable", true);
|
||||
super.addOptions(new OptionData(OptionType.STRING, "feature", "The feature to disable", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.feature;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
@ -14,6 +14,7 @@ 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 net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -22,10 +23,10 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component("feature:enable.sub")
|
||||
@CommandInfo(name = "enable", description = "Enables a feature")
|
||||
public class EnableSubCommand extends BatSubCommand {
|
||||
public class EnableSubCommand extends BatCommand {
|
||||
@Autowired
|
||||
public EnableSubCommand() {
|
||||
super.addOption(OptionType.STRING, "feature", "The feature to enable", true);
|
||||
super.addOptions(new OptionData(OptionType.STRING, "feature", "The feature to enable", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,8 +17,10 @@ import org.springframework.stereotype.Component;
|
||||
public class FeatureCommand extends BatCommand {
|
||||
@Autowired
|
||||
public FeatureCommand(@NonNull ApplicationContext context) {
|
||||
super.addSubCommand(context.getBean(EnableSubCommand.class));
|
||||
super.addSubCommand(context.getBean(DisableSubCommand.class));
|
||||
super.addSubCommand(context.getBean(ListSubCommand.class));
|
||||
super.addSubCommands(
|
||||
context.getBean(EnableSubCommand.class),
|
||||
context.getBean(DisableSubCommand.class),
|
||||
context.getBean(ListSubCommand.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.fascinated.bat.features.base.commands.server.feature;
|
||||
|
||||
import cc.fascinated.bat.command.BatSubCommand;
|
||||
import cc.fascinated.bat.command.BatCommand;
|
||||
import cc.fascinated.bat.command.CommandInfo;
|
||||
import cc.fascinated.bat.common.EmbedUtils;
|
||||
import cc.fascinated.bat.features.Feature;
|
||||
@ -19,7 +19,7 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component("feature:list.sub")
|
||||
@CommandInfo(name = "list", description = "Lists the features and their states")
|
||||
public class ListSubCommand extends BatSubCommand {
|
||||
public class ListSubCommand extends BatCommand {
|
||||
@Override
|
||||
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) {
|
||||
StringBuilder featureStates = new StringBuilder();
|
||||
|
Reference in New Issue
Block a user