Bat/src/main/java/cc/fascinated/bat/service/FeatureService.java

44 lines
1.3 KiB
Java
Raw Normal View History

2024-06-25 14:43:36 +00:00
package cc.fascinated.bat.service;
2024-06-25 16:20:19 +00:00
import cc.fascinated.bat.command.BatCommand;
2024-06-25 14:43:36 +00:00
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()));
});
2024-06-25 16:20:19 +00:00
context.getBeansOfType(BatCommand.class)
.values()
.forEach((command) -> {
commandService.registerCommand(context.getBean(command.getClass()));
});
2024-06-25 14:43:36 +00:00
commandService.registerSlashCommands(); // Register all slash commands
}
}