Skip to content

Instantly share code, notes, and snippets.

@Snack-X
Created February 12, 2014 09:25
Show Gist options
  • Save Snack-X/8952363 to your computer and use it in GitHub Desktop.
Save Snack-X/8952363 to your computer and use it in GitHub Desktop.
var util = require("util");
var net = require("net");
var exec = require("child_process").exec;
String.prototype.startsWith = function(prefix) {
return this.indexOf(prefix) === 0;
}
// loadbot config
var _server = "yourserver";
var _nick = "loadbot";
var _chan = "#yourchannel";
var _irc_server = "irc.ozinger.org";
var _irc_port = "6667";
// loadbot config
irc_con = net.connect(_irc_port, _irc_server);
irc_con.on("data", function(data) { proc(data, this); }).on("error", function(e) { console.log(e.code); });
irc_con.write("NICK "+_nick+"\r\n");
irc_con.write("USER loadbotjs 8 * :loadavg bot - "+_server+"\r\n");
function proc(buf, con) {
arr = buf.toString().split("\r\n");
for(i in arr) {
data = arr[i];
msg = data.split(" ");
if(msg[0] == "PING") {
res = data.match(/^PING :(.*)/);
con.write("PONG "+res[1]+"\r\n");
}
else if(msg[1] == "001") {
con.write("JOIN "+_chan+"\r\n");
}
else if(msg[1] == "INVITE") {
res = data.match(/^:(.*) INVITE (.*) :(.*)/);
con.write("JOIN "+res[3]+"\r\n");
}
else if(msg[1] == "PRIVMSG") {
res = data.match(/^:(.*) PRIVMSG (.*) :(.*)/);
who = res[1]
chan = res[2];
msg = res[3];
if(msg == "!로드" || msg == "!loadavg" || msg.startsWith(_nick)) {
exec("uptime", function(err, stdout, stderr) {
con.write("PRIVMSG "+chan+" :"+_server+" |"+stdout.replace("\n","")+"\r\n");
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment