Better Chat Commands [API]

Better Chat Commands [API] 2.0.0

IMPORTANT: THIS HAS BEEN CONVERTED FROM A MOD INTO A LIBRARY. PLEASE PLACE IT IN YOUR MODS FOLDER TO USE IT.



Added​

  • New module structure: the file now returns a table via return M, usable with require.
  • Namespaced API surface — all functions live on M instead of _G. The old _G exports are gone.
  • 4 new argument types on top of the original 5:
    • CMD_ARG_DURATION — parses 500ms, 5s, 2m, 1h30m, 2d into frames (30 fps). Plain numbers are treated as seconds.
    • CMD_ARG_COLOR — parses #rrggbb, rrggbb, or a named color (red, cyan, etc.). Returns {r, g, b, hex} with components in 0..255.
    • CMD_ARG_STRING_REST — rest-of-line argument, keeps commas, must be the last argument in the list.
    • CMD_ARG_PLAYER_LIST — a single player or @a (array of all connected MarioState).
  • Player selectors: @s (self), @p (nearest), @r (random) for CMD_ARG_PLAYER; @a additionally for CMD_ARG_PLAYER_LIST. Enabled via selectors = true per argument.
  • Optional arguments with default values.
  • ... skip syntax — an optional argument can be explicitly bypassed at any position.
  • Enum support via choices = { "add", "remove", "toggle" }. Case-insensitive, normalized to the entry from choices.
  • min / max bounds for CMD_ARG_INTEGER and CMD_ARG_NUMBER.
  • Permission gating via options.permission:
    • "anyone" / "user" — no restriction.
    • "moderator" / "mod" — mods and host.
    • "host" / "server" / "admin" — host only.
  • Automatic Usage: line appended to every parse error, generated from the argument signature.
  • pcall protection around command bodies. On failure, the player sees a short message and the console gets the stack trace plus a dump of parsed arguments.
  • Registration-time validation:
    • CMD_ARG_STRING_REST must be the last argument.
    • Only one CMD_ARG_STRING_REST per command.
    • Mandatory arguments cannot follow optional ones.
    • command, description, args, func are all type-checked.
  • Duplicate command registration warning in the console.
  • Console logging helpers with color tags: log_error_console, log_warn_console.
  • Full LuaDoc annotations for every function, alias, and class.
  • Two accepted forms of argument declaration:
    • Array form: { { "name", TYPE, optional = true, default = X }, ... } — preserves order, supports all options.
    • Map form: { name = TYPE } — backward-compatible with v1, order is sorted alphabetically.

Changed​

  • Argument parsing rewritten to preserve trailing empty tokens and trailing commas are now handled correctly.
  • CMD_ARG_BOOLEAN now accepts 1/0 in addition to true/false, and matching is case-insensitive.
  • CMD_ARG_INTEGER no longer accepts 0x10, 1e5, or whitespace-padded values.
  • Error messages now always include the command's usage string.
  • Argument order is deterministic: array form uses declaration order; map form is sorted alphabetically.

Fixed​

  • Argument ordering no longer depends on pairs — previously the parsing order and the description order could diverge between runs.
  • Empty command body no longer crashes on chat_create_log.

Removed​

  • G exports: CMD_ARG, hook_better_chat_command, chat_create_. Use local BC = require("better-commands") and access them via BC. instead.

Color palette​

  • Success: #00ff00 → #a0ffa0.
  • Warning: #ffaa00 → #fff982.
  • Error: #ff4444 → #ffa0a0.
  • Log: #8aa3ab → #91a9b3.