Package com.dianxin.tori.api.bot
Interface IBotLoader
public interface IBotLoader
An interface responsible for the lifecycle management and execution of bot files
within the Tori Server environment.
-
Method Summary
Modifier and TypeMethodDescriptionbooleandisableBot(String botName) Gracefully shuts down and removes a bot from the active bots list.booleanDynamically loads and starts a bot from a JAR file at runtime.Retrieves a list of all bot instances that are currently running on the server.voidloadBots()Scans the designated bots directory, reads their metadata, initializes their class loaders, and starts the bots concurrently.voidGracefully shuts down all currently active bots.
-
Method Details
-
loadBots
Scans the designated bots directory, reads their metadata, initializes their class loaders, and starts the bots concurrently.- Throws:
Exception- If a critical error occurs during the file reading or class loading process.
-
getActiveBots
List<JavaDiscordBot> getActiveBots()Retrieves a list of all bot instances that are currently running on the server.- Returns:
- An unmodifiable list of active
JavaDiscordBotinstances.
-
shutdownAll
void shutdownAll()Gracefully shuts down all currently active bots.This method triggers the
onShutdown()lifecycle event for each bot, allowing them to safely disconnect their JDA instances and save necessary data. -
enableBot
Dynamically loads and starts a bot from a JAR file at runtime.This method finds the specified JAR file in the bots directory, reads its metadata, initializes its class loader, and starts the bot in a separate thread.
- Parameters:
jarFileName- The name of the bot JAR file (e.g., "MyBot.jar")- Returns:
trueif the bot was successfully enabled,falseotherwise.
-
disableBot
Gracefully shuts down and removes a bot from the active bots list.This method finds the bot by name, calls its
onShutdown()lifecycle event, and removes it from the list of active bots.- Parameters:
botName- The name of the bot to disable (matches the 'name' field in bot.yml)- Returns:
trueif the bot was successfully disabled,falseif not found.
-