This commit is contained in:
Lee
2024-12-27 13:48:53 +00:00
parent b3a6284e40
commit 9089767dc5
117 changed files with 1235 additions and 666 deletions

View File

@ -3,7 +3,7 @@ package cc.fascinated.bat.afk;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.afk.command.AfkCommand;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
*/
@Component
public class AfkFeature extends Feature {
public AfkFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public AfkFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("AFK", FeatureProfile.FeatureState.DISABLED, true);
registerCommand(commandService, context.getBean(AfkCommand.class));

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.afk.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.MemberUtils;
import cc.fascinated.bat.afk.profile.AfkProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -3,7 +3,7 @@ package cc.fascinated.bat.autorole;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.autorole.command.AutoRoleCommand;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
@Component
public class AutoRoleFeature extends Feature {
@Autowired
public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("Auto Role", FeatureProfile.FeatureState.DISABLED, true);
registerCommand(commandService, context.getBean(AutoRoleCommand.class));

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.autorole.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.RoleUtils;
import cc.fascinated.bat.autorole.profile.AutoRoleProfile;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.autorole.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import net.dv8tion.jda.api.Permission;
import org.springframework.context.ApplicationContext;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.autorole.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.autorole.profile.AutoRoleProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.autorole.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.autorole.profile.AutoRoleProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.autorole.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.autorole.profile.AutoRoleProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.autorole.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.autorole.profile.AutoRoleProfile;

View File

@ -16,7 +16,7 @@ import cc.fascinated.bat.base.commands.server.channel.ChannelCommand;
import cc.fascinated.bat.base.commands.server.feature.FeatureCommand;
import cc.fascinated.bat.base.commands.utility.PastebinCommand;
import cc.fascinated.bat.base.commands.utility.lookup.LookupCommand;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@ -28,7 +28,7 @@ import org.springframework.stereotype.Component;
@Component
public class BaseFeature extends Feature {
@Autowired
public BaseFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public BaseFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("Base", FeatureProfile.FeatureState.ENABLED, false);
super.registerCommand(commandService, context.getBean(PremiumCommand.class));
@ -38,7 +38,6 @@ public class BaseFeature extends Feature {
super.registerCommand(commandService, context.getBean(VoteCommand.class));
super.registerCommand(commandService, context.getBean(PingCommand.class));
super.registerCommand(commandService, context.getBean(InviteCommand.class));
super.registerCommand(commandService, context.getBean(HelpCommand.class));
super.registerCommand(commandService, context.getBean(BotStatsCommand.class));
super.registerCommand(commandService, context.getBean(BannerCommand.class));
super.registerCommand(commandService, context.getBean(AvatarCommand.class));

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.botadmin;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.base.commands.botadmin.premium.PremiumRemoveSubCommand;
import cc.fascinated.bat.base.commands.botadmin.premium.PremiumSetSubCommand;
import lombok.NonNull;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.botadmin.premium;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import cc.fascinated.bat.premium.PremiumProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.botadmin.premium;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import cc.fascinated.bat.premium.PremiumProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.fun;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import lombok.NonNull;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.fun;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.fun;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.MathUtils;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.fun.image;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.WebRequest;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.fun.image;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.WebRequest;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.fun.image;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.WebRequest;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.fun.image;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.WebRequest;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.fun.image;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.*;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,127 +0,0 @@
package cc.fascinated.bat.base.commands.general;
import cc.fascinated.bat.Consts;
import cc.fascinated.bat.Emojis;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.InteractionBuilder;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author Fascinated (fascinated7)
*/
@Component
@CommandInfo(
name = "help",
description = "View the bots command categories",
userInstall = true,
category = Category.GENERAL
)
public class HelpCommand extends BatCommand implements EventListener {
private final CommandService commandService;
@Autowired
public HelpCommand(@NonNull CommandService commandService) {
this.commandService = commandService;
}
@Override
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, Message commandMessage, String[] arguments, SlashCommandInteraction event) {
InteractionBuilder interactionBuilder = new InteractionBuilder();
interactionBuilder.addUrlButton("Invite Me", Consts.INVITE_URL, null);
interactionBuilder.addUrlButton("Support Server", Consts.SUPPORT_INVITE_URL, null);
interactionBuilder.addStringSelect("Home", "Return Home", Emojis.HOME_EMOJI, (buttonEvent) -> {
buttonEvent.editMessageEmbeds(createHomeEmbed(event.isFromGuild())).queue();
});
for (Category category : Category.getSortedByName()) {
List<BatCommand> categoryCommands = commandService.getCommandsByCategory(category, event.isFromGuild());
if (categoryCommands.isEmpty()) {
continue;
}
interactionBuilder.addStringSelect(
category.getName(),
"View commands in the %s category".formatted(category.getName()),
category.getEmoji(),
(buttonEvent) -> {
DescriptionBuilder description = new DescriptionBuilder(null);
description.appendLine("Commands in the **%s** Category".formatted(category.getName()), false);
description.emptyLine();
for (BatCommand command : categoryCommands) {
if (!command.getSubCommands().isEmpty()) {
for (BatCommand subCommand : command.getSubCommands().values()) {
description.appendLine("`%s %s` - %s".formatted(
command.getInfo().getName(),
subCommand.getInfo().getName(),
subCommand.getInfo().getDescription()
), true);
}
continue;
}
description.appendLine("`%s` - %s".formatted(
command.getInfo().getName(),
command.getInfo().getDescription()
), true);
}
buttonEvent.editMessageEmbeds(EmbedUtils.genericEmbed()
.setDescription(description.build())
.build()).queue();
});
}
event.replyEmbeds(createHomeEmbed(event.isFromGuild())).addComponents(interactionBuilder.build()).queue();
}
/**
* Creates the home embed for the help command
*
* @return The home embed
*/
private MessageEmbed createHomeEmbed(boolean ranInsideGuild) {
StringBuilder categories = new StringBuilder();
for (Category category : Category.values()) {
if (commandService.getCommandsByCategory(category, ranInsideGuild).isEmpty()) {
continue;
}
long commandCount = commandService.getCommandsByCategory(category, ranInsideGuild).size();
categories.append("➜ %s - **%s Command%s**\n".formatted(
category.getName(),
commandCount,
commandCount == 1 ? "" : "s"
));
}
return EmbedUtils.genericEmbed()
.setDescription("""
**Welcome to the Bat Help Menu!**%s
%s
*View our [TOS](%s) and [Privacy Policy](%s) for more information.*
""".formatted(
!ranInsideGuild ? "\n*guild only commands won't be shown here*" : "",
categories.toString(),
Consts.TERMS_OF_SERVICE_URL,
Consts.PRIVACY_POLICY_URL
))
.build();
}
}

View File

@ -1,9 +1,9 @@
package cc.fascinated.bat.base.commands.general;
import cc.fascinated.bat.Consts;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import cc.fascinated.bat.service.DiscordService;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general.avatar;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general.avatar;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general.avatar;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general.banner;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general.banner;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.general.banner;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberFormatter;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.server.channel;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server.channel;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server.channel;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server.channel;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server.feature;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server.feature;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.server.feature;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import net.dv8tion.jda.api.Permission;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.server.feature;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.utility;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.PasteUtils;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.base.commands.utility.lookup;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.base.commands.utility.lookup;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -6,7 +6,7 @@ import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.birthday.command.BirthdayCommand;
import cc.fascinated.bat.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
@ -22,7 +22,7 @@ import org.springframework.stereotype.Component;
public class BirthdayFeature extends Feature implements EventListener {
private final GuildService guildService;
public BirthdayFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
public BirthdayFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService, @NonNull GuildService guildService) {
super("Birthday", FeatureProfile.FeatureState.DISABLED, true);
this.guildService = guildService;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.birthday.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.birthday.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.TextChannelUtils;
import cc.fascinated.bat.birthday.profile.BirthdayProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.birthday.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.birthday.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.birthday.UserBirthday;
import cc.fascinated.bat.birthday.profile.BirthdayProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.birthday.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.birthday.profile.BirthdayProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.birthday.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.birthday.UserBirthday;
import cc.fascinated.bat.birthday.profile.BirthdayProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.birthday.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.birthday.UserBirthday;
import cc.fascinated.bat.birthday.profile.BirthdayProfile;

View File

@ -0,0 +1,44 @@
package cc.fascinated.bat.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
/**
* Emojis used by Rufus.
*
* @author Braydon
*/
@AllArgsConstructor @RequiredArgsConstructor @Getter
public enum BatEmoji {
RUFUS("rufus", "1319317309608689674"),
LOADING("loading", "1319483685787013212", true),
SUCCESS("success", "1319483459781132410"),
CROSS("cross", "1319483437928677446");
/**
* The name of this emoji.
*/
@NonNull private final String name;
/**
* The ID of this emoji.
*/
@NonNull private final String id;
/**
* Whether this emoji is animated.
*/
private boolean animated;
/**
* Get the formatted emoji.
*
* @return the formatted emoji
*/
@Override @NonNull
public String toString() {
return (animated ? "<a:" : "<:") + name + ":" + id + ">";
}
}

View File

@ -0,0 +1,294 @@
package cc.fascinated.bat.common;
import cc.fascinated.bat.Consts;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
import java.awt.*;
/**
* A simple utility class to make
* responding to interactions easier.
*
* @author Braydon
*/
@AllArgsConstructor
public final class InteractionResponder {
/**
* The interaction event to respond to.
*/
@NonNull private final IReplyCallback event;
/**
* Respond to the interaction with a generic embed.
*
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @return the reply action
*/
@NonNull
public RestAction<Message> replyGenericEmbed(@NonNull String content, Object... args) {
return replyGenericEmbed(content, args, (LayoutComponent[]) null);
}
/**
* Respond to the interaction with a generic embed.
*
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @param components the optional components to add to the message
* @return the reply action
*/
@NonNull
public RestAction<Message> replyGenericEmbed(@NonNull String content, Object[] args, LayoutComponent... components) {
return replyGenericEmbed(false, content, args, components);
}
/**
* Respond to the interaction with a generic embed.
*
* @param ephemeral whether the message should be ephemeral
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @return the reply action
*/
@NonNull
public RestAction<Message> replyGenericEmbed(boolean ephemeral, @NonNull String content, Object... args) {
return replyGenericEmbed(ephemeral, content, args, (LayoutComponent[]) null);
}
/**
* Respond to the interaction with a generic embed.
*
* @param ephemeral whether the message should be ephemeral
* @param content the content to respond with
* @param components the optional components to add to the message
* @return the reply action
*/
@NonNull
public RestAction<Message> replyGenericEmbed(boolean ephemeral, @NonNull String content, LayoutComponent... components) {
return replyGenericEmbed(ephemeral, content, null, components);
}
/**
* Respond to the interaction with a generic embed.
*
* @param ephemeral whether the message should be ephemeral
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @param components the optional components to add to the message
* @return the reply action
*/
@NonNull
public RestAction<Message> replyGenericEmbed(boolean ephemeral, @NonNull String content, Object[] args, LayoutComponent... components) {
content = format(content, args);
return reply(ephemeral, buildGenericEmbed(content, args), components);
}
/**
* Build a generic embed.
*
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @return the embed
*/
@NonNull
public MessageEmbed buildGenericEmbed(@NonNull String content, Object... args) {
content = format(content, args);
return new EmbedBuilder()
.setColor(Colors.DEFAULT)
.setDescription(format(content, args))
.build();
}
/**
* Respond to the interaction with a success embed.
*
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @return the reply action
*/
@NonNull
public RestAction<Message> replySuccess(@NonNull String content, Object... args) {
return replySuccess(false, content, args);
}
/**
* Respond to the interaction with a success embed.
*
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @param components the optional components to add to the message
* @return the reply action
*/
@NonNull
public RestAction<Message> replySuccess(@NonNull String content, Object[] args, LayoutComponent... components) {
return replySuccess(false, content, args, components);
}
/**
* Respond to the interaction with a success embed.
*
* @param ephemeral whether the message should be ephemeral
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @return the reply action
*/
@NonNull
public RestAction<Message> replySuccess(boolean ephemeral, @NonNull String content, Object... args) {
return replySuccess(ephemeral, content, args, (LayoutComponent[]) null);
}
/**
* Respond to the interaction with a success embed.
*
* @param ephemeral whether the message should be ephemeral
* @param content the content to respond with
* @param args the optional arguments to format the content with
* @param components the optional components to add to the message
* @return the reply action
*/
@NonNull
public RestAction<Message> replySuccess(boolean ephemeral, @NonNull String content, Object[] args, LayoutComponent... components) {
content = format(content, args);
return reply(ephemeral, new EmbedBuilder()
.setColor(Color.GREEN)
.setDescription(BatEmoji.SUCCESS + " " + content)
.build(), components);
}
/**
* Respond to the interaction with an error embed.
*
* @param error the error to respond with
* @param args the optional arguments to format the error with
* @return the reply action
*/
@NonNull
public RestAction<Message> replyError(@NonNull String error, Object... args) {
return replyError(false, error, args);
}
/**
* Respond to the interaction with an error embed.
*
* @param ephemeral whether the message should be ephemeral
* @param error the error to respond with
* @param args the optional arguments to format the error with
* @return the reply action
*/
@NonNull
public RestAction<Message> replyError(boolean ephemeral, @NonNull String error, Object... args) {
error = format(error, args);
return reply(ephemeral, new EmbedBuilder()
.setColor(Color.RED)
.setDescription(BatEmoji.CROSS + " " + error)
.build());
}
/**
* Respond to the interaction with an embed.
*
* @param embed the embed to respond with
* @return the reply action
*/
@NonNull
public RestAction<Message> reply(@NonNull MessageEmbed embed) {
return reply(false, embed);
}
/**
* Respond to the interaction with an embed.
*
* @param embed the embed to respond with
* @param components the optional components to add to the message
* @return the reply action
*/
@NonNull
public RestAction<Message> reply(@NonNull MessageEmbed embed, LayoutComponent... components) {
return reply(false, embed, components);
}
/**
* Respond to the interaction with an embed.
*
* @param ephemeral whether the message should be ephemeral
* @param embed the embed to respond with
* @return the reply action
*/
@NonNull
public RestAction<Message> reply(boolean ephemeral, @NonNull MessageEmbed embed) {
return reply(ephemeral, embed, (LayoutComponent[]) null);
}
/**
* Respond to the interaction with an embed.
*
* @param ephemeral whether the message should be ephemeral
* @param embed the embed to respond with
* @param components the optional components to add to the message
* @return the reply action
*/
@NonNull
public RestAction<Message> reply(boolean ephemeral, @NonNull MessageEmbed embed, LayoutComponent... components) {
boolean hasComponents = components != null && (components.length > 0);
if (event.isAcknowledged()) {
WebhookMessageCreateAction<Message> action = event.getHook()
.setEphemeral(ephemeral)
.sendMessageEmbeds(embed);
return hasComponents ? action.setComponents(components) : action;
}
ReplyCallbackAction action = event.replyEmbeds(embed).setEphemeral(ephemeral);
return (hasComponents ? action.setComponents(components) : action).flatMap(InteractionHook::retrieveOriginal);
}
/**
* Respond to the interaction with a message.
*
* @param content the message to respond with
* @param args the optional arguments to format the message with
* @return the reply action
*/
@NonNull
public RestAction<Message> reply(@NonNull String content, Object... args) {
return reply(false, content, args);
}
/**
* Respond to the interaction with a message.
*
* @param ephemeral whether the message should be ephemeral
* @param content the message to respond with
* @param args the optional arguments to format the message with
* @return the reply action
*/
@NonNull
public RestAction<Message> reply(boolean ephemeral, @NonNull String content, Object... args) {
content = format(content, args);
if (event.isAcknowledged()) {
return event.getHook().setEphemeral(ephemeral).sendMessage(content);
}
return event.reply(content).setEphemeral(ephemeral).flatMap(InteractionHook::retrieveOriginal);
}
/**
* Format the given content with the given arguments.
*
* @param content the content to format
* @param args the arguments to format with
* @return the formatted content
*/
@NonNull
private String format(@NonNull String content, Object... args) {
return args != null && (args.length > 0) ? content.formatted(args) : content;
}
}

View File

@ -0,0 +1,96 @@
package cc.fascinated.bat.common;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.JDA;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
@UtilityClass
public final class MiscUtils {
/**
* Get the invite url for the bot.
*
* @param jda the JDA instance
* @return the invite url
*/
@NonNull
public static String getInviteUrl(@NonNull JDA jda) {
return "https://discord.com/oauth2/authorize?client_id=" + jda.getSelfUser().getId();
}
/**
* Convert an array of strings to a single string.
*
* @param lines the lines to convert
* @return the string
*/
@NonNull
public static String arrayToString(String... lines) {
return Arrays.stream(lines)
.filter(Objects::nonNull)
.collect(Collectors.joining("\n"));
}
/**
* Capitalize the first letter of
* every word in the given string.
*
* @param input the input to capitalize
* @return the capitalized string
*/
@NonNull
public static String capitalize(@NonNull String input) {
input = input.toLowerCase().replace('_', ' ');
StringBuilder result = new StringBuilder();
boolean capitalizeNext = true;
for (char character : input.toCharArray()) {
if (Character.isSpaceChar(character)) {
capitalizeNext = true;
result.append(character);
} else if (capitalizeNext) {
result.append(Character.toUpperCase(character));
capitalizeNext = false;
} else {
result.append(character);
}
}
return result.toString();
}
/**
* Get the enum constant with the given
* name from the given enum class.
*
* @param enumClass the enum class
* @param enumName the enum name
* @param <T> the enum type
* @return the enum constant, null if not found
*/
public static <T extends Enum<T>> T getEnum(@NonNull Class<T> enumClass, String enumName) {
return getEnum(enumClass, enumName, null);
}
/**
* Get the enum constant with the given
* name from the given enum class.
*
* @param enumClass the enum class
* @param enumName the enum name
* @param defaultValue the default value
* @param <T> the enum type
* @return the enum constant, default value if not found
*/
public static <T extends Enum<T>> T getEnum(@NonNull Class<T> enumClass, String enumName, T defaultValue) {
if (enumName == null) {
return defaultValue;
}
try {
return Enum.valueOf(enumClass, enumName);
} catch (IllegalArgumentException ex) {
return defaultValue;
}
}
}

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.common.feature;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.service.OldCommandService;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@ -35,7 +35,7 @@ public abstract class Feature {
* @param commandService The command service
* @param command The command to register
*/
public void registerCommand(@NonNull CommandService commandService, @NonNull BatCommand command) {
public void registerCommand(@NonNull OldCommandService commandService, @NonNull BatCommand command) {
command.setFeature(this);
for (BatCommand subCommand : command.getSubCommands().values()) {
subCommand.setFeature(this);

View File

@ -1,4 +1,4 @@
package cc.fascinated.bat.common.command;
package cc.fascinated.bat.common.oldcommand;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,4 +1,4 @@
package cc.fascinated.bat.common.command;
package cc.fascinated.bat.common.oldcommand;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package cc.fascinated.bat.common.command;
package cc.fascinated.bat.common.oldcommand;
import net.dv8tion.jda.api.Permission;

View File

@ -1,4 +1,4 @@
package cc.fascinated.bat.common.command;
package cc.fascinated.bat.common.oldcommand;
import lombok.AccessLevel;
import lombok.Getter;

View File

@ -3,7 +3,7 @@ package cc.fascinated.bat.counter;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.counter.command.CounterCommand;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
@Component
public class CounterFeature extends Feature {
@Autowired
public CounterFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public CounterFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("Counter", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(CounterCommand.class));

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.counter.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import net.dv8tion.jda.api.Permission;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,8 +1,8 @@
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.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberFormatter;
import cc.fascinated.bat.counter.CounterChannel;

View File

@ -1,8 +1,8 @@
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.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;

View File

@ -1,8 +1,8 @@
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.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;

View File

@ -1,8 +1,8 @@
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.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.counter.CounterProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -3,7 +3,7 @@ package cc.fascinated.bat.leveling;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.leveling.command.LevelingCommand;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@ -23,7 +23,7 @@ public class LevelingFeature extends Feature {
public static final Map<Integer, Double> xpRequiredCache = new HashMap<>();
@Autowired
public LevelingFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public LevelingFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("Leveling", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(LevelingCommand.class));

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.leveling.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.leveling.LevelingProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.leveling.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberFormatter;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.leveling.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.leveling.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.leveling.LevelingProfile;
import cc.fascinated.bat.leveling.UserLevel;

View File

@ -7,7 +7,7 @@ import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.logging.command.LogsCommand;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.DiscordMessage;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
@ -27,7 +27,7 @@ public class LogFeature extends Feature {
public static LogFeature INSTANCE;
@Autowired
public LogFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public LogFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("Logging", FeatureProfile.FeatureState.DISABLED, true);
INSTANCE = this;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.logging.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.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.InteractionBuilder;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.logging.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import net.dv8tion.jda.api.Permission;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.logging.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.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.logging.LogCategory;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.logging.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.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.logging.LogCategory;

View File

@ -7,7 +7,7 @@ import cc.fascinated.bat.messagesnipe.command.MessageSnipeCommand;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import cc.fascinated.bat.common.model.DiscordMessage;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -31,7 +31,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
private static final long SNIPED_MESSAGE_EXPIRATION = TimeUnit.HOURS.toMillis(1);
@Autowired
public MessageSnipeFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public MessageSnipeFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("Message Snipe", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(MessageSnipeCommand.class));

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.messagesnipe.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.messagesnipe.MessageSnipeFeature;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.messagesnipe.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.PasteUtils;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.messagesnipe.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

View File

@ -8,7 +8,7 @@ import cc.fascinated.bat.moderation.punish.Punishment;
import cc.fascinated.bat.moderation.punish.PunishmentProfile;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import cc.fascinated.bat.service.UserService;
@ -37,7 +37,7 @@ public class ModerationFeature extends Feature implements EventListener {
private final UserService userService;
@Autowired
public ModerationFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService,
public ModerationFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService, @NonNull GuildService guildService,
@NonNull UserService userService) {
super("Moderation", FeatureProfile.FeatureState.DISABLED, true);
this.guildService = guildService;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.TimeUtils;
import cc.fascinated.bat.moderation.punish.PunishmentProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.moderation.punish.PunishmentProfile;
import cc.fascinated.bat.moderation.punish.PunishmentType;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.TimeUtils;
import cc.fascinated.bat.moderation.punish.PunishmentProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.moderation.punish.Punishment;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberFormatter;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.moderation.punish.Punishment;
import cc.fascinated.bat.moderation.punish.PunishmentProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.moderation.punish.Punishment;
import cc.fascinated.bat.moderation.punish.PunishmentProfile;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.moderation.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.moderation.punish.PunishmentProfile;
import cc.fascinated.bat.moderation.punish.PunishmentType;

View File

@ -3,7 +3,7 @@ package cc.fascinated.bat.namehistory;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.namehistory.command.NameHistoryCommand;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@ -17,7 +17,7 @@ public class NameHistoryFeature extends Feature {
public static final int NAME_HISTORY_SIZE = 25;
@Autowired
public NameHistoryFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public NameHistoryFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService) {
super("Name History", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(NameHistoryCommand.class));

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.namehistory.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.namehistory.TrackedName;
import cc.fascinated.bat.namehistory.profile.guild.NameHistoryProfile;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.namehistory.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.namehistory.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.namehistory.TrackedName;
import cc.fascinated.bat.namehistory.profile.user.NameHistoryProfile;

View File

@ -4,7 +4,7 @@ import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.reminder.command.ReminderCommand;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.OldCommandService;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
@ -36,7 +36,7 @@ public class ReminderFeature extends Feature {
private final GuildService guildService;
@Autowired
public ReminderFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
public ReminderFeature(@NonNull ApplicationContext context, @NonNull OldCommandService commandService, @NonNull GuildService guildService) {
super("Reminder", FeatureProfile.FeatureState.DISABLED, true);
this.guildService = guildService;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.reminder.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.reminder.ReminderProfile;
import cc.fascinated.bat.common.model.BatGuild;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.reminder.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.DescriptionBuilder;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.reminder.Reminder;

View File

@ -1,8 +1,8 @@
package cc.fascinated.bat.reminder.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.Category;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@ -1,7 +1,7 @@
package cc.fascinated.bat.reminder.command;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.CommandInfo;
import cc.fascinated.bat.common.oldcommand.BatCommand;
import cc.fascinated.bat.common.oldcommand.CommandInfo;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.TimeUtils;
import cc.fascinated.bat.reminder.Reminder;

View File

@ -1,322 +1,293 @@
package cc.fascinated.bat.service;
import cc.fascinated.bat.Consts;
import cc.fascinated.bat.common.command.BatCommand;
import cc.fascinated.bat.common.command.Category;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.config.Config;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.command.CommandCategory;
import cc.fascinated.bat.command.IBatCommand;
import cc.fascinated.bat.command.annotation.BotOwner;
import cc.fascinated.bat.command.annotation.Thinking;
import cc.fascinated.bat.command.command.HelpCommand;
import cc.fascinated.bat.common.InteractionResponder;
import cc.fascinated.bat.common.model.BatGuild;
import cc.fascinated.bat.common.model.BatUser;
import io.sentry.Hint;
import io.sentry.Sentry;
import jakarta.annotation.Nonnull;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.boot.info.BuildProperties;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author Fascinated (fascinated7)
* @author Braydon
*/
@Service
@Log4j2(topic = "Command Service")
@Getter
@DependsOn("discordService")
public class CommandService extends ListenerAdapter {
public static CommandService INSTANCE;
@Service @Log4j2(topic = "Commands")
public final class CommandService extends ListenerAdapter {
/**
* The guild service to get and create guilds.
*/
public final GuildService guildService;
/**
* The registered commands
* The build properties for this app, null if not available.
*/
private final Map<String, BatCommand> commands = new HashMap<>();
private final BuildProperties buildProperties;
/**
* The guild service to use
* The currently registered commands.
*/
private final GuildService guildService;
/**
* The user service to use
*/
private final UserService userService;
@Getter private final List<BatCommand> registry = Collections.synchronizedList(new ArrayList<>());
@Autowired
public CommandService(@NonNull GuildService guildService, @NonNull UserService userService) {
INSTANCE = this;
public CommandService(@NonNull GuildService guildService, BuildProperties buildProperties) {
this.guildService = guildService;
this.userService = userService;
this.buildProperties = buildProperties;
DiscordService.JDA.addEventListener(this);
}
/**
* Registers a command
*
* @param command The command to register
*/
public void registerCommand(@NonNull BatCommand command) {
String commandName = command.getInfo().getName().toLowerCase();
if (commands.get(commandName) != null) {
return;
}
log.info("Registered command \"{}\"", command.getInfo().getName());
commands.put(commandName, command);
}
@PostConstruct
public void onInitialize() {
// Command Registry
registerCommand(new HelpCommand(this, buildProperties));
log.info("Registered {} commands", registry.size());
/**
* Registers all slash commands
*/
public void registerSlashCommands() {
log.info("Registering all slash commands");
JDA jda = DiscordService.JDA;
long before = System.currentTimeMillis();
// Send the commands to the guilds
log.info("Sending {} commands to guilds...", registry.size());
List<SlashCommandData> commandData = registry.stream()
.map(BatCommand::getCommandData)
.toList();
Guild adminGuild = jda.getGuildById(Config.INSTANCE.getAdminGuild());
if (!Config.isProduction()) {
if (adminGuild == null) {
log.error("Unable to find the admin guild to register commands");
return;
}
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).complete());
List<Command> registeredCommands = adminGuild.updateCommands().addCommands(commands.values().stream().map(BatCommand::getCommandData).toList()).complete();
log.info("Registered {} slash commands in {}ms (DEV MODE)", registeredCommands.size(), System.currentTimeMillis() - before);
return;
}
// the amount of indents here should be illegal
for (Guild guild : DiscordService.JDA.getGuilds()) {
log.info("Queueing {} commands for guild {}", commandData.size(), guild.getName());
guild.updateCommands().addCommands(commandData).queue(registry -> {
// Once sent to Discord, set the snowflake of the commands in our registry
for (Command registeredCommand : registry) {
BatCommand rufusCommand = Objects.requireNonNull(getCommand(registeredCommand.getName()));
rufusCommand.setSnowflake(registeredCommand.getIdLong());
log.info("Retrieved snowflake {} for command /{}", rufusCommand.getSnowflake(), rufusCommand.getName());
// Unregister all commands that Discord has but we don't
jda.retrieveCommands().complete().forEach(command -> {
if (commands.containsKey(command.getName()) && commands.get(command.getName()).getInfo().isBotOwnerOnly()) {
jda.deleteCommandById(command.getId()).complete(); // Unregister the command on Discord
log.info("Unregistered hidden command \"{}\" from Discord", command.getName());
return;
}
if (commands.containsKey(command.getName())) {
return;
}
// Register the sub-command groups
for (Command.SubcommandGroup subCommandGroup : registeredCommand.getSubcommandGroups()) {
for (Command.Subcommand subCommand : subCommandGroup.getSubcommands()) {
String fullName = rufusCommand.getName() + " " + subCommandGroup.getName() + " " + subCommand.getName();
BatSubCommand rufusSubCommand = Objects.requireNonNull(rufusCommand.getSubCommand(subCommandGroup.getName(), subCommand.getName()));
rufusSubCommand.setSnowflake(subCommand.getIdLong());
rufusSubCommand.setFullName(fullName);
log.info("Retrieved snowflake {} for sub-command-group /{}", subCommand.getIdLong(), fullName);
}
}
jda.deleteCommandById(command.getId()).complete(); // Unregister the command on Discord
log.info("Unregistered unknown command \"{}\" from Discord", command.getName());
});
// Register all commands
List<Command> discordCommands = jda.updateCommands().addCommands(commands.values().stream().filter(command -> !command.getInfo().isBotOwnerOnly())
.map(BatCommand::getCommandData).toList()).complete();
for (Command discordCommand : discordCommands) {
commands.get(discordCommand.getName()).setSnowflake(discordCommand.getIdLong());
if (!discordCommand.getSubcommands().isEmpty()) {
for (Command.Subcommand subCommand : discordCommand.getSubcommands()) {
commands.get(discordCommand.getName()).getSubCommands().get(subCommand.getName()).setSnowflake(subCommand.getIdLong());
// Register the sub-commands
for (Command.Subcommand subCommand : registeredCommand.getSubcommands()) {
String fullName = rufusCommand.getName() + " " + subCommand.getName();
BatSubCommand rufusSubCommand = Objects.requireNonNull(rufusCommand.getSubCommand(null, subCommand.getName()));
rufusSubCommand.setSnowflake(subCommand.getIdLong());
rufusSubCommand.setFullName(fullName);
log.info("Retrieved snowflake {} for sub-command /{}", subCommand.getIdLong(), fullName);
}
}
}
});
}
if (adminGuild != null) {
adminGuild.updateCommands().addCommands(commands.values().stream().filter(command -> command.getInfo().isBotOwnerOnly())
.map(BatCommand::getCommandData).toList()).complete();
} else {
log.error("Unable to find the admin guild to register hidden commands");
}
log.info("Registered {} slash commands in {}ms", discordCommands.size(), System.currentTimeMillis() - before);
}
/**
* Gets commands that are in a specific category
*
* @param category The category
* @param includeGuildCommands If guild commands should be included
* @return The commands
*/
public List<BatCommand> getCommandsByCategory(Category category, boolean includeGuildCommands) {
List<BatCommand> commands = new ArrayList<>();
for (BatCommand command : this.commands.values()) {
if (command.getInfo().getCategory() == category
&& (includeGuildCommands || command.getInfo().isUserInstall())
&& !command.getInfo().isBotOwnerOnly()) {
commands.add(command);
}
}
return commands;
}
/**
* Gets a command by its class
*
* @param clazz The class of the command
* @return The command
*/
public BatCommand getCommand(Class<? extends BatCommand> clazz) {
for (Map.Entry<String, BatCommand> entry : this.commands.entrySet()) {
if (entry.getValue().getClass().equals(clazz)) {
return entry.getValue();
}
}
return null;
log.info("Done, commands have been sent to {} guilds", DiscordService.JDA.getGuilds().size());
}
@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
if (event.getUser().isBot()) {
return;
}
long before = System.currentTimeMillis();
BatCommand command = commands.get(event.getName());
if (command == null) {
return;
}
String subcommandName = event.getSubcommandName();
if (subcommandName != null) { // Use the sub command if given
command = command.getSubCommands().get(subcommandName);
}
BatUser user = userService.getUser(event.getUser().getId());
BatGuild guild = event.getGuild() == null ? null : guildService.getGuild(event.getGuild().getId());
Member member = event.getMember();
Guild discordGuild = event.getGuild();
assert member != null && discordGuild != null;
BatGuild guild = guildService.getGuild(discordGuild.getId());
String executeChecks = runPreExecuteChecks(command, user, guild, event.getMember());
if (executeChecks != null) {
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription(executeChecks)
.build()).setEphemeral(true).queue();
return;
}
// Execute the command
try {
MessageChannelUnion channel = event.getChannel();
command.execute(guild, user, channel, event.getMember(), null, null, event.getInteraction());
log.info("Executed slash command \"{}\" for user \"{}\" in channel \"{}\" (took: {}ms)",
command.getInfo().getName(),
user.getName(),
channel.getName(),
System.currentTimeMillis() - before
);
} catch (Exception ex) {
log.error("An error occurred while executing command \"{}\"", command.getInfo().getName(), ex);
event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue();
Hint hint = new Hint();
hint.set("command", command.getInfo().getName());
hint.set("user", user.getId());
if (guild != null) {
hint.set("guild", guild.getId());
// Execute the command if registered
for (BatCommand parent : registry) {
if (!parent.getName().equals(event.getName())) {
continue;
}
Sentry.captureException(ex, hint); // Capture the exception
// Log the executed command
logUsage(discordGuild, guild, member, parent, event.getSubcommandGroup(), event.getSubcommandName(), event);
// If @Thinking is present, tell discord we received the command, send a thinking... message to the user
if (parent.getClass().isAnnotationPresent(Thinking.class)) {
event.deferReply().queue();
}
InteractionResponder responder = new InteractionResponder(event);
IBatCommand executor = getExecutor(parent, event);
// Initial checks before running the command
if (executor.getClass().isAnnotationPresent(BotOwner.class) && !member.getId().equals(Consts.BOT_OWNER)) {
responder.replyError("This command is restricted to the bot owner.").queue();
return;
}
// Execute the command
executor.execute(guild, discordGuild, member, responder, event);
break;
}
}
@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
if (event.getAuthor().isBot() || !event.isFromGuild()) { // This message wasn't sent in a guild
return;
}
BatUser user = userService.getUser(event.getAuthor().getId());
if (user == null) {
return;
}
BatGuild guild = guildService.getGuild(event.getGuild().getId());
String message = event.getMessage().getContentRaw();
if (!message.startsWith(guild.getPrefix())) { // Check if the message starts with the guild prefix
return;
}
public void onCommandAutoCompleteInteraction(@NotNull CommandAutoCompleteInteractionEvent event) {
Member member = event.getMember();
Guild discordGuild = event.getGuild();
assert member != null && discordGuild != null;
BatGuild guild = guildService.getGuild(discordGuild.getId());
String[] parts = message.substring(guild.getPrefix().length()).split("\\s+");
String commandName = parts[0].toLowerCase();
String[] args = parts.length > 1 ? new String[parts.length - 1] : new String[0];
if (args.length > 0) {
System.arraycopy(parts, 1, args, 0, args.length);
}
BatCommand command = commands.get(commandName);
if (command == null) {
// Auto complete the command if registered
IBatCommand executor = getExecutor(event);
if (executor == null) {
return;
}
if (!command.getInfo().isPrefixAllowed()) { // Check if the command is allowed to be ran with a prefix
List<Command.Choice> choices = executor.autoComplete(guild, discordGuild, member, event);
if (choices.isEmpty()) {
return;
}
String executeChecks = runPreExecuteChecks(command, user, guild, event.getMember());
if (executeChecks != null) {
event.getChannel().sendMessageEmbeds(EmbedUtils.errorEmbed()
.setDescription(executeChecks)
.build()).queue();
return;
}
// Execute the command
try {
command.execute(guild, user, event.getChannel(), event.getMember(), event.getMessage(), args, null);
log.info("Executed prefixed command \"{}{}\" for user \"{}\" in channel \"{}\"",
command.getInfo().getName(),
args.length > 0 ? " " + String.join(" ", args) : "",
user.getName(),
event.getChannel().getName()
);
} catch (Exception ex) {
log.error("An error occurred while executing command \"{}\"", command.getInfo().getName(), ex);
event.getChannel().sendMessageEmbeds(EmbedUtils.genericInteractionError(ex).build()).queue();
Hint hint = new Hint();
hint.set("command", command.getInfo().getName());
hint.set("user", user.getId());
hint.set("guild", guild.getId());
Sentry.captureException(ex, hint); // Capture the exception
}
event.replyChoices(choices.stream()
.filter(choice -> choice.getName().startsWith(event.getFocusedOption().getValue()))
.collect(Collectors.toList())).queue();
}
/**
* Runs pre execute checks for a command
* Register a command.
*
* @param command The command
* @param user The user
* @param guild The guild
* @param member The member
* @return The error message if any
* @param command the command
*/
public String runPreExecuteChecks(BatCommand command, BatUser user, BatGuild guild, Member member) {
// Only the bot owner can run this command
if (command.getInfo().isBotOwnerOnly() && !user.getId().equalsIgnoreCase(Consts.BOT_OWNER)) {
return "You do not have permission to execute this command";
}
private void registerCommand(@NonNull BatCommand command) {
registry.add(command);
log.info("Registered command: /{}", command.getCommandData().getName());
}
// Check if the command is guild only and if it was not ran inside a guild
if (command.getInfo().isGuildOnly() && guild == null) {
return "This command can only be executed in a guild";
}
/**
* Get the commands in a category
* the given member has access to.
*
* @param member the member to get the commands for
* @param category the category to get the commands for
* @return the commands the member has
*/
@NonNull
public List<IBatCommand> getCommands(@Nonnull Member member, @NonNull CommandCategory category) {
// Collect all the commands in this category
List<IBatCommand> categoryCommands = registry.stream()
.filter(command -> {
// Not the right category
if (command.getCategory() != category) {
return false;
}
// Return the commands the user has access to
Long rawPermissions = command.getCommandData().getDefaultPermissions().getPermissionsRaw();
return rawPermissions == null || (member.getPermissions().containsAll(Permission.getPermissions(rawPermissions)));
})
.collect(Collectors.toList());
// Check if the feature is disabled in the guild
if (guild != null) {
FeatureProfile featureProfile = guild.getFeatureProfile();
if (featureProfile.isFeatureDisabled(command.getFeature())) {
return "The feature `%s` is disabled in this guild".formatted(command.getFeature().getName());
}
}
// Add all the sub-commands from the parents
List<IBatCommand> subCommands = categoryCommands.stream()
.flatMap(parent -> ((BatCommand) parent).getSubCommands().stream())
.collect(Collectors.toList());
categoryCommands.addAll(subCommands);
// Check if the user has the required permissions
if (guild != null && member != null) {
List<Permission> missingPermissions = new ArrayList<>();
for (Permission permission : command.getInfo().getPermissions()) {
if (!member.hasPermission(permission)) {
missingPermissions.add(permission);
}
}
if (!missingPermissions.isEmpty()) {
return "You are missing the following permissions to execute this command:\n" +
missingPermissions.stream().map(perm -> "`" + perm.name() + "`").collect(Collectors.joining(", "));
// Finally, remove any parents that have sub-commands as they can't be executed directly
categoryCommands.removeIf(command -> command instanceof BatCommand parentCommand && (!parentCommand.getSubCommands().isEmpty()));
return categoryCommands;
}
/**
* Get a command by name.
*
* @param name the command name
* @return the command, null if none
*/
public BatCommand getCommand(@NonNull String name) {
for (BatCommand command : registry) {
if (command.getName().equalsIgnoreCase(name)) {
return command;
}
}
return null;
}
/**
* Log the usage of a command.
*
* @param discordGuild the Discord guild the command was executed in
* @param guild the ticket guild the command was executed in
* @param member the member that executed the command
* @param parent the parent command
* @param subCommandGroup the sub-command group, if any
* @param subCommandName the sub-command name, if any
* @param event the event that triggered the command
*/
private void logUsage(@NonNull Guild discordGuild, @NonNull BatGuild guild, @NonNull Member member, @NonNull BatCommand parent,
String subCommandGroup, String subCommandName, @NonNull SlashCommandInteractionEvent event) {
StringBuilder fullCommandName = new StringBuilder(parent.getName());
if (subCommandGroup != null) {
fullCommandName.append(" ").append(subCommandGroup);
}
if (subCommandName != null) {
fullCommandName.append(" ").append(subCommandName);
}
for (OptionMapping option : event.getOptions()) {
fullCommandName.append(" ").append(option.getName()).append(":").append(option.getAsString());
}
log.info("User {} (UID: {}) executed '/{}' in guild {} (GID: {})",
member.getUser().getName(), member.getId(), fullCommandName.toString(), discordGuild.getName(), guild.getId()
);
}
/**
* Get the command executor for the given event.
*
* @param event the event
* @return the command executor, null if none
*/
private IBatCommand getExecutor(@NonNull CommandInteractionPayload event) {
for (BatCommand parent : registry) {
if (!parent.getName().equals(event.getName())) {
continue;
}
return getExecutor(parent, event);
}
return null;
}
/**
* Get the command executor for the given command.
*
* @param parent the parent command
* @param event the event
* @return the command executor
*/
@Nonnull
private IBatCommand getExecutor(BatCommand parent, @NonNull CommandInteractionPayload event) {
String subCommandGroup = event.getSubcommandGroup();
String subCommandName = event.getSubcommandName();
IBatCommand executor = null;
// Get the command executor
if (subCommandName != null) { // Try to find the sub-command to execute
executor = parent.getSubCommand(subCommandGroup, subCommandName);
}
if (executor == null) { // Fallback to the parent
executor = parent;
}
return executor;
}
}

Some files were not shown because too many files have changed in this diff Show More