Introduce discrete event handlers (`InteractionHandlers`, `GuildLifecycleHandler`, `MessageReceivedHandler`, and more) to replace centralized logic in `EventsHandler`. Simplify handler registration, improve separation of concerns, and enable better testability. Added unit tests to verify isolated execution and failure resilience of handlers.
37 lines
953 B
Java
37 lines
953 B
Java
package me.bobert.netneutrality.hooks;
|
|
|
|
/*
|
|
* Copyright (c) anthorob
|
|
*
|
|
* https://discord.gg/qUa6zNFZsd
|
|
*/
|
|
|
|
import me.bobert.netneutrality.core.command.CommandRegistry;
|
|
import net.dv8tion.jda.api.events.session.ReadyEvent;
|
|
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* Registers the global slash commands once the first shard is ready.
|
|
*/
|
|
public class ReadyHandler implements EventListenerHandler<ReadyEvent> {
|
|
private final CommandRegistry commands;
|
|
|
|
public ReadyHandler(CommandRegistry commands) {
|
|
this.commands = Objects.requireNonNull(commands, "commands");
|
|
}
|
|
|
|
@Override
|
|
public Class<ReadyEvent> eventType() {
|
|
return ReadyEvent.class;
|
|
}
|
|
|
|
@Override
|
|
public void handle(ReadyEvent event) {
|
|
// Global commands are shared by all shards, so only register them once.
|
|
if (event.getJDA().getShardInfo().getShardId() == 0) {
|
|
commands.registerSlashCommands(event.getJDA());
|
|
}
|
|
}
|
|
}
|