Nighttime Possum Meandering
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    behestpublic

    behest

    Build Status Dependency Status

    Parser for commands to IRC bots.

    Let's first examine the different syntaxes used by various IRC bots:

    Classic:                   /help
    TwitchTV bots:             !topic
    TwitchTV IRC mod commands: .timeout 2 KenanY
    #bitcoin-otc:              ;;book MTGUSD
    

    Okay, so IRC bot commands typically:

    1. Start with a !, ., /, or two ;s
    2. Are immediately followed by the command, which is alphanumeric
    3. (optional) Followed by parameter(s), separated by spaces

    If a regex was written for this pattern, it would hopefully look like this:

    /^(([!.\/])|(;{2}))\w+(\s[^\s]+)*$/
    

    And if you were to make a railroad diagram of this regex, you would have this:

    trainwreck

    Example

    var behest = require('behest');
     
    var message = '/give KenanY 5 bitcoins';
     
    behest.isValid(message);
    // => true
     
    behest(message);
    // => {
    // =>   start: '/',
    // =>   command: 'give',
    // =>   params: ['KenanY', '5', 'bitcoins']
    // => }

    Installation

    $ npm install behest

    API

    behest(message)

    Parses the String message. If message is not a valid IRC command (the syntax of which has already been described), an empty Object is returned. Otherwise, an Object (let's call it command) is returned:

    • command.start is what began the command (!, /, ., or ;;)
    • command.command is the command (topic, help, timeout, etc.)
    • command.params is an Array of what followed the command

    behest.isValid(message)

    Returns true if message passes the command regex. Returns false otherwise.

    Keywords

    install

    npm i behest

    Downloadsweekly downloads

    11

    version

    1.0.4

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar