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

39 lines
878 B
JavaScript
Raw Normal View History

2014-09-13 23:29:45 +02:00
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) {
2016-03-20 15:28:47 +01:00
var chan = network.getChannel(data.channel);
2014-09-13 23:29:45 +02:00
if (typeof chan === "undefined") {
chan = new Chan({
name: data.channel
});
network.channels.push(chan);
2014-10-12 01:59:01 +02:00
client.save();
2014-09-13 23:29:45 +02:00
client.emit("join", {
network: network.id,
chan: chan
});
}
chan.users.push(new User({nick: data.nick, modes: ""}));
chan.sortUsers(irc);
2014-09-13 23:29:45 +02:00
client.emit("users", {
chan: chan.id
2014-09-13 23:29:45 +02:00
});
var msg = new Msg({
2016-03-12 10:36:55 +01:00
time: data.time,
2014-09-13 23:29:45 +02:00
from: data.nick,
hostmask: data.ident + "@" + data.hostname,
type: Msg.Type.JOIN,
self: data.nick === irc.user.nick
2014-09-13 23:29:45 +02:00
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};