}
}
// Setup the managers for the bot
setupManagers();
// Load the static commands
registerCommands(
new PingCommand(),
new AboutCommand()
);
if (SimpleSettings.Stop.Enabled()) {
registerCommand(new StopCommand());
}
// Load the static console commands
registerConsoleCommands(
new HelpConsoleCommand(),
new ClearConsoleCommand(),
new StopConsoleCommand()
);
// Load the bots matrix
onBotStart();
// Run the method that gets called to load things on startup and reloads
onReloadableStart();
// Register all the commands
slashCommandHandler.registerCommands();
// TODO: Make the reload system work
// Enable the bot
// TODO: Add a check to all managers to see if the bot is enabled
// before running command, button, menu, and modal code.
// TODO: Change how this method works. only set enabled to true if
// it is really done with everything and no errors accured.
// Adding multiple booleans in this class could do this.
// (separate checks for all systems)
setEnabled();
// A check to see if the bot is succecfully enabled
if (enabled) {
Common.success("Bot is ready");
} else {
Common.error("The bot failed to enable something is wrong!");
}
// A debug message to see what command are registered
if (Debugger.isDebugged("SlashCommand")) {
for (final Command command : getJDA().retrieveCommands().complete()) {
Debugger.debug("SlashCommand", command.getName() + "" + command.getDescription());
}
}
// A log option to show how many things are registered
Common.log("Loaded a total of " + ConsoleColor.CYAN + getSlashCommandHandler().getTotal() + ConsoleColor.RESET + " slash commands " + ConsoleColor.CYAN + getSlashCommandHandler().getGuildTotal() + ConsoleColor.RESET + " main guild and " + ConsoleColor.CYAN + getSlashCommandHandler().getPublicTotal() + ConsoleColor.RESET + " public");
Common.log("Loaded a total of " + ConsoleColor.CYAN + getConsoleCommandHandler().getTotal() + ConsoleColor.RESET + " console commands");
Common.log("Loaded a total of " + ConsoleColor.CYAN + getStringSelectMenuHandler().getTotal() + ConsoleColor.RESET + " menus");
Common.log("Loaded a total of " + ConsoleColor.CYAN + getButtonHandler().getTotal() + ConsoleColor.RESET + " buttons");
Common.log("Loaded a total of " + ConsoleColor.CYAN + getModalHandler().getTotal() + ConsoleColor.RESET + " modals");
}
/**
* The registration of the bot by Discord
*
* @param token The token from the https://discord.com/developers/applications
* @param activity The activity of the bot
*/
private static void registerJda(final String token, final Activity activity) {
// Log message when starting to register the bot
Common.log("Registering JDA...");
// Registering the bot by Discord
try {
jda = JDABuilder.createDefault(token)
.setEnabledIntents(GatewayIntent.getIntents(GatewayIntent.DEFAULT | GatewayIntent.GUILD_MEMBERS.getRawValue() | GatewayIntent.GUILD_BANS.getRawValue()))
.setDisabledIntents(GatewayIntent.DIRECT_MESSAGE_TYPING, GatewayIntent.GUILD_MESSAGE_TYPING)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.ONLINE_STATUS)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.setChunkingFilter(ChunkingFilter.ALL)
.setActivity(activity)
.setEventManager(new AnnotatedEventManager())
.build().awaitReady();
// Set selfUser so it can be used later
self = jda.getSelfUser();
onBotLoad();
// Log message when the bot is registered
Common.log("JDA registered");
} catch (final InterruptedException ex) {
Common.throwError(ex, "Failed to register JDA");
}
}
/**
* Initilization of all managers and handlers
*/
public final void setupManagers() {
// Log message to let know managers are starting
Common.log("Setting up the system managers");
slashCommandHandler = new SlashCommandHandler();
buttonHandler = new ButtonHandler();
modalHandler = new ModalHandler();
stringSelectMenuHandler = new StringSelectMenuHandler();
entitySelectMenuHandler = new EntitySelectMenuHandler();
consoleCommandHandler = new ConsoleCommandHandler();
cronHandler = new CronHandler();
// Log message to let know managers are setup
Common.log("System managers have been set up");
}
// TODO: Fix the reload system
/**
* Reload the bot, this method stops all systems and
* load the important things again.
* Database, Settings, cronHandlers
*/
private void reload() {
Common.log("Reload has been started")
// Check if the bot is enabled or not.
if (enabled) {
Common.log("Stopping systems to reload configuration");
// TODO: Add system stoppers
// Disable the bot when everything is disabled
enabled = false
}
// Load things before settings are loaded
onBotPreReload()
// Load after settings have loaded
onBotReload()
// TODO: Add enable methods
// Close old SQL connection safely before opening a new one
/*try {
sqlManager.getConnection().close();
it is really done with everything and no errors accured.
Adding multiple booleans in this class could do this.
(separate checks for all systems)
A check to see if the bot is succecfully enabled
https://github.com/Greazi-Times/Discord_Bot_Foundation/blob/39ba86761a1fb12315ab081b62b7bcb0af424621/src/main/java/com/greazi/discordbotfoundation/SimpleBot.java#L217