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

43 lines
935 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");
var User = require("../../models/user");
module.exports = function(irc, network) {
var client = this;
irc.on("join", function(data) {
var chan = _.find(network.channels, {name: data.channel});
if (typeof chan === "undefined") {
chan = new Chan({
name: data.channel
});
network.channels.push(chan);
2014-10-11 23:59:01 +00:00
client.save();
2014-09-13 21:29:45 +00:00
client.emit("join", {
network: network.id,
chan: chan
});
}
chan.users.push(new User({name: data.nick}));
2014-09-13 21:29:45 +00:00
chan.sortUsers();
client.emit("users", {
chan: chan.id,
users: chan.users
2014-09-13 21:29:45 +00:00
});
2014-09-14 18:49:42 +00:00
var self = false;
2015-09-30 22:39:57 +00:00
if (data.nick.toLowerCase() === irc.me.toLowerCase()) {
2014-09-14 18:49:42 +00:00
self = true;
}
2014-09-13 21:29:45 +00:00
var msg = new Msg({
from: data.nick,
type: Msg.Type.JOIN,
2014-09-14 18:49:42 +00:00
self: self
2014-09-13 21:29:45 +00:00
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};