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

41 lines
931 B
JavaScript
Raw Normal View History

2014-09-13 21:29:45 +00:00
var _ = require("lodash");
2016-03-08 09:42:38 +00:00
var Chan = require("../../models/chan");
2014-09-13 21:29:45 +00:00
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("mode", function(data) {
2016-03-08 09:42:38 +00:00
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;
2014-09-13 21:29:45 +00:00
}
2016-03-08 09:42:38 +00:00
}
for (var i = 0; i < data.modes.length; i++) {
var mode = data.modes[i];
var text = mode.mode;
if (mode.param) {
text += " " + mode.param;
}
2014-09-13 21:29:45 +00:00
var msg = new Msg({
type: Msg.Type.MODE,
2016-03-08 09:42:38 +00:00
mode: (targetChan.type !== Chan.Type.LOBBY && targetChan.getMode(data.nick)) || "",
from: data.nick,
text: text,
self: data.nick === irc.user.nick
2014-09-13 21:29:45 +00:00
});
2016-03-08 09:42:38 +00:00
targetChan.messages.push(msg);
2014-09-13 21:29:45 +00:00
client.emit("msg", {
2016-03-08 09:42:38 +00:00
chan: targetChan.id,
2014-09-13 21:29:45 +00:00
msg: msg,
});
}
});
};