Comparing version 1.1.8 to 1.1.9
@@ -30,8 +30,7 @@ var sys = require( 'sys' ) | ||
.on( 'privmsg', _receive_message.bind( this ) ) | ||
.connect( function() { | ||
if ( options.waitForPing ) | ||
bot.once( 'ping', _on_connect ) | ||
else | ||
_on_connect.call( bot ) | ||
.on( 'error', function( message ) { | ||
console.log( 'There was an error! "' + message.params[0] + '"' ) | ||
this.disconnect().connect( _on_connect.bind( this ) ) | ||
}) | ||
.connect( _on_connect.bind( bot ) ) | ||
@@ -47,13 +46,20 @@ return { say: _privmsg_protected.bind( this ) | ||
function _on_connect() { | ||
setTimeout( function(){ | ||
// Join channels | ||
var i | ||
if ( Array.isArray( this.options.channels ) ) | ||
for ( i = 0; i < this.options.channels.length; i++ ) | ||
this.join( this.options.channels[i] ) | ||
if ( this.options.waitForPing ) | ||
this.once( 'ping', justDoIt ) | ||
else | ||
justDoIt.call( this ) | ||
// Call onConnect callback | ||
if ( this.options.onConnect ) | ||
this.options.onConnect() | ||
}.bind( this ), this.options.delayAfterConnect || 1000 ) | ||
function justDoIt () { | ||
setTimeout( function() { | ||
// Join channels | ||
var i | ||
if ( Array.isArray( this.options.channels ) ) | ||
for ( i = 0; i < this.options.channels.length; i++ ) | ||
this.join( this.options.channels[i] ) | ||
// Call onConnect callback | ||
if ( this.options.onConnect ) | ||
this.options.onConnect() | ||
}.bind( this ), this.options.delayAfterConnect || 1000 ) | ||
} | ||
} | ||
@@ -60,0 +66,0 @@ |
@@ -9,3 +9,3 @@ { "name" : "jerk" | ||
, "homepage" : "http://github.com/gf3/Jerk" | ||
, "version" : "1.1.8" | ||
, "version" : "1.1.9" | ||
, "main" : "./lib/jerk" | ||
@@ -12,0 +12,0 @@ , "dependencies" : |
@@ -21,25 +21,31 @@ # Jerk | ||
var jerk = require( 'jerk' ) | ||
```javascript | ||
var jerk = require( 'jerk' ) | ||
``` | ||
You'll need some `options`. Jerk takes the exact same options object as the [IRC-js library](https://github.com/gf3/IRC-js/). Let's just go ahead and supply some basic info: | ||
var options = | ||
{ server: 'irc.freenode.net' | ||
, nick: 'YourBot9001' | ||
, channels: [ '#your-channel' ] | ||
} | ||
```javascript | ||
var options = | ||
{ server: 'irc.freenode.net' | ||
, nick: 'YourBot9001' | ||
, channels: [ '#your-channel' ] | ||
} | ||
``` | ||
Hah, now you're going to cry once you see how easy this is: | ||
jerk( function( j ) { | ||
```javascript | ||
jerk( function( j ) { | ||
j.watch_for( 'soup', function( message ) { | ||
message.say( message.user + ': soup is good food!' ) | ||
}) | ||
j.watch_for( 'soup', function( message ) { | ||
message.say( message.user + ': soup is good food!' ) | ||
}) | ||
j.watch_for( /^(.+) are silly$/, function( message ) { | ||
message.say( message.user + ': ' + message.match_data[1] + ' are NOT SILLY. Don't joke!' ) | ||
}) | ||
j.watch_for( /^(.+) are silly$/, function( message ) { | ||
message.say( message.user + ': ' + message.match_data[1] + ' are NOT SILLY. Don\'t joke!' ) | ||
}) | ||
}).connect( options ) | ||
}).connect( options ) | ||
``` | ||
@@ -52,7 +58,9 @@ Really. That's it. | ||
{ user: String | ||
, source: String | ||
, match_data: Array | ||
, say: Function( message ) | ||
} | ||
```javascript | ||
{ user: String | ||
, source: String | ||
, match_data: Array | ||
, say: Function( message ) | ||
} | ||
``` | ||
@@ -63,16 +71,20 @@ One thing I will tell you though, is the `say` method is smart enough to reply to the context that the message was received, so you don't need to pass it any extra info, just a reply :) | ||
{ say: Function( destination, message ) | ||
, action: Function( destination, action ) | ||
, part: Function( channel ) | ||
, join: Function( channel ) | ||
, quit: Function( message ) | ||
} | ||
```javascript | ||
{ say: Function( destination, message ) | ||
, action: Function( destination, action ) | ||
, part: Function( channel ) | ||
, join: Function( channel ) | ||
, quit: Function( message ) | ||
} | ||
``` | ||
Example: | ||
var superBot = jerk( ... ).connect( options ) | ||
// Later... | ||
superBot.say( '#myChan', 'Soup noobs?' ) | ||
superBot.join( '#haters' ) | ||
superBot.action( '#hates', 'hates all of you!' ) | ||
```javascript | ||
var superBot = jerk( ... ).connect( options ) | ||
// Later... | ||
superBot.say( '#myChan', 'Soup noobs?' ) | ||
superBot.join( '#haters' ) | ||
superBot.action( '#hates', 'hates all of you!' ) | ||
``` | ||
@@ -79,0 +91,0 @@ I think everything there is pretty self-explanatory, no? |
672637
19042
121