thelounge/lib/plugins/whois.js

58 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-06-19 15:28:53 +00:00
var _ = require("lodash");
var Chan = require("../models/chan");
var Msg = require("../models/msg");
2014-06-23 17:28:36 +00:00
module.exports = function(slate, network) {
var client = this;
slate.on("whois", function(err, data) {
2014-06-19 15:28:53 +00:00
if (!data) {
return;
}
var chan = _.findWhere(network.channels, {name: data.nickname});
if (typeof chan === "undefined") {
chan = new Chan({
type: "query",
name: data.nickname,
});
network.addChan(chan);
2014-06-23 17:28:36 +00:00
client.emit("join", {
2014-06-19 15:28:53 +00:00
id: network.id,
chan: chan,
});
}
var prefix = {
hostname: "from",
realname: "is",
channels: "on",
server: "using",
};
var i = 0;
for (var k in data) {
var key = prefix[k];
if (!key || data[k].toString() == "") {
continue;
}
var msg = new Msg({
type: "whois",
from: data.nickname,
text: key + " " + data[k],
});
chan.addMsg(msg);
2014-06-23 17:28:36 +00:00
client.emit("msg", {
2014-06-19 15:28:53 +00:00
id: chan.id,
msg: msg,
});
}
var msg = new Msg({
type: "whois",
from: data.nickname,
text: "End of /WHOIS list.",
});
chan.addMsg(msg);
2014-06-23 17:28:36 +00:00
client.emit("msg", {
2014-06-19 15:28:53 +00:00
id: chan.id,
msg: msg,
});
});
};