Parser for commands to IRC bots


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:


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

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

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

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