Skip to main content
Version: Current

Core Types

BotFilter

Defines a bot filter function.

Common bot filters are byTag(tag, filter)

A BotFilter can be one of the following values:

  • (bot: Bot) => boolean
  • null

Space

The possible bot spaces.

  • "shared" means that the bot is a normal bot.
  • "local" means that the bot is stored in the local storage partition.
  • "tempLocal" means that the bot is stored in the temporary partition.
  • "tempShared" means that the bot is temporary and shared with other devices.
  • "remoteTempShared" means that the bot is temporary and shared with this device from a remote device.

A Space can be one of the following values:

  • "shared"
  • "local"
  • "tempLocal"
  • "history"
  • "admin"
  • "tempShared"
  • "remoteTempShared"
  • "certified"

BotState

Defines an interface that contains a set of bots that have been indexed by their IDs.

Generally, this is only used when working with groups of bots. For example, the diffSnapshots(first, second) function takes two bot states and produces the difference between them.

Index Signature

Gets or sets the bot in the state with the given ID.

[id: string]: Bot

Examples

Create a bot state with two bots
let state = {
[bot1.id]: bot1,
[bot2.id]: bot2
};
Get a bot by its ID from a bot state
let bot = state[botId];

TagMasks

Defines an interface for a map of tag masks to tag names.

Tag masks are special tags that can exist in a different space from the bot they are applied to. This makes it possible to have some local-only data applied to a shared bot for example.

The actual data structure is similar to the bot tags structure except that tags are additionally split by the space that they originated from. This makes it possible to identify which space a tag came from and also prevents cross-space conflicts.

interface TagMasks {
     [space: string]: Tags;
}

Index Signature

Gets or sets the tag masks that are specific to the given space.

[space: string]: Tags

Tags

Defines an interface that represents a set of tags and their related values.

interface Tags {
     [tag: string]: any
}

Index Signature

Gets or sets the given tag on the bot.

[tag: string]: any

Examples

Get the #color on this bot
let color = thisBot.tags.color;
Get a raw tag on this bot
let rawTag = thisBot.raw.tag;
Set the #color tag to "red" on this bot
thisBot.tags.color = "red";
Set a tempLocal tag mask for #color on this bot
thisBot.masks.color = "red";

Listeners

An interface that maps tag names to compiled listener functions.

interface Listeners {
     [tag: string]: (arg?: any) => any;
}

Index Signature

Gets the listener in the given tag.

[tag: string]: (arg: any) => any

Mod

Defines a type that represents a mod. That is, a set of tags that can be applied to another bot.

A Mod can be one of the following values:

Defines an interface that represents a bot link that was parsed from a tag.

The bot IDs that the link references.

The tag that the link was parsed from.

PartialBotState

Defines an interface that contains a set of partial bots that have been indexed by their IDs.

Generally, this is only used when working with differences between groups of bots. For example, the applyDiffToSnapshot(snapshot, diff) function takes a bot state and a partial bot state and produces a final state that contains the combined result.

Index Signature

[id: string]: Partial<Bot>

Bot

Defines an interface for a bot in a script/formula.

The difference between this and Bot is that the tags are calculated values and raw is the original tag values.

i.e. tags will evaluate formulas while raw will return the formula scripts themselves.

Index Signature

Gets the listener or bot property with the given name.

If given a property name, like "tags" or "vars", then it will return the value of that property. Alternatively, if the name does not match an existing property on the bot, then it will return the listener with the given name.

[listenerOrProperty: string]: (((arg: any) => any) | any)

Examples

Get the tags of a bot
let tags = bot.tags;
Get the links of a bot
let links = bot.links;
Get the @onClick listener of a bot
let onClick = bot.onClick;
Get a property on a bot by a variable
let propertyToGet = 'tags';
let tags = bot[propertyToGet];

changes: Tags

The changes that have been made to the bot.

id: string

The ID of the bot.

The link to the bot.

The tags on the bot that link to other bots.

listeners: Listeners

The calculated listener functions. This lets you get the compiled listener functions.

maskChanges: TagMasks

The tag mask changes that have been made to the bot.

masks: Tags

The tag masks that have been applied to this bot.

raw: Tags

The raw tag values. This lets you get the raw script text from formulas.

space?: Space

The space that the bot is in. Defaults to "shared"

tags: Tags

The calculated tag values. This lets you get the calculated values from formulas.

vars: Variables

The variables that the bot contains.

Defines an interface that represents the bot links a bot can have.

interface Links {
     [link: string]: Bot | Bot[];
}

Gets the bot or bots that are linked in the given tag.

[tag: string]: (Bot | Bot[])

Examples

Get a bot that is linked in the #manager tag
let managerBot = thisBot.links.manager;
Link a bot to another bot in the #manager tag
thisBot.links.manager = managerBot;

Variables

Defines an interface that represents the variables a bot can have. Variables are useful for storing data that is not able to be saved to a tag.

interface Variables {
     [variable: string]: any;
}

Index Signature

Gets or sets a variable on the bot.

[variable: string]: any

Examples

Get a variable on thisBot
let variable = thisBot.vars.variable;
Save a variable on thisBot
thisBot.vars.variable = variable;

TagFilter

Defines the possible values that can be used as a tag filter.

A TagFilter can be one of the following values:

  • (value: any) => boolean
  • string
  • number
  • boolean
  • null
  • undefined

PortalType

The possible portal types.

A PortalType can be one of the following values:

  • "grid"
  • "miniGrid"
  • "menu"
  • "sheet"
  • "meet"
  • "system"
  • string

PseudoRandomNumberGenerator

Defines an interface for a random number generator.

seed: (string | number)

The seed used for this random number generator. If null then an unpredictable seed was used.

random(): number

Generates a random number between 0 and 1.

randomInt(min: number, max: number): number

Generates a random integer between the given min and max values.

The first parameter is a number and is the minimum output number.

The second parameter is a number and is the maximum output number.

RegisterPrefixOptions

Defines an interface that contains options for register prefix actions.

language?: ("text" | "javascript" | "typescript" | "json" | "jsx" | "tsx")

The possible languages that prefixes can use.

name?: string

The name of the prefix.