behest
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:
- Start with a
!
, .
, /
, or two ;
s - Are immediately followed by the command, which is alphanumeric
- (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:
Example
var behest = require('behest');
var message = '/give KenanY 5 bitcoins';
behest.isValid(message);
behest(message);
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.