Skip to content

Commit

Permalink
Just talkin' bout changin'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuakfarrar committed Jun 25, 2012
1 parent b1899c2 commit 33524a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.js
Expand Up @@ -23,7 +23,11 @@ function zIRCClient(stream, options) {

this.on("say", function (message) {
this.send_command("PRIVMSG %s :%s", [ this.options.chan, message]);
//this.send_command("PRIVMSG " + this.options.chan + " :" + message);
});

this.on("quit", function (message) {
this.send_command("QUIT :%s", [ message ]);
process.exit();
});

this.stream.on("connect", function() {
Expand Down Expand Up @@ -111,14 +115,18 @@ zIRCClient.prototype.send_command = function (command, args) {
return false;
}

var vsprintf = function (string, args) {
var vsprintf = function (string, args, newline) {
args.forEach(function(arg) {
string = util.format(string, arg);
});
if (newline) {
string += "\r\n";
}
return string;
}

this.commands_sent += !stream.write(vsprintf(command, args) + "\r\n");
console.log(vsprintf(command, args));
this.commands_sent += !stream.write(vsprintf(command, args, true));
return true;
};

Expand Down
21 changes: 21 additions & 0 deletions tests/test_connect.js
Expand Up @@ -13,6 +13,27 @@ zirc_client.on("ready", function() {
process.stdin.setEncoding("utf8");

process.stdin.on("data", function(text) {
if (text.match(/^\//g)) {
var command = "";
// Slash commands for client
text = text.trim();
if (text.indexOf(" ") > 1) {
command = text.toString().substring(1, text.indexOf(" "));
}
else {
command = text.toString().substring(1);
}
switch (command) {
case "quit":
var message = text.substring(text.indexOf(" ") + 1);
zirc_client.emit("quit", message);
break;
default:
console.log("That command doesn't exist!");
break;
}
return true;
}
zirc_client.emit("say", text);
});
});
Expand Down

0 comments on commit 33524a6

Please sign in to comment.