Skip to content

Latest commit

 

History

History
246 lines (142 loc) · 5.93 KB

File metadata and controls

246 lines (142 loc) · 5.93 KB

Bot / structs/handlers/Handler / Handler

Class: Handler<T>

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.

Type parameters

Name Type Description
T extends Module The type of module that the handler manages.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Handler<T>(client)

Initializes a new Handler instance.

Type parameters

Name Type
T extends Module

Parameters

Name Type Description
client Client<boolean> The instantiated Discord client.

Defined in

src/structs/handlers/Handler.ts:60

Properties

client

Readonly client: Client<boolean>

The Discord client.

A reference to the instantiated Discord client.

Defined in

src/structs/handlers/Handler.ts:45


directory

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.

Defined in

src/structs/handlers/Handler.ts:38


modules

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.

Defined in

src/structs/handlers/Handler.ts:53


reference

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.

Defined in

src/structs/handlers/Handler.ts:29

Methods

import

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.

Parameters

Name Type Description
path string The path to import the module from.

Returns

T

The initialized module.

Defined in

src/structs/handlers/Handler.ts:77


inherits

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.

Parameters

Name Type Description
object unknown The object to check.

Returns

object is Function

Whether if the object is a valid module.

Defined in

src/structs/handlers/Handler.ts:163


register

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.

Parameters

Name Type Description
path string The path to register the module at.

Returns

T

The registered module.

Defined in

src/structs/handlers/Handler.ts:131


registerAll

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.

Parameters

Name Type Description
directory string The directory to register modules from.

Returns

void

Defined in

src/structs/handlers/Handler.ts:101