Bot / structs/handlers/Handler / Handler
structs/handlers/Handler.Handler
The base structure for handlers.
Handlers are used to manage modules, which are abstract classes that must be extended to define a certain functionality. Handlers are responsible for importing modules from files and storing them within a collection for future reference.
| Name | Type | Description |
|---|---|---|
T |
extends Module |
The type of module that the handler manages. |
-
Handler
• new Handler<T>(client)
Initializes a new Handler instance.
| Name | Type |
|---|---|
T |
extends Module |
| Name | Type | Description |
|---|---|---|
client |
Client<boolean> |
The instantiated Discord client. |
src/structs/handlers/Handler.ts:60
• Readonly client: Client<boolean>
The Discord client.
A reference to the instantiated Discord client.
src/structs/handlers/Handler.ts:45
• Readonly Abstract directory: string
The root directory to look for modules in.
When importing modules, the handler will use the specified directory to look in, importing all scripts within this directory and all subdirectories.
src/structs/handlers/Handler.ts:38
• Readonly modules: Map<string, T>
The collection of modules that the handler manages.
References all modules that have been initialized by the handler, stored within a collection for future reference.
src/structs/handlers/Handler.ts:53
• Readonly Abstract reference: AbstractClass<T, any[]>
A reference to the abstract class that the handler manages.
This property references the abstract class for the desired module, allowing the handler to determine whether if a file correctly exports an instance of the expected class.
src/structs/handlers/Handler.ts:29
▸ import(path): T
Imports and initializes a module from a file.
This method implements the logic used for initializing a module from a file, given a path, the method attempts to import and initialize a module from the file.
Note that when importing a module, this method only looks at the script's default export.
| Name | Type | Description |
|---|---|---|
path |
string |
The path to import the module from. |
T
The initialized module.
src/structs/handlers/Handler.ts:77
▸ inherits(object): object is Function
Determines whether if the provided object is a valid module.
A helper method that determines whether if the provided object is an instantiable class that extends the abstract class that the handler manages.
This method is used to determine whether if a file correctly exports an instance of the expected class.
| Name | Type | Description |
|---|---|---|
object |
unknown |
The object to check. |
object is Function
Whether if the object is a valid module.
src/structs/handlers/Handler.ts:163
▸ register(path): T
Registers a module within the handler.
This method will register a module from the specified path, initializing it and storing it within the handler's collection of modules.
| Name | Type | Description |
|---|---|---|
path |
string |
The path to register the module at. |
T
The registered module.
src/structs/handlers/Handler.ts:131
▸ registerAll(directory?): void
Registers all modules from the provided directory.
This method will recursively import all modules from the specified directory, initializing them and storing them within the handler's collection of modules.
| Name | Type | Description |
|---|---|---|
directory |
string |
The directory to register modules from. |
void