hardlounge/lib/plugins/inputs/msg.js

39 lines
744 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;
2014-07-02 22:00:11 +00:00
}
var client = this;
var irc = network.irc;
2014-07-06 15:22:43 +00:00
if (args.length === 0 || args[0] === "") {
2014-07-02 22:00:11 +00:00
return;
}
var target = args[0].charAt(0) == "#" ? args[0] : chan.name;
2014-07-02 22:00:11 +00:00
if (target !== chan.name) {
chan = _.findWhere(network.channels, {
2014-07-02 22:00:11 +00:00
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
};