thelounge/lib/plugins/inputs/msg.js

39 lines
737 B
JavaScript
Raw Normal View History

2014-07-02 22:00:11 +00:00
var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(network, chan, cmd, args) {
if (cmd != "say" && cmd != "msg") {
return
}
var client = this;
var irc = network.irc;
if (args.length === 0) {
return;
}
var target = args[0].charAt(0) == "#" ? args[0] : "#" + chan.name;
if (target !== chan.name) {
targetChan = _.findWhere(network.channels, {
name: target
});
}
var text = args.join(" ");
irc.send(target, text);
if (typeof chan !== "undefined") {
var msg = new Msg({
type: Msg.Type.MESSAGE,
from: irc.me,
text: text
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
}
2014-06-26 23:05:47 +00:00
};