Package Description

LIBRARY: This module is just a dependency for other modules and provides little functionality on its own.

 

Allows for easy registration of custom chat commands such as /command.

The library will handle multiple commands in a single string - if any are marked shouldDisplayToChat, then a single chat message is created with all commands stripped.

 

Example Usage

Hooks.on("chatCommandsReady"function(chatCommands) {

  // (GM Only) This Command will display the text after the command as well as invoke the method
  chatCommands.registerCommand(chatCommands.createCommandFromData({
    commandKey: "/displaytochat",
    invokeOnCommand: (chatlogmessageTextchatdata=> {
      console.log("Invoked /displaytochat");
      console.log(messageText);
    },
    shouldDisplayToChat: true,
    iconClass: "fa-sticky-note",
    description: "Display to chat",
    gmOnly: true
  }));


  // This will eat the command, displaying nothing to chat, as well as invoke the method
  chatCommands.registerCommand(chatCommands.createCommandFromData({
    commandKey: "/dontdisplaytochat",
    invokeOnCommand: (chatlogmessageTextchatdata=> {
      console.log("Invoked /dontdisplaytochat");
      console.log(messageText);
    },
    shouldDisplayToChat: false,
    iconClass: "fa-sticky-note",
    description: "Don't display to chat"
  }));


  // This uses the optional createdMessageType option to make the created message "Out of Character"
  chatCommands.registerCommand(chatCommands.createCommandFromData({
    commandKey: "/outofcharacter",
    invokeOnCommand: (chatlogmessageTextchatdata=> {
      console.log("Invoked /outofcharacter");
      console.log(messageText);
    },
    shouldDisplayToChat: true,
    createdMessageType: 1,
    iconClass: "fa-sticky-note",
    description: "Posts message OOC"
  }));


  // This modifies the text that will end up in the created message
  var command = chatCommands.createCommandFromData({
    commandKey: "/toupper",
    invokeOnCommand: (chatlogmessageTextchatdata=> {
      console.log("Invoked /toupper");
      messageText = messageText.toUpperCase();
      console.log(messageText);
      return messageText;
    },
    shouldDisplayToChat: true,
    iconClass: "fa-sticky-note",
    description: "Uppercases text"
  });

  chatCommands.registerCommand(command);

  // Actually, deregister it
  chatCommands.deregisterCommand(command);
});
 
 


Tagged Categories

  1. Chat Log and Messaging

Available Versions

  1. Version beta1-1.0.0

  2. Version 1.1.0

  3. Version 1.2.0

  4. Version 1.3.0

  5. Version 1.3.2

  6. Version 1.3.3