1.0.4 • Published 10 years ago
behest v1.0.4
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 MTGUSDOkay, 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);
// => true
behest(message);
// => {
// => start: '/',
// => command: 'give',
// => params: ['KenanY', '5', 'bitcoins']
// => }Installation
$ npm install behestAPI
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.startis what began the command (!,/,., or;;)command.commandis the command (topic,help,timeout, etc.)command.paramsis an Array of what followed the command
behest.isValid(message)
Returns true if message passes the command regex. Returns false otherwise.