Permalink
Browse files

Just talkin' bout changin'

  • Loading branch information...
1 parent b1899c2 commit 33524a6162dea2f3f839ddfea41c180640fa5d35 @sent1nel committed Jun 25, 2012
Showing with 32 additions and 3 deletions.
  1. +11 −3 index.js
  2. +21 −0 tests/test_connect.js
View
@@ -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() {
@@ -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;
};
View
@@ -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);
});
});

0 comments on commit 33524a6

Please sign in to comment.