3 API specification
7cc5c4f330d47060 edited this page 2024-09-08 22:59:37 -04:00

An old API specification from another repo, from before the release of beta 1.

The bot

chat (data) event

Gets called whenever a message is received. data format is as follows:

  • json: The raw JSON of the message.
  • type: The type of message (player, profileless, system, legacy)
  • uuid: The UUID of the message's sender
  • message: The message being sent, if it can be parsed
  • username: The username sending the message, if it can be parsed

command (name, uuid, text, prefix) command

Called when a user runs a command in Minecraft chat. The extra arguments are as follows:

  • name: The username of the person running the command
  • uuid: The UUID of the person running the command
  • text: The text of the command
  • prefix: The prefix used to run the command

plainchat (message, type) event

Gets called whenever a message is received. message is an already parsed message without any colors in any format. type is the type of message received (system, profileless, player, legacy)

ccstart event

Gets called whenever the command core is ready to be used.

addCloop (command, rate) function

A function to create a command loop of command command at rate rate.

removeCloop (index) function

This removes the cloop of index index.

clearCloops () function

This removes all command loops.

runCommand (name, nickname, uuid, text, msgType, prefix) function

Executes a command.

  • name: Username running the command
  • name: Nickname running the command
  • uuid: UUID running the command
  • text: Command text
  • msgType: the type of message received (system, profileless, player, legacy)
  • prefix: Prefix used to run the command

advanceccq () function

Advances the queue of commands to run in command blocks. Takes no arguments.

tellraw (uuid, message) function

Displays JSON text to a player using tellraw.

  • uuid: UUID/name/@a to display the message to
  • message: JSON text component to send, as a JavaScript object.

info (message) function

Displays message to console. Used by the reconnect script.

chat (message) function

Pushes message to the chat queue.

findUUID (name) function

Determine a player's UUID from their real name (not nickname).

findRealName (name) function

Determine a player's real name from their display name.

findRealNameFromUUID (uuid) function

Determine a player's real name from their UUID.

findDisplayName (uuid) function

Determine a player's display name (prefix + nickname on Kaboom) from their UUID.

add_sc_task (name, failTask, chatCommand, startFailed) function

Adds a selfcare task.

  • name: Name of the task being added
  • failTask: JavaScript function to run when failed is true
  • startFailed: Whether to run this task on login. Unused.

Utils (util folder)

parseNBT (data) function

Converts data to parsed JSON. If it already is parsed JSON, it passes it through.

chatparse_console (data) function

Parses a single chat message (data) to a format that can be displayed by a terminal in color.

chatparse_plain (data) function

Parses a single chat message (data) to a format that has no color formatting (useful for Discord or similar)

Command (uuid, user, nick, cmd, msgType, prefix, bot, verify, prefs) class

Internally used by the command handler. Converts the various arguments into a format which can be read by commands.

Inputs:

  • uuid: Player UUID
  • user: Player user name
  • nick: Player nickname
  • cmd: Command being called
  • msgType: the type of message received (system, profileless, player, legacy)
  • prefix: Prefix used to run the command
  • bot: Bot on the server the command is being run from
  • verify: Permission level determined from the hash or lack thereof
  • prefs: The settings that the player selected or the bot's defaults for each missing setting

Outputs:

  • send (text, uuid): Effectively just a tellraw wrapper.

    • text: The raw JSON of the message.
    • uuid: UUID/name/@a to display the message to
  • reply (text): Reply to a command with JSON

    • text: The raw JSON of the message.
  • uuid: Player UUID

  • username: Player user name

  • nickname: Player nickname

  • command: Command being called

  • msgType: the type of message received (system, profileless, player, legacy)

  • prefix: Prefix used to run the command

  • bot: Bot on the server the command is being run from

  • type: Type of bot receiving the command

  • index: Index of the bot in the bot array

  • args: Arguments of the command

  • verify: Permission level determined from the hash or lack thereof

  • host: The server the command was sent from

  • port: The port of server the command was sent from

  • prefs: The settings that the player selected or the bot's defaults for each missing setting

  • lang: The language that the player has selected (not implemented) or the bot's default

  • colors: The colors that the player has selected (not implemented) or the bot's default

  • ConsoleCommand (cmd, index2) class

Internally used by the command handler. Converts the various arguments into a format which can be read by commands.

Inputs:

  • cmd: Command being called
  • index2: Index of the bot in the bot array where the command is being run (running commands like say * will call this class several times)

Outputs:

  • send (): Stub function. Why do I still have this?
  • reply (text): Reply to a command with JSON (gets parsed by the console parser)
    • text: The raw JSON of the message.
  • uuid: Always dde5a2a6-ebdd-4bbb-8eac-f75b10c10446_console. Hard-coded because the console does not have a UUID.
  • username: Always Owner. Hard-coded because the console does not have a username.
  • nickname: Always Console. Hard-coded because the console does not have a nickname.
  • command: Command being called
  • msgType: Always _bot_console. Hard-coded because the user does not send Minecraft messages to the command handler from console.
  • prefix: Always an empty string. Hard-coded because the console does not have a prefix to run commands.
  • bot: Bot on the server the command is being run from (a stub with only the help functions if it does not require to be run as a bot)
  • type: Type of bot receiving the command
  • index: Always the index2 value. Hard-coded because the console does not have a bot ID.
  • args: Arguments of the command
  • verify: Always 3. Hard-coded because the console has permission level 3.
  • host: Always an empty string. Hard-coded because the console does not have a server host.
  • port: Always 3. Hard-coded because the console does not have a server port. Displays as :3 in commands such as netmsg.
  • lang: The bot's default language
  • colors: The bot's default colors

hashcheck (cmd) function

Checks cmd against the hashing system. If it matches, it returns a non-zero value corresponding to the level of hash that matched.

lang.getMessage (l, msg, with2) function

Gets a message (msg) in a certain language (l), and replaces all %s with the values in with2.

lang.timeFormat (time, language) function

Formats an amount of time in milliseconds (time) to the language language.

Generates a username for the bot to join the server with.

  • legal: Whether to generate a legal username

Index.js

bot array

An array of bots. Each one should be connected to a different server.

createBot (host, oldId) function

Creates a bot with the options specified by host, on id oldId if specified, otherwise added to the end of the bot array. Used internally by index.js itself as well as the reconnect script.