Add all event listeners in BotConfig.java

java-rewrite
Hammy 3 years ago
parent f855e60343
commit fbbe1ef005

@ -4,7 +4,6 @@ import io.micronaut.context.annotation.Value;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.goudham.command.CommandManager;
import me.goudham.listener.SlashCommandListener;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
@ -29,7 +28,6 @@ public class EnsoBot implements Bot {
@Override
public void startup() throws InterruptedException {
jda.awaitReady();
addEventListeners();
if (registerCommands) {
commandManager.registerSlashCommands(guild);
@ -37,8 +35,4 @@ public class EnsoBot implements Bot {
commandManager.populateCommandMap();
}
}
private void addEventListeners() {
jda.addEventListener(new SlashCommandListener(commandManager));
}
}

@ -11,7 +11,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.security.auth.login.LoginException;
import me.goudham.command.CommandHandler;
import me.goudham.listener.OnReadyListener;
import me.goudham.listener.SlashCommandListener;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
@ -38,25 +40,16 @@ public class BotConfig {
return new HashMap<>();
}
@Singleton
@Order(2)
public Guild ownerGuild(JDA jda) throws InterruptedException {
jda.awaitStatus(JDA.Status.CONNECTED);
Guild ownerGuild = jda.getGuildById(guildId);
if (ownerGuild == null) {
throw new RuntimeException("Owner Guild Not Found");
}
return ownerGuild;
}
@Singleton
@Order(1)
public JDA jda() throws LoginException {
public JDA jda(CommandHandler commandHandler) throws LoginException {
return JDABuilder
.createDefault(token)
.setActivity(Activity.playing("With Hamothy"))
.addEventListeners(new OnReadyListener())
.addEventListeners(
new OnReadyListener(),
new SlashCommandListener(commandHandler)
)
.enableIntents(
List.of(
GatewayIntent.GUILD_MEMBERS,
@ -69,4 +62,16 @@ public class BotConfig {
).enableCache(CacheFlag.VOICE_STATE)
.build();
}
@Singleton
@Order(2)
public Guild ownerGuild(JDA jda) throws InterruptedException {
jda.awaitStatus(JDA.Status.CONNECTED);
Guild ownerGuild = jda.getGuildById(guildId);
if (ownerGuild == null) {
throw new RuntimeException("Owner Guild Not Found");
}
return ownerGuild;
}
}

Loading…
Cancel
Save