cleanup commands
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 46s

This commit is contained in:
Lee 2024-06-25 15:43:36 +01:00
parent 519cb72c14
commit e0fca911d9
24 changed files with 182 additions and 109 deletions

View File

@ -85,6 +85,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- Libraries -->
<dependency>

View File

@ -7,12 +7,14 @@ import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
@EnableCaching
@SpringBootApplication()
@Log4j2(topic = "Ember")
public class BatApplication {

View File

@ -3,7 +3,6 @@ package cc.fascinated.bat.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Transient;
/**
* @author Fascinated (fascinated7)

View File

@ -0,0 +1,23 @@
package cc.fascinated.bat.features;
import cc.fascinated.bat.service.CommandService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@RequiredArgsConstructor
@Getter
@Component
public abstract class Feature {
@Autowired
private CommandService commandService;
/**
* The name of the feature
*/
private final String name;
}

View File

@ -0,0 +1,20 @@
package cc.fascinated.bat.features.autorole;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.autorole.command.AutoRoleCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
/**
* @author Fascinated (fascinated7)
*/
public class AutoRoleFeature extends Feature {
@Autowired
public AutoRoleFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("AutoRole");
commandService.registerCommand(context.getBean(AutoRoleCommand.class));
}
}

View File

@ -18,7 +18,6 @@ import java.util.List;
*/
@Component @Log4j2
public class AutoRoleListener implements EventListener {
@Override
public void onGuildMemberJoin(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull GuildMemberJoinEvent event) {
AutoRoleProfile profile = guild.getProfile(AutoRoleProfile.class);

View File

@ -1,6 +1,9 @@
package cc.fascinated.bat.features.scoresaber;
import cc.fascinated.bat.common.*;
import cc.fascinated.bat.common.DateUtils;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberUtils;
import cc.fascinated.bat.common.ScoreSaberUtils;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.scoresaber.profile.GuildNumberOneScoreFeedProfile;
import cc.fascinated.bat.model.BatGuild;
@ -38,6 +41,11 @@ public class NumberOneScoreFeedListener implements EventListener {
if (!leaderboard.isRanked()) { // Only send if the leaderboard is ranked
return;
}
log.info("A new #1 score has been set by {} on {} ({})!",
player.getName(),
leaderboard.getSongName(),
"%s⭐".formatted(NumberUtils.formatNumberCommas(leaderboard.getStars()))
);
for (Guild guild : DiscordService.JDA.getGuilds()) {
BatGuild batGuild = guildService.getGuild(guild.getId());

View File

@ -0,0 +1,27 @@
package cc.fascinated.bat.features.scoresaber;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.scoresaber.command.numberone.NumberOneFeedCommand;
import cc.fascinated.bat.features.scoresaber.command.scoresaber.ScoreSaberCommand;
import cc.fascinated.bat.features.scoresaber.command.userfeed.UserFeedCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component
public class ScoreSaberFeature extends Feature {
@Autowired
public ScoreSaberFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("ScoreSaber");
commandService.registerCommand(context.getBean(ScoreSaberCommand.class));
commandService.registerCommand(context.getBean(UserFeedCommand.class));
commandService.registerCommand(context.getBean(NumberOneFeedCommand.class));
}
}

View File

@ -1,12 +1,15 @@
package cc.fascinated.bat.features.scoresaber;
import cc.fascinated.bat.common.*;
import cc.fascinated.bat.common.DateUtils;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberUtils;
import cc.fascinated.bat.common.ScoreSaberUtils;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.scoresaber.profile.GuildUserScoreFeedProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberLeaderboardToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberPlayerScoreToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberScoreToken;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import lombok.extern.log4j.Log4j2;

View File

@ -36,12 +36,12 @@ public class ChannelSubCommand extends BatSubCommand {
if (option == null) {
if (!TextChannelUtils.isValidChannel(profile.getChannelId())) {
interaction.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("Please provide a channel to set the ScoreSaber #1 feed channel to")
.setDescription("Please provide a channel to set the feed channel to")
.build()).queue();
return;
}
interaction.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("The current ScoreSaber #1 feed channel is %s".formatted(TextChannelUtils.getChannelMention(profile.getChannelId())))
.setDescription("The current feed channel is %s".formatted(TextChannelUtils.getChannelMention(profile.getChannelId())))
.build()).queue();
return;
}
@ -57,8 +57,8 @@ public class ChannelSubCommand extends BatSubCommand {
profile.setChannelId(targetChannel.getId());
guildService.saveGuild(guild);
interaction.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("Successfully set the ScoreSaber #1 feed channel to %s".formatted(targetChannel.asTextChannel().getAsMention()))
interaction.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Successfully set the feed channel to %s".formatted(targetChannel.asTextChannel().getAsMention()))
.build()).queue();
}
}

View File

@ -21,15 +21,15 @@ public class NumberOneFeedCommand extends BatCommand {
super.setCategory(Category.BEAT_SABER);
super.addSubCommand("channel", context.getBean(ChannelSubCommand.class));
super.addSubCommand("clear-channel", context.getBean(ClearChannelSubCommand.class));
super.addSubCommand("reset", context.getBean(ResetSubCommand.class));
super.setDescription("ScoreSaber #1 score feed commands");
super.setDescription("Modifies the settings for the feed.");
super.setCommandData(new CommandDataImpl(this.getName(), this.getDescription())
.setGuildOnly(true)
.addSubcommands(new SubcommandData("channel", "Edit the channel the score feed is sent in")
.addOptions(new OptionData(OptionType.CHANNEL, "channel", "Set the channel to send the score feed in", false))
.addSubcommands(new SubcommandData("channel", "Change the channel the score feed is sent in")
.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel scores are sent in", false))
).setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER))
.addSubcommands(new SubcommandData("clear-channel", "Disable the score feed"))
.addSubcommands(new SubcommandData("reset", "Resets the feed settings to default"))
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER))
);
}

View File

@ -16,12 +16,12 @@ import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("scoresaber-number-one-feed:clear-channel.sub")
public class ClearChannelSubCommand extends BatSubCommand {
@Component("scoresaber-number-one-feed:reset.sub")
public class ResetSubCommand extends BatSubCommand {
private final GuildService guildService;
@Autowired
public ClearChannelSubCommand(GuildService guildService) {
public ResetSubCommand(GuildService guildService) {
this.guildService = guildService;
}
@ -31,8 +31,8 @@ public class ClearChannelSubCommand extends BatSubCommand {
profile.setChannelId(null);
guildService.saveGuild(guild);
interaction.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("Successfully cleared the ScoreSaber #1 feed channel")
interaction.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Successfully reset the settings.")
.build()).queue();
}
}

View File

@ -2,10 +2,10 @@ package cc.fascinated.bat.features.scoresaber.command.scoresaber;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.service.ScoreSaberService;
import cc.fascinated.bat.service.UserService;
import lombok.NonNull;

View File

@ -5,10 +5,10 @@ import cc.fascinated.bat.common.Colors;
import cc.fascinated.bat.common.DateUtils;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberUtils;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.service.ScoreSaberService;
import lombok.NonNull;
import net.dv8tion.jda.api.EmbedBuilder;

View File

@ -3,8 +3,8 @@ package cc.fascinated.bat.features.scoresaber.command.userfeed;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.TextChannelUtils;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.features.scoresaber.profile.GuildUserScoreFeedProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("scoresaber-userfeed:channel.sub")
@Component("scoresaber-user-feed:channel.sub")
public class ChannelSubCommand extends BatSubCommand {
private final GuildService guildService;

View File

@ -1,38 +0,0 @@
package cc.fascinated.bat.features.scoresaber.command.userfeed;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.features.scoresaber.profile.GuildUserScoreFeedProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("scoresaber-userfeed:clear-channel.sub")
public class ClearChannelSubCommand extends BatSubCommand {
private final GuildService guildService;
@Autowired
public ClearChannelSubCommand(GuildService guildService) {
this.guildService = guildService;
}
@Override
public void execute(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull TextChannel channel, @NonNull Member member, @NonNull SlashCommandInteraction interaction) {
GuildUserScoreFeedProfile profile = guild.getProfile(GuildUserScoreFeedProfile.class);
profile.setChannelId(null);
guildService.saveGuild(guild);
interaction.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("Successfully cleared the ScoreSaber feed channel")
.build()).queue();
}
}

View File

@ -2,8 +2,8 @@ package cc.fascinated.bat.features.scoresaber.command.userfeed;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.features.scoresaber.profile.GuildUserScoreFeedProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
@ -16,23 +16,24 @@ import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("scoresaber-userfeed:clearusers.sub")
public class ClearUsersSubCommand extends BatSubCommand {
@Component("scoresaber-user-feed:reset.sub")
public class ResetSubCommand extends BatSubCommand {
private final GuildService guildService;
@Autowired
public ClearUsersSubCommand(GuildService guildService) {
public ResetSubCommand(GuildService guildService) {
this.guildService = guildService;
}
@Override
public void execute(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull TextChannel channel, @NonNull Member member, @NonNull SlashCommandInteraction interaction) {
GuildUserScoreFeedProfile profile = guild.getProfile(GuildUserScoreFeedProfile.class);
profile.setChannelId(null);
profile.getTrackedUsers().clear();
guildService.saveGuild(guild);
interaction.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Successfully cleared all users from the ScoreSaber feed")
.setDescription("Successfully reset the settings.")
.build()).queue();
}
}

View File

@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("scoresaber-userfeed.command")
@Component("scoresaber-user-feed.command")
public class UserFeedCommand extends BatCommand {
public UserFeedCommand(@NonNull ApplicationContext context) {
super("scoresaber-user-feed");
@ -22,24 +22,20 @@ public class UserFeedCommand extends BatCommand {
super.addSubCommand("user", context.getBean(UserSubCommand.class));
super.addSubCommand("channel", context.getBean(ChannelSubCommand.class));
super.addSubCommand("clear-channel", context.getBean(ClearChannelSubCommand.class));
super.addSubCommand("clear-users", context.getBean(ClearUsersSubCommand.class));
super.addSubCommand("reset", context.getBean(ResetSubCommand.class));
super.setDescription("ScoreSaber user score feed commands");
super.setDescription("Modifies the settings for the feed.");
super.setCommandData(new CommandDataImpl(this.getName(), this.getDescription())
.setGuildOnly(true)
.addSubcommands(new SubcommandData("user", "Edit the users in the score feed")
.addOptions(new OptionData(OptionType.USER, "user", "Add or remove a user from the score feed", false))
).setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER))
.addSubcommands(new SubcommandData("clear-users", "Remove all users from the score feed"))
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER))
.addSubcommands(new SubcommandData("channel", "Edit the channel the score feed is sent in")
.addOptions(new OptionData(OptionType.CHANNEL, "channel", "Set the channel to send the score feed in", false))
.addSubcommands(new SubcommandData("channel", "Change the channel the score feed is sent in")
.addOptions(new OptionData(OptionType.CHANNEL, "channel", "The channel scores are sent in", false))
).setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER))
.addSubcommands(new SubcommandData("clear-channel", "Disable the score feed"))
.addSubcommands(new SubcommandData("reset", "Resets the feed settings to default"))
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_SERVER))
);
}

View File

@ -2,10 +2,10 @@ package cc.fascinated.bat.features.scoresaber.command.userfeed;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.features.scoresaber.profile.GuildUserScoreFeedProfile;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.features.scoresaber.profile.UserScoreSaberProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.GuildService;
import cc.fascinated.bat.service.UserService;
import lombok.NonNull;
@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component("scoresaber-userfeed:user.sub")
@Component("scoresaber-user-feed:user.sub")
public class UserSubCommand extends BatSubCommand {
private final GuildService guildService;
private final UserService userService;
@ -38,7 +38,7 @@ public class UserSubCommand extends BatSubCommand {
if (option == null){
if (profile.getTrackedUsers().isEmpty()) {
interaction.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("There are no users being tracked in the ScoreSaber feed")
.setDescription("There are no users being tracked in the feed")
.build()).queue();
return;
}
@ -50,7 +50,7 @@ public class UserSubCommand extends BatSubCommand {
));
}
interaction.replyEmbeds(EmbedUtils.genericEmbed()
.setDescription("The current users being tracked in the ScoreSaber feed are:\n%s".formatted(stringBuilder.toString()))
.setDescription("The current users being tracked in the feed are:\n%s".formatted(stringBuilder.toString()))
.build()).queue();
return;
}
@ -68,12 +68,12 @@ public class UserSubCommand extends BatSubCommand {
if (profile.getTrackedUsers().contains(targetProfile.getSteamId())) {
profile.getTrackedUsers().remove(targetProfile.getSteamId());
interaction.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Successfully removed %s from the ScoreSaber feed".formatted(target.getAsMention()))
.setDescription("Successfully removed %s from the feed".formatted(target.getAsMention()))
.build()).queue();
} else {
profile.getTrackedUsers().add(targetProfile.getSteamId());
interaction.replyEmbeds(EmbedUtils.successEmbed()
.setDescription("Successfully added %s to the ScoreSaber feed".formatted(target.getAsMention()))
.setDescription("Successfully added %s to the feed".formatted(target.getAsMention()))
.build()).queue();
}
guildService.saveGuild(guild);

View File

@ -1,6 +1,5 @@
package cc.fascinated.bat.model;
import cc.fascinated.bat.common.Profile;
import cc.fascinated.bat.common.ProfileHolder;
import cc.fascinated.bat.service.DiscordService;
import lombok.Getter;
@ -11,8 +10,7 @@ import net.dv8tion.jda.api.entities.Guild;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
/**
* @author Fascinated (fascinated7)
@ -27,6 +25,11 @@ public class BatGuild extends ProfileHolder {
*/
@NonNull @Id private final String id;
/**
* The time this guild was joined
*/
private Date createdAt = new Date();
/**
* Gets the guild as the JDA Guild
*

View File

@ -1,6 +1,5 @@
package cc.fascinated.bat.model;
import cc.fascinated.bat.common.Profile;
import cc.fascinated.bat.common.ProfileHolder;
import cc.fascinated.bat.service.DiscordService;
import lombok.Getter;
@ -11,8 +10,7 @@ import net.dv8tion.jda.api.entities.User;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
/**
* @author Fascinated (fascinated7)
@ -27,6 +25,11 @@ public class BatUser extends ProfileHolder {
*/
@NonNull @Id private final String id;
/**
* The time this user was created
*/
private Date createdAt = new Date();
/**
* Gets the guild as the JDA Guild
*

View File

@ -2,12 +2,7 @@ package cc.fascinated.bat.service;
import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.command.impl.PingCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.features.autorole.command.AutoRoleCommand;
import cc.fascinated.bat.features.scoresaber.command.numberone.NumberOneFeedCommand;
import cc.fascinated.bat.features.scoresaber.command.scoresaber.ScoreSaberCommand;
import cc.fascinated.bat.features.scoresaber.command.userfeed.UserFeedCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import lombok.NonNull;
@ -52,18 +47,7 @@ public class CommandService extends ListenerAdapter {
this.userService = userService;
DiscordService.JDA.addEventListener(this);
// todo: auto register commands
// Guild commands
registerCommand(context.getBean(UserFeedCommand.class));
registerCommand(context.getBean(NumberOneFeedCommand.class));
registerCommand(context.getBean(AutoRoleCommand.class));
// Global commands
registerCommand(context.getBean(ScoreSaberCommand.class));
registerCommand(context.getBean(PingCommand.class));
registerSlashCommands(); // Register all slash commands
context.getBeansOfType(BatCommand.class).values().forEach(this::registerCommand);
}
/**
@ -72,6 +56,10 @@ public class CommandService extends ListenerAdapter {
* @param command The command to register
*/
public void registerCommand(@NonNull BatCommand command) {
if (commands.get(command.getName().toLowerCase()) != null) {
return;
}
log.info("Registered command \"{}\"", command.getName());
commands.put(command.getName().toLowerCase(), command);
}

View File

@ -9,7 +9,6 @@ import cc.fascinated.bat.model.BatUser;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -0,0 +1,36 @@
package cc.fascinated.bat.service;
import cc.fascinated.bat.features.Feature;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author Fascinated (fascinated7)
*/
@Service @Getter @Log4j2
@DependsOn("commandService")
public class FeatureService {
/**
* The registered features
*/
private final List<Feature> features = new ArrayList<>();
@Autowired
public FeatureService(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
context.getBeansOfType(Feature.class)
.values()
.forEach((feature) -> {
features.add(context.getBean(feature.getClass()));
});
commandService.registerSlashCommands(); // Register all slash commands
}
}