Merge pull request #3138 from Dominent/send-message-after-query

Move query to msg, fix #3049
This commit is contained in:
Pavel Djundik 2019-05-13 10:22:52 +03:00 committed by GitHub
commit 0eddb9153d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 65 deletions

View File

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

View File

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