msgroom-orm Documentation

website·Indexed 29 days ago

https://nandertga.github.io/msgroom-orm/

A library and command framework for MsgRoom.js featuring a powerful command system with subcommands, a built-in help command, and a Client class extending TypedEventEmitter. The documentation includes API references for ClientOptions, CommandContext, and various event types such as Message and User.

Tokens
6.8K
Snippets
49
Records
73
Agent score
75%

What's inside msgroom-orm

  1. Reference the TagAddInfo interface properties

    The TagAddInfo interface (defined in types/events) provides metadata about a tag being added. It contains the following properties:

    • newTag (string): The identifier or value of the new tag.
    • newTagLabel (string): The display label associated with the new tag.
    • user (User): The user object associated with the action.
    interface TagAddInfo {
      user: User;
      newTag: string;
      newTagLabel: string;
    }
  2. Define bot commands in msgroom

    Commands are defined by adding objects to client.commands. Each command requires a handler function which receives a CommandContext and a spread of user-provided arguments. You can optionally include a description, aliases, and subcommands. A built-in help command is provided automatically.
    client.commands.ping = {
        description: "Replies with Pong!",
        handler    : () => "Pong!",
    };
    
    client.commands.repeat = {
        description: "Repeats what you said.",
        handler    : (context, ...args) => {
            return args.join(" ");
        },
    };
  3. Handle events using Client event emitter methods

    The Client class extends TypedEventEmitter, providing type-safe event handling based on ClientEvents. Available methods include:

    • on(event, listener): Registers a listener for the specified event.
    • once(event, listener): Registers a one-time listener for the specified event.
    • off(event, listener): Removes a listener.
    • prependListener(event, listener): Adds a listener to the beginning of the listeners array.
    • prependOnceListener(event, listener): Adds a one-time listener to the beginning of the listeners array.
    • removeAllListeners(event?): Removes all listeners, or all listeners for a specific event.
    • rawListeners(event): Returns an array of listeners for the specified event.
  4. Listen for client events in msgroom-orm

    The msgroom-orm client uses an EventEmitter pattern to handle events. You can listen for events using client.on(). Note that these events are transformed versions of the raw server events (socket.on) to be more developer-friendly. In addition to .on(), the client supports standard EventEmitter methods such as .off(), .once(), and .listeners().
    client.on("message", message => {
        console.log("Hey look mom I got a message!");
    });
  5. Define nested subcommands in msgroom-orm

    You can create hierarchical command structures by using the subcommands field within a command definition. Subcommands are defined as objects where the key is the subcommand name and the value is a standard command object (containing a description, handler, and potentially its own subcommands). There is no limit to the depth of nesting for subcommands.
    client.commands.subCommandTest = {
        description: "Main command description",
        handler: () => "Main command response",
        subcommands: {
            sub1: {
                description: "First level subcommand",
                handler: () => "First subcommand response"
            },
            subCommand: {
                description: "Nested subcommand",
                handler: () => "Nested response",
                subcommands: {
                    subSubcommand: {
                        description: "Second level subcommand",
                        handler: () => "Deeply nested response",
                    }
                }
            }
        }
    };
  6. Block users and sessions in msgroom

    To block a user, add their ID to client.blockedIDs or their session ID to client.blockedSessionIDs. Events triggered by blocked users are automatically ignored. You can manually verify if a user is blocked using the client.isBlocked() method.
    client.isBlocked("bad-user-id", "some session id"); // false
    client.blockedIDs.add("bad-user-id");
    client.isBlocked("bad-user-id", "some session id"); // true
  7. Initialize a msgroom Client

    Create a new Client instance by providing a bot name, one or more prefixes (strings or regular expressions), and an options object. To disable the command system entirely, set the prefix to an empty string (""). After configuration, call await client.connect() to establish the connection.
    import Client from "msgroom";
    
    const client = new Client("TestBot", "!", {
        // options here
    });
    
    await client.connect();
  8. Manage msgroom server connections with Client

    The Client class provides methods to establish and terminate connections to a msgroom server. Note that some properties cannot be changed after the connection is established.
    const client = new Client();
    
    // Connect to the server
    await client.connect();
    
    // Disconnect from the server
    client.disconnect();
  9. Install msgroom-orm nightly build

    Install the latest v2 build of msgroom-orm using npm, Yarn, or pnpm. Note that nightly builds are updated frequently and may contain breaking changes or instability.
    npm install msgroom@nightly