Skip to content

internal.inputs

orciument edited this page Nov 16, 2024 · 1 revision

Inputs are Threads that run for the entire runtime of the Bot. Inputs are supposed to provide Events to the rest of the application. These events can come through an external API that the Input is communication with, or trough anything that you might want to implement.

Registering Inputs

Inputs are Classes that are annotated with the @Input Annotation and implement the TwitchBotInput interface, this interface extends Runnable and makes the Inputs runnable as a separate Thread. Inputs are to be placed in the input directory under a folder of a name you can choose freely, for more information see Folder-structure. The Interface consists of a check Method that is called after all Inputs have been found and bevor the Inputs will be started, the Method should be used to check if all configuration, conditions and prerequisites for starting the bot are met, this can include trying to establish a connection with the API and closing it afterwards. In the ideal case, the Input should not be able to fail while starting if the check function returned true, this is because it is currently not tracked if a Input failed and shut down (besides the Input itself logging the failure).

If the check returned true, the input is started afterwards via the run() Method, this Method already runs in a new Thread, so it is not necessary to create a new Thread in this Method. When the Bot is shutdown the shutdown() Method is called on all Inputs, this Method should shut down the Input safely, save all necessary data to the database for persistence, and if you have created additional threads, you have to stop them yourself. The first Thread, the one that is created by calling the run() Method is disbanded after the run() Method runs to completion and returns.

Extending the current Input System

The Input system could be extended; mainly through a name change, rather than any technical changes, because it is already possible; to be more general subroutines instead of being just for inputting events. Then you would have Hooks and Subscriber for running Methods on Commands, and Events, and Subroutines for having a Thread in the background. You could use this to implement stuff like timer yourself using Subroutines instead of having to build it right into the core of the Bot.

Clone this wiki locally