diff --git a/src/client.js b/src/client.js index d29f22d6..f794b3b2 100644 --- a/src/client.js +++ b/src/client.js @@ -57,7 +57,6 @@ const inputs = [ "mode", "nick", "notice", - "query", "quit", "raw", "topic", diff --git a/src/plugins/inputs/msg.js b/src/plugins/inputs/msg.js index 94a6450d..7e61f0a5 100644 --- a/src/plugins/inputs/msg.js +++ b/src/plugins/inputs/msg.js @@ -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", { diff --git a/src/plugins/inputs/query.js b/src/plugins/inputs/query.js deleted file mode 100644 index a3eda2fe..00000000 --- a/src/plugins/inputs/query.js +++ /dev/null @@ -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); -};