hardlounge/lib/plugins/mode.js

32 lines
754 B
JavaScript
Raw Normal View History

2014-06-19 15:28:53 +00:00
var _ = require("lodash");
var Chan = require("../models/chan");
var Msg = require("../models/msg");
2014-06-23 17:28:36 +00:00
module.exports = function(slate, network) {
var client = this;
2014-06-19 15:28:53 +00:00
var timer = null;
2014-06-23 17:28:36 +00:00
slate.on("mode", function(data) {
2014-06-19 15:28:53 +00:00
var chan = _.findWhere(network.channels, {name: data.target});
if (typeof chan !== "undefined") {
clearTimeout(timer);
timer = setTimeout(function() {
2014-06-23 17:28:36 +00:00
slate.write("NAMES " + data.target);
2014-06-19 15:28:53 +00:00
}, 200);
var nick = data.nick;
if (nick.indexOf(".") !== -1) {
nick = data.target;
}
var msg = new Msg({
type: "mode",
from: nick,
text: data.mode + " " + data.client,
});
chan.addMsg(msg);
2014-06-23 17:28:36 +00:00
client.emit("msg", {
2014-06-19 15:28:53 +00:00
id: chan.id,
msg: msg,
});
}
});
};