Skip to main content

Class: PreconditionContainerArray

An IPreconditionContainer that defines an array of multiple IPreconditionContainers.

By default, array containers run either of two conditions: AND and OR (PreconditionRunCondition), the top level will always default to AND, where the nested one flips the logic (OR, then children arrays are AND, then OR...).

This allows ['Connect', ['Moderator', ['DJ', 'SongAuthor']]] to become a thrice-nested precondition container, where:

  • Level 1: [Single(Connect), Array] runs AND, both containers must return a successful value.
  • Level 2: [Single(Moderator), Array] runs OR, either container must return a successful value.
  • Level 3: [Single(DJ), Single(SongAuthor)] runs AND, both containers must return a successful value.

In other words, it is identical to doing:

Connect && (Moderator || (DJ && SongAuthor));

remark More advanced logic can be accomplished by adding more IPreconditionConditions (e.g. other operators), see PreconditionContainerArray.conditions for more information.

since 1.0.0

Implements

Constructors

constructor

โ€ข new PreconditionContainerArray(data?, parent?)

Parameters

NameTypeDefault value
dataPreconditionArrayResolvable[]
parentnull | PreconditionContainerArraynull

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:127

Properties

entries

โ€ข Readonly entries: IPreconditionContainer[]

The IPreconditionContainers the array holds.

since 1.0.0

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:119


mode

โ€ข Readonly mode: PreconditionRunMode

The mode at which this precondition will run.

since 1.0.0

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:113


runCondition

โ€ข Readonly runCondition: PreconditionRunCondition

The PreconditionRunCondition that defines how entries must be handled.

since 1.0.0

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:125


conditions

โ–ช Static Readonly conditions: Collection<PreconditionRunCondition, IPreconditionCondition>

The preconditions to be run. Extra ones can be added by augmenting PreconditionRunCondition and then inserting IPreconditionConditions.

since 1.0.0

example

// Adding more kinds of conditions

// Set the new condition:
PreconditionContainerArray.conditions.set(2, PreconditionConditionRandom);

// Augment Sapphire to add the new condition, in case of a JavaScript
// project, this can be moved to an `Augments.d.ts` (or any other name)
// file somewhere:
declare module '@sapphire/framework' {
export enum PreconditionRunCondition {
Random = 2
}
}

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:219

Accessors

condition

โ€ข Protected get condition(): IPreconditionCondition

Retrieves a condition from PreconditionContainerArray.conditions, assuming existence.

since 1.0.0

Returns

IPreconditionCondition

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:194

Methods

add

โ–ธ add(entry): PreconditionContainerArray

Adds a new entry to the array.

since 1.0.0

Parameters

NameTypeDescription
entryIPreconditionContainerThe value to add to the entries.

Returns

PreconditionContainerArray

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:149


append

โ–ธ append(keyOrEntries): PreconditionContainerArray

Parameters

NameType
keyOrEntriesPreconditionContainerArray | SimplePreconditionKeys | SimplePreconditionSingleResolvableDetails

Returns

PreconditionContainerArray

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:154

โ–ธ append<K>(entry): PreconditionContainerArray

Type parameters

NameType
Kextends keyof Preconditions

Parameters

NameType
entryPreconditionSingleResolvableDetails<K>

Returns

PreconditionContainerArray

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:155


parse

โ–ธ Protected parse(entries): PreconditionContainerArray

Parses the precondition entry resolvables, and adds them to the entries.

since 1.0.0

Parameters

NameTypeDescription
entriesIterable<PreconditionEntryResolvable>The entries to parse.

Returns

PreconditionContainerArray

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:178


run

โ–ธ run(message, command, context?): PreconditionContainerReturn

Runs the container.

since 1.0.0

Parameters

NameTypeDescription
messageMessage<boolean>The message that ran this precondition.
commandCommand<Args, CommandOptions>The command the message invoked.
contextPreconditionContext-

Returns

PreconditionContainerReturn

Implementation of

IPreconditionContainer.run

Defined in

projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:167