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
new PreconditionContainerArray()
new PreconditionContainerArray(
data
:PreconditionArrayResolvable
,parent
:null
|PreconditionContainerArray
):PreconditionContainerArray
Parameters
Parameter | Type | Default value |
---|---|---|
data | PreconditionArrayResolvable | [] |
parent | null | PreconditionContainerArray | null |
Returns
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
readonly
static
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:254
Accessors
condition
get
protected
condition():IPreconditionCondition
Retrieves a condition from PreconditionContainerArray.conditions, assuming existence.
Since
1.0.0
Returns
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:229
Methods
add()
add(
entry
:IPreconditionContainer
):this
Adds a new entry to the array.
Parameters
Parameter | Type | Description |
---|---|---|
entry | IPreconditionContainer | The value to add to the entries. |
Returns
this
Since
1.0.0
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:149
append()
append(keyOrEntries)
append(
keyOrEntries
:SimplePreconditionKeys
|SimplePreconditionSingleResolvableDetails
|PreconditionContainerArray
):this
Parameters
Parameter | Type |
---|---|
keyOrEntries | SimplePreconditionKeys | SimplePreconditionSingleResolvableDetails | PreconditionContainerArray |
Returns
this
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:154
append(entry)
append<
K
>(entry
:PreconditionSingleResolvableDetails
<K
>):this
Type Parameters
Type Parameter |
---|
K extends keyof Preconditions |
Parameters
Parameter | Type |
---|---|
entry | PreconditionSingleResolvableDetails <K > |
Returns
this
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:155
chatInputRun()
chatInputRun(
interaction
:ChatInputCommandInteraction
<CacheType
>,command
:ChatInputCommand
,context
:PreconditionContext
):PreconditionContainerReturn
Runs the container.
Parameters
Parameter | Type | Description |
---|---|---|
interaction | ChatInputCommandInteraction <CacheType > | The interaction that ran this precondition. |
command | ChatInputCommand | The command the interaction invoked. |
context | PreconditionContext | The context for the chat input precondition. |
Returns
Since
3.0.0
Implementation of
IPreconditionContainer
.chatInputRun
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:181
contextMenuRun()
contextMenuRun(
interaction
:ContextMenuCommandInteraction
<CacheType
>,command
:ContextMenuCommand
,context
:PreconditionContext
):PreconditionContainerReturn
Runs the container.
Parameters
Parameter | Type | Description |
---|---|---|
interaction | ContextMenuCommandInteraction <CacheType > | The interaction that ran this precondition. |
command | ContextMenuCommand | The command the interaction invoked. |
context | PreconditionContext | The context for the context menu precondition. |
Returns
Since
3.0.0
Implementation of
IPreconditionContainer
.contextMenuRun
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:198
messageRun()
messageRun(
message
:Message
<boolean
>,command
:MessageCommand
,context
:PreconditionContext
):PreconditionContainerReturn
Runs the container.
Parameters
Parameter | Type | Description |
---|---|---|
message | Message <boolean > | The message that ran this precondition. |
command | MessageCommand | The command the message invoked. |
context | PreconditionContext | The context for the message command precondition. |
Returns
Since
1.0.0
Implementation of
IPreconditionContainer
.messageRun
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:168
parse()
protected
parse(entries
:Iterable
<PreconditionEntryResolvable
>):this
Parses the precondition entry resolvables, and adds them to the entries.
Parameters
Parameter | Type | Description |
---|---|---|
entries | Iterable <PreconditionEntryResolvable > | The entries to parse. |
Returns
this
Since
1.0.0
Defined in
projects/framework/src/lib/utils/preconditions/PreconditionContainerArray.ts:213