Skip to content
Browse files

Added join/part/say functions and associated examples/docs

  • Loading branch information...
1 parent 3903860 commit 16c4dc0b66a0362ea5a3c78198d38dec4ed46c34 @martynsmith committed May 15, 2010
Showing with 50 additions and 5 deletions.
  1. +20 −0 API.md
  2. +5 −5 example/bot.js
  3. +25 −0 lib/irc.js
View
20 API.md
@@ -133,3 +133,23 @@ parameter is exactly as in the 'raw' event.
Sends a raw message to the server, generally speaking it's best not to use this
method unless you know what you're doing, instead use one of the methods below.
+
+### Client.join(channel, callback)
+
+Joins the specified channel.
+
+`callback` is automatically subscribed to the `join#channel` event, but removed
+after the first invocation.
+
+### Client.part(channel, callback)
+
+Parts the specified channel.
+
+callback is automatically subscribed to the `part#channel` event, but removed
+after the first invocation.
+
+### Client.say(target, message)
+
+Sends a message to the specified target.
+
+`target` is either a nickname, or a channel.
View
10 example/bot.js
@@ -25,13 +25,13 @@ bot.addListener('message', function (from, to, message) {
if ( to.match(/^[#&]/) ) {
// channel message
if ( message.match(/hello/i) ) {
- bot.send('PRIVMSG', to, 'Hello there');
+ bot.say(to, 'Hello there ' + from);
}
if ( message.match(/dance/) ) {
- setTimeout(function () { bot.send("PRIVMSG", to, "\u0001ACTION dances: :D\\-<\u0001") }, 1000);
- setTimeout(function () { bot.send("PRIVMSG", to, "\u0001ACTION dances: :D|-<\u0001") }, 2000);
- setTimeout(function () { bot.send("PRIVMSG", to, "\u0001ACTION dances: :D/-<\u0001") }, 3000);
- setTimeout(function () { bot.send("PRIVMSG", to, "\u0001ACTION dances: :D|-<\u0001") }, 4000);
+ setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D\\-<\u0001") }, 1000);
+ setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D|-<\u0001") }, 2000);
+ setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D/-<\u0001") }, 3000);
+ setTimeout(function () { bot.say(to, "\u0001ACTION dances: :D|-<\u0001") }, 4000);
}
}
else {
View
25 lib/irc.js
@@ -741,6 +741,31 @@ Client.prototype.send = function(command) { // {{{
this.conn.write(command + " " + args.join(" ") + "\r\n");
}; // }}}
+Client.prototype.join = function(channel, callback) { // {{{
+ if ( typeof(callback) == 'function' ) {
+ var callbackWrapper = function () {
+ this.removeListener('join' + channel, callbackWrapper);
+ return callback.apply(this, arguments);
+ };
+ this.addListener('join' + channel, callbackWrapper);
+ }
+
+ this.send('JOIN', channel);
+} // }}}
+Client.prototype.part = function(channel, callback) { // {{{
+ if ( typeof(callback) == 'function' ) {
+ var callbackWrapper = function () {
+ this.removeListener('part' + channel, callbackWrapper);
+ return callback.apply(this, arguments);
+ };
+ this.addListener('part' + channel, callbackWrapper);
+ }
+
+ this.send('PART', channel);
+} // }}}
+Client.prototype.say = function(target, text) { // {{{
+ this.send('PRIVMSG', target, text);
+} // }}}
/*
* parseMessage(line)

0 comments on commit 16c4dc0

Please sign in to comment.
Something went wrong with that request. Please try again.