Handle channel and user modes
This commit is contained in:
parent
e380319400
commit
360563528a
@ -1,28 +1,38 @@
|
||||
var _ = require("lodash");
|
||||
var Chan = require("../../models/chan");
|
||||
var Msg = require("../../models/msg");
|
||||
|
||||
module.exports = function(irc, network) {
|
||||
var client = this;
|
||||
irc.on("mode", function(data) {
|
||||
var chan = _.find(network.channels, {name: data.target});
|
||||
if (typeof chan !== "undefined") {
|
||||
setTimeout(function() {
|
||||
irc.write("NAMES " + data.target);
|
||||
}, 200);
|
||||
var from = data.nick;
|
||||
if (from.indexOf(".") !== -1) {
|
||||
from = data.target;
|
||||
var targetChan;
|
||||
|
||||
if (data.target === irc.user.nick) {
|
||||
targetChan = network.channels[0];
|
||||
} else {
|
||||
targetChan = _.find(network.channels, {name: data.target});
|
||||
if (typeof targetChan === "undefined") {
|
||||
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({
|
||||
type: Msg.Type.MODE,
|
||||
mode: chan.getMode(from),
|
||||
from: from,
|
||||
text: data.mode + " " + (data.client || ""),
|
||||
self: from === irc.user.nick
|
||||
mode: (targetChan.type !== Chan.Type.LOBBY && targetChan.getMode(data.nick)) || "",
|
||||
from: data.nick,
|
||||
text: text,
|
||||
self: data.nick === irc.user.nick
|
||||
});
|
||||
chan.messages.push(msg);
|
||||
targetChan.messages.push(msg);
|
||||
client.emit("msg", {
|
||||
chan: chan.id,
|
||||
chan: targetChan.id,
|
||||
msg: msg,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user