Tidy up code

java-rewrite
Hammy 3 years ago
parent dd6763269e
commit a2efe9dc69

@ -1,71 +1,26 @@
package me.goudham.bot; package me.goudham.bot;
import io.micronaut.context.BeanContext;
import io.micronaut.core.annotation.AnnotationValue;
import io.micronaut.inject.BeanDefinition;
import io.micronaut.inject.qualifiers.Qualifiers;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.inject.Singleton; import jakarta.inject.Singleton;
import java.lang.annotation.Annotation; import me.goudham.command.CommandManager;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import me.goudham.command.annotation.Choice;
import me.goudham.command.annotation.Command;
import me.goudham.command.annotation.Option;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
@Singleton @Singleton
public class Enso implements Bot { public class Enso implements Bot {
private final JDA bot; private final JDA bot;
private final BeanContext beanContext; private final Guild guild;
private final CommandManager commandManager;
@Inject @Inject
public Enso(JDA bot, BeanContext beanContext) { public Enso(JDA bot, Guild guild, CommandManager commandManager) {
this.bot = bot; this.bot = bot;
this.beanContext = beanContext; this.guild = guild;
this.commandManager = commandManager;
} }
@Override @Override
public void startup() { public void startup() {
System.out.println("pog"); commandManager.registerSlashCommands(guild);
Set<Class<?>> classes = collectConsumedAnnotatedClasses();
// CommandListUpdateAction commands = bot.updateCommands();
// CommandData commandData = new CommandData("", "");
// SubcommandGroupData subcommandGroupData = new SubcommandGroupData();
// SubcommandData subcommandData = new SubcommandData();
// OptionData optionData = new OptionData(OptionType.BOOLEAN, "", "");
// Guild guildById = bot.getGuildById(1234);
// guildById.upsertCommand()
// commands.addCommands(
// commandData
// );
}
private Set<Class<?>> collectConsumedAnnotatedClasses() {
Set<Class<?>> classes = new HashSet<>();
Collection<BeanDefinition<?>> definitions = beanContext.getBeanDefinitions(Qualifiers.byStereotype(Command.class));
definitions.forEach(definition -> {
AnnotationValue<Annotation> command = definition.getDeclaredAnnotation("me.goudham.command.annotation.Command");
Optional<String> name = command.stringValue("name");
if (command.contains("options")) {
List<AnnotationValue<Option>> optionAnnotations = command.getAnnotations("options", Option.class);
for (AnnotationValue<Option> optionAnnotationValue : optionAnnotations) {
// do option stuff
if (command.contains("choices")) {
List<AnnotationValue<Choice>> choiceAnnotations = optionAnnotationValue.getAnnotations("choices", Choice.class);
for (AnnotationValue<Choice> choiceAnnotationValue : choiceAnnotations) {
// do choice stuff
}
} }
}
}
});
return classes;
}
} }

Loading…
Cancel
Save