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.Inject;
import jakarta.inject.Singleton; import jakarta.inject.Singleton;
import me.goudham.command.CommandManager; import me.goudham.command.CommandManager;
import me.goudham.listener.SlashCommandListener;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
@ -29,7 +28,6 @@ public class EnsoBot implements Bot {
@Override @Override
public void startup() throws InterruptedException { public void startup() throws InterruptedException {
jda.awaitReady(); jda.awaitReady();
addEventListeners();
if (registerCommands) { if (registerCommands) {
commandManager.registerSlashCommands(guild); commandManager.registerSlashCommands(guild);
@ -37,8 +35,4 @@ public class EnsoBot implements Bot {
commandManager.populateCommandMap(); 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.List;
import java.util.Map; import java.util.Map;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import me.goudham.command.CommandHandler;
import me.goudham.listener.OnReadyListener; import me.goudham.listener.OnReadyListener;
import me.goudham.listener.SlashCommandListener;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
@ -38,25 +40,16 @@ public class BotConfig {
return new HashMap<>(); 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 @Singleton
@Order(1) @Order(1)
public JDA jda() throws LoginException { public JDA jda(CommandHandler commandHandler) throws LoginException {
return JDABuilder return JDABuilder
.createDefault(token) .createDefault(token)
.setActivity(Activity.playing("With Hamothy")) .setActivity(Activity.playing("With Hamothy"))
.addEventListeners(new OnReadyListener()) .addEventListeners(
new OnReadyListener(),
new SlashCommandListener(commandHandler)
)
.enableIntents( .enableIntents(
List.of( List.of(
GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MEMBERS,
@ -69,4 +62,16 @@ public class BotConfig {
).enableCache(CacheFlag.VOICE_STATE) ).enableCache(CacheFlag.VOICE_STATE)
.build(); .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