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

40 lines
899 B
JavaScript
Raw Normal View History

"use strict";
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
});
2017-04-01 08:33:17 +00:00
// Request channels' modes
network.irc.raw("MODE", chan.name);
2014-09-13 21:29:45 +00:00
}
chan.users.push(new User({nick: data.nick}));
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.pushMessage(client, msg);
2014-09-13 21:29:45 +00:00
});
};