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

50 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
const User = require("../../models/user");
2014-09-13 21:29:45 +00:00
module.exports = function(irc, network) {
const client = this;
2014-09-13 21:29:45 +00:00
irc.on("join", function(data) {
let chan = network.getChannel(data.channel);
2014-09-13 21:29:45 +00:00
if (typeof chan === "undefined") {
chan = new Chan({
name: data.channel,
state: Chan.State.JOINED,
2014-09-13 21:29:45 +00:00
});
2014-09-13 21:29:45 +00:00
client.emit("join", {
network: network.id,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
2014-09-13 21:29:45 +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);
} else if (data.nick === irc.user.nick) {
chan.state = Chan.State.JOINED;
2014-09-13 21:29:45 +00:00
}
const user = new User({nick: data.nick});
const msg = new Msg({
2016-03-12 09:36:55 +00:00
time: data.time,
from: user,
hostmask: data.ident + "@" + data.hostname,
type: Msg.Type.JOIN,
self: data.nick === irc.user.nick,
2014-09-13 21:29:45 +00:00
});
chan.pushMessage(client, msg);
2017-11-16 20:32:03 +00:00
chan.setUser(new User({nick: data.nick}));
client.emit("users", {
chan: chan.id,
});
2014-09-13 21:29:45 +00:00
});
};