Giter Club home page Giter Club logo

slash's Introduction

slash

Easy handling of slash commands.

Users

There are three ways to use a custom slash command:

  • type `command args into any chat channel
  • /w `command args to send a whisper to a target starting with the command prefix
  • /w /command args to send a whisper to a target starting with a slash

Currently the prefix ` is not settable anywhere but in the code.

If strict mode is enabled (it is by default), any message that starts with the prefix and is not a registered command will not be sent. If you want to send a message starting with the command prefix, put a backslash (\) before it and the backslash will be removed and the message sent as normal.

Developers

To register slash commands, instantiate an object of Slash passing dispatch as the sole argument to the constructor, and then use Slash#on(command, callback) to register a hook.

callback will be passed only one parameter, args, which is an array of all command arguments with all HTML tags removed, HTML entities decoded, and all extra whitespace removed. args[0] is the command name.

args also has two properties:

  • raw: the original, raw text of the slash command
  • target: either an integer for the chat channel, or a string of the whisper target. If the whisper command syntax was used, target will be the whisper channel (7), otherwise it will be the name of whomever was the whisper target when the command was entered.

In all cases, args and raw will be normalized to always look like prefix form. In other words, args[0] will always begin with the prefix, and raw will always begin with either <FONT> and the HTML encoded prefix, or in some cases, just the HTML encoded prefix.

An instance of Slash has three read-only properties:

  • prefix: the HTML encoded prefix (only &lt; and &gt; conversions)
  • prefixRaw: the prefix without HTML encoding
  • strict: true if invalid commands are silenced, false otherwise

Example

const Slash = require('slash');

module.exports = function Example(dispatch) {
  const slash = new Slash(dispatch);

  slash.on('command', (args) => {
    // ...
  });
};

slash's People

Contributors

meishuu avatar ericbanker12 avatar

Stargazers

Kyon avatar  avatar Yukikoo avatar

Watchers

James Cloos avatar  avatar  avatar  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.