2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-10 20:44:14 +00:00
|
|
|
const Chan = require("../../models/chan");
|
|
|
|
const Msg = require("../../models/msg");
|
|
|
|
const User = require("../../models/user");
|
2014-09-13 21:29:45 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
module.exports = function (irc, network) {
|
2017-11-10 20:44:14 +00:00
|
|
|
const client = this;
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
irc.on("join", function (data) {
|
2017-11-10 20:44:14 +00:00
|
|
|
let chan = network.getChannel(data.channel);
|
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
if (typeof chan === "undefined") {
|
2018-04-27 10:16:23 +00:00
|
|
|
chan = client.createChannel({
|
2017-11-15 06:35:15 +00:00
|
|
|
name: data.channel,
|
2018-02-13 10:30:26 +00:00
|
|
|
state: Chan.State.JOINED,
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
client.emit("join", {
|
2018-04-26 09:06:01 +00:00
|
|
|
network: network.uuid,
|
2017-12-03 14:29:50 +00:00
|
|
|
chan: chan.getFilteredClone(true),
|
2018-03-12 12:42:59 +00:00
|
|
|
index: network.addChannel(chan),
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
2018-03-12 12:42:59 +00:00
|
|
|
client.save();
|
2017-04-01 08:33:17 +00:00
|
|
|
|
2017-11-28 17:56:53 +00:00
|
|
|
chan.loadMessages(client, network);
|
|
|
|
|
2017-04-01 08:33:17 +00:00
|
|
|
// Request channels' modes
|
|
|
|
network.irc.raw("MODE", chan.name);
|
2018-03-02 10:29:40 +00:00
|
|
|
} else if (data.nick === irc.user.nick) {
|
|
|
|
chan.state = Chan.State.JOINED;
|
2018-07-19 18:03:53 +00:00
|
|
|
|
|
|
|
client.emit("channel:state", {
|
|
|
|
chan: chan.id,
|
|
|
|
state: chan.state,
|
|
|
|
});
|
2014-09-13 21:29:45 +00:00
|
|
|
}
|
2017-11-10 20:44:14 +00:00
|
|
|
|
|
|
|
const user = new User({nick: data.nick});
|
|
|
|
const msg = new Msg({
|
2016-03-12 09:36:55 +00:00
|
|
|
time: data.time,
|
2017-11-10 20:44:14 +00:00
|
|
|
from: user,
|
2016-03-07 21:09:42 +00:00
|
|
|
hostmask: data.ident + "@" + data.hostname,
|
2014-09-14 17:06:56 +00:00
|
|
|
type: Msg.Type.JOIN,
|
2017-11-15 06:35:15 +00:00
|
|
|
self: data.nick === irc.user.nick,
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
2016-04-19 10:20:18 +00:00
|
|
|
chan.pushMessage(client, msg);
|
2017-11-10 20:44:14 +00:00
|
|
|
|
2017-11-16 20:32:03 +00:00
|
|
|
chan.setUser(new User({nick: data.nick}));
|
2017-11-10 20:44:14 +00:00
|
|
|
client.emit("users", {
|
|
|
|
chan: chan.id,
|
|
|
|
});
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
|
|
|
};
|