hardlounge/lib/plugins/inputs/msg.js

42 lines
753 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
}
2014-07-06 15:22:43 +00:00
if (args.length === 0 || args[0] === "") {
2014-07-02 22:00:11 +00:00
return;
}
2014-08-02 12:08:26 +00:00
var client = this;
var irc = network.irc;
2014-07-02 22:00:11 +00:00
2014-08-02 12:08:26 +00:00
var target = "";
if (cmd == "msg") {
target = args.shift();
if (args.length === 0) {
return;
}
} else {
target = chan.name;
2014-07-02 22:00:11 +00:00
}
var text = args.join(" ");
irc.send(target, text);
2014-08-02 12:08:26 +00:00
if (target == chan.name && typeof chan !== "undefined") {
2014-07-02 22:00:11 +00:00
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
};