Move query to msg, fix #3049

This commit is contained in:
Alistair McKinlay 2019-05-13 08:07:45 +01:00
parent ff8b706cc6
commit 4c35b80b88
3 changed files with 66 additions and 65 deletions

View File

@ -57,7 +57,6 @@ const inputs = [
"mode",
"nick",
"notice",
"query",
"quit",
"raw",
"topic",

View File

@ -1,11 +1,72 @@
"use strict";
exports.commands = ["msg", "say"];
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;
}
}
exports.input = function(network, chan, cmd, args) {
const target = cmd === "msg" ? args.shift() : chan.name;
const targetName = getTarget(cmd, args, chan);
if (args.length === 0 || !target) {
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);
}
}
if (args.length === 0 || !targetName) {
return true;
}
@ -15,10 +76,10 @@ exports.input = function(network, chan, cmd, args) {
return true;
}
network.irc.say(target, msg);
network.irc.say(targetName, msg);
if (!network.irc.network.cap.isEnabled("echo-message")) {
const channel = network.getChannel(target);
const channel = network.getChannel(targetName);
if (typeof channel !== "undefined") {
network.irc.emit("privmsg", {

View File

@ -1,59 +0,0 @@
"use strict";
const _ = require("lodash");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
exports.commands = ["query"];
exports.input = function(network, chan, cmd, args) {
const target = args[0];
if (args.length === 0 || target.length === 0) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "You cannot open a query window without an argument.",
}));
return;
}
const query = _.find(network.channels, {name: target});
if (typeof query !== "undefined") {
return;
}
const char = target[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: target,
});
this.emit("join", {
network: network.uuid,
chan: newChan.getFilteredClone(true),
shouldOpen: true,
index: network.addChannel(newChan),
});
this.save();
newChan.loadMessages(this, network);
};