hardlounge/lib/plugins/irc-events/whois.js

48 lines
1010 B
JavaScript
Raw Normal View History

2014-06-29 19:41:02 +00:00
var _ = require("lodash");
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("whois", function(data) {
if (!data) {
return;
}
var chan = _.findWhere(network.channels, {name: data.nickname});
if (typeof chan === "undefined") {
chan = new Chan({
type: Chan.Type.QUERY,
name: data.nickname
});
network.channels.push(chan);
client.emit("join", {
network: 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];
2014-06-30 01:20:54 +00:00
if (!key || data[k].toString() === "") {
2014-06-29 19:41:02 +00:00
continue;
}
var msg = new Msg({
type: Msg.Type.WHOIS,
from: data.nickname,
text: key + " " + data[k]
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
}
});
2014-06-26 23:05:47 +00:00
};