Handle channel and user modes

This commit is contained in:
Pavel Djundik 2016-03-08 11:42:38 +02:00 committed by Maxime Poulin
parent e380319400
commit 360563528a

View File

@ -1,28 +1,38 @@
var _ = require("lodash"); var _ = require("lodash");
var Chan = require("../../models/chan");
var Msg = require("../../models/msg"); var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
irc.on("mode", function(data) { irc.on("mode", function(data) {
var chan = _.find(network.channels, {name: data.target}); var targetChan;
if (typeof chan !== "undefined") {
setTimeout(function() { if (data.target === irc.user.nick) {
irc.write("NAMES " + data.target); targetChan = network.channels[0];
}, 200); } else {
var from = data.nick; targetChan = _.find(network.channels, {name: data.target});
if (from.indexOf(".") !== -1) { if (typeof targetChan === "undefined") {
from = data.target; return;
} }
}
for (var i = 0; i < data.modes.length; i++) {
var mode = data.modes[i];
var text = mode.mode;
if (mode.param) {
text += " " + mode.param;
}
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.MODE, type: Msg.Type.MODE,
mode: chan.getMode(from), mode: (targetChan.type !== Chan.Type.LOBBY && targetChan.getMode(data.nick)) || "",
from: from, from: data.nick,
text: data.mode + " " + (data.client || ""), text: text,
self: from === irc.user.nick self: data.nick === irc.user.nick
}); });
chan.messages.push(msg); targetChan.messages.push(msg);
client.emit("msg", { client.emit("msg", {
chan: chan.id, chan: targetChan.id,
msg: msg, msg: msg,
}); });
} }