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

39 lines
878 B
JavaScript
Raw Normal View History

2014-09-13 21:29:45 +00: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 14:28:47 +00:00
var chan = network.getChannel(data.channel);
2014-09-13 21:29:45 +00:00
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({nick: data.nick, modes: ""}));
chan.sortUsers(irc);
2014-09-13 21:29:45 +00:00
client.emit("users", {
chan: chan.id
2014-09-13 21:29:45 +00:00
});
var msg = new Msg({
2016-03-12 09:36:55 +00:00
time: data.time,
2014-09-13 21:29:45 +00:00
from: data.nick,
hostmask: data.ident + "@" + data.hostname,
type: Msg.Type.JOIN,
self: data.nick === irc.user.nick
2014-09-13 21:29:45 +00:00
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};