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
|
|
|
|
});
|
|
|
|
}
|
2016-02-14 09:50:48 +00:00
|
|
|
chan.users.push(new User({name: data.nick}));
|
2014-09-13 21:29:45 +00:00
|
|
|
chan.sortUsers();
|
|
|
|
client.emit("users", {
|
|
|
|
chan: chan.id,
|
2016-02-14 09:50:48 +00:00
|
|
|
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,
|
2014-09-14 17:06:56 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|