2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-05-13 07:07:45 +00:00
|
|
|
const Chan = require("../../models/chan");
|
|
|
|
const Msg = require("../../models/msg");
|
|
|
|
|
|
|
|
exports.commands = ["query", "msg", "say"];
|
|
|
|
|
|
|
|
function getTarget(cmd, args, chan) {
|
|
|
|
switch (cmd) {
|
|
|
|
case "msg":
|
|
|
|
case "query":
|
|
|
|
return args.shift();
|
|
|
|
default:
|
|
|
|
return chan.name;
|
|
|
|
}
|
|
|
|
}
|
2016-03-14 04:21:42 +00:00
|
|
|
|
|
|
|
exports.input = function(network, chan, cmd, args) {
|
2019-05-13 07:07:45 +00:00
|
|
|
const targetName = getTarget(cmd, args, chan);
|
|
|
|
|
|
|
|
if (cmd === "query") {
|
|
|
|
if (!targetName) {
|
|
|
|
chan.pushMessage(this, new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "You cannot open a query window without an argument.",
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const target = network.getChannel(targetName);
|
|
|
|
|
|
|
|
if (typeof target === "undefined") {
|
|
|
|
const char = targetName[0];
|
|
|
|
|
|
|
|
if (network.irc.network.options.CHANTYPES && network.irc.network.options.CHANTYPES.includes(char)) {
|
|
|
|
chan.pushMessage(this, new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "You can not open query windows for channels, use /join instead.",
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < network.irc.network.options.PREFIX.length; i++) {
|
|
|
|
if (network.irc.network.options.PREFIX[i].symbol === char) {
|
|
|
|
chan.pushMessage(this, new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
|
|
|
text: "You can not open query windows for names starting with a user prefix.",
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const newChan = this.createChannel({
|
|
|
|
type: Chan.Type.QUERY,
|
|
|
|
name: targetName,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.emit("join", {
|
|
|
|
network: network.uuid,
|
|
|
|
chan: newChan.getFilteredClone(true),
|
|
|
|
shouldOpen: true,
|
|
|
|
index: network.addChannel(newChan),
|
|
|
|
});
|
|
|
|
this.save();
|
|
|
|
newChan.loadMessages(this, network);
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 01:19:09 +00:00
|
|
|
|
2019-05-13 07:07:45 +00:00
|
|
|
if (args.length === 0 || !targetName) {
|
2016-05-11 01:19:09 +00:00
|
|
|
return true;
|
2014-09-13 21:29:45 +00:00
|
|
|
}
|
2016-03-08 13:36:25 +00:00
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const msg = args.join(" ");
|
2016-05-25 07:23:03 +00:00
|
|
|
|
|
|
|
if (msg.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-13 07:07:45 +00:00
|
|
|
network.irc.say(targetName, msg);
|
2016-03-08 13:36:25 +00:00
|
|
|
|
2016-04-22 16:38:13 +00:00
|
|
|
if (!network.irc.network.cap.isEnabled("echo-message")) {
|
2019-05-13 07:07:45 +00:00
|
|
|
const channel = network.getChannel(targetName);
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2016-04-22 16:38:13 +00:00
|
|
|
if (typeof channel !== "undefined") {
|
2018-01-11 11:33:36 +00:00
|
|
|
network.irc.emit("privmsg", {
|
|
|
|
nick: network.irc.user.nick,
|
2018-09-22 10:27:03 +00:00
|
|
|
ident: network.irc.user.username,
|
|
|
|
hostname: network.irc.user.host,
|
2016-04-22 16:38:13 +00:00
|
|
|
target: channel.name,
|
2017-11-15 06:35:15 +00:00
|
|
|
message: msg,
|
2016-04-22 16:38:13 +00:00
|
|
|
});
|
|
|
|
}
|
2014-09-13 21:29:45 +00:00
|
|
|
}
|
2016-03-06 09:24:56 +00:00
|
|
|
|
|
|
|
return true;
|
2014-09-13 21:29:45 +00:00
|
|
|
};
|