Coder Social home page Coder Social logo

xdy-forks / chat-commands-lib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from league-of-foundry-developers/chat-commands-lib

0.0 0.0 0.0 725 KB

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

License: GNU General Public License v3.0

JavaScript 97.29% CSS 2.71%

chat-commands-lib's Introduction

FoundryVTT Library: Chat Commands

Allows for easy registration of custom chat commands such as /command, complete with autocomplete

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.

As of v1.2.0, Core Command autocomplete is included as part of the library

Include as a dependency in your manifest

{
    "name": "_chatcommands",
    "type": "module",
    "manifest": "https://github.com/League-of-Foundry-Developers/Chat-Commands-Lib/releases/download/1.2.0/module.json"
}

Chat Command class

commandKey

Type: string The chat command, such as "/command"

invokeOnCommand

Type: function

The function to invoke when the command is matched

Example Function:

function onCommandInvoke(chatlog, messageText, chatData) => {
    console.log("Invoked Command");
});

shouldDisplayToChat

Type: boolean Default: false

If true, the command will be removed from the message and the message displayed to chat, such as "/command hi" -> "hi" If false, no message will be displayed

createdMessageType

Type: integer Default: 0 (Other)

When shouldDisplayToChat is true, the type of message that should be created

iconClass

Type: string Default: fa-terminal

A Font Awesome icon to display in the autocomplete results

description

Type: string Default: No description provided

A string to display in autocomplete results to help a user pick the right command

gmOnly

Type: boolean Default: false

If true, the command will only be executed if the current user is a GM

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: (chatlog, messageText, chatdata) => {
      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: (chatlog, messageText, chatdata) => {
      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: (chatlog, messageText, chatdata) => {
      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: (chatlog, messageText, chatdata) => {
      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);
});

Changelog

v1.0.0

  • Initial release

v1.1.0

  • Deprecated createCommand(commandKey, shouldDisplayToChat, invokeOnCommand, createdMessageType = 0) in favor of createCommandFromData(data)
  • Added autocomplete for commands (on by default, client setting)
  • Added IconClass
  • Added Description

v1.2.0

  • Added Core Command autocomplete

v1.3.0

  • Added deregisterCommand
  • Added gmOnly command option
  • CSS fixes, including compatibility with Dice Tray
  • Removed extraneous logs

chat-commands-lib's People

Contributors

aaronlip avatar cswendrowski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.