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

41 lines
783 B
JavaScript
Raw Normal View History

2014-09-13 21:29:45 +00:00
var _ = require("lodash");
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
2016-03-09 08:27:01 +00:00
irc.on("whois", function(data) {
var chan = _.find(network.channels, {name: data.nick});
2014-09-13 21:29:45 +00:00
if (typeof chan === "undefined") {
chan = new Chan({
type: Chan.Type.QUERY,
2016-03-09 08:27:01 +00:00
name: data.nick
2014-09-13 21:29:45 +00:00
});
network.channels.push(chan);
client.emit("join", {
network: network.id,
chan: chan
});
}
2016-03-09 08:27:01 +00:00
var msg;
if (data.error) {
msg = new Msg({
type: Msg.Type.ERROR,
text: "No such nick: " + data.nick
});
} else {
msg = new Msg({
type: Msg.Type.WHOIS,
whois: data
});
}
2016-03-07 15:10:46 +00:00
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
2014-09-13 21:29:45 +00:00
});
};