2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const _ = require("lodash");
|
|
|
|
const Chan = require("../../models/chan");
|
|
|
|
const Msg = require("../../models/msg");
|
2016-03-24 20:40:36 +00:00
|
|
|
|
|
|
|
exports.commands = ["query"];
|
|
|
|
|
|
|
|
exports.input = function(network, chan, cmd, args) {
|
2018-01-11 11:33:36 +00:00
|
|
|
const target = args[0];
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-10-31 19:46:58 +00:00
|
|
|
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.",
|
|
|
|
}));
|
2016-03-24 20:40:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const query = _.find(network.channels, {name: target});
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2016-03-24 20:40:36 +00:00
|
|
|
if (typeof query !== "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const char = target[0];
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-11-22 06:39:32 +00:00
|
|
|
if (network.irc.network.options.CHANTYPES && network.irc.network.options.CHANTYPES.includes(char)) {
|
2016-04-19 10:20:18 +00:00
|
|
|
chan.pushMessage(this, new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "You can not open query windows for channels, use /join instead.",
|
2016-04-19 10:20:18 +00:00
|
|
|
}));
|
2016-03-26 17:18:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
for (let i = 0; i < network.irc.network.options.PREFIX.length; i++) {
|
2016-03-26 20:03:31 +00:00
|
|
|
if (network.irc.network.options.PREFIX[i].symbol === char) {
|
2016-04-19 10:20:18 +00:00
|
|
|
chan.pushMessage(this, new Msg({
|
|
|
|
type: Msg.Type.ERROR,
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "You can not open query windows for names starting with a user prefix.",
|
2016-04-19 10:20:18 +00:00
|
|
|
}));
|
2016-03-26 20:03:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const newChan = new Chan({
|
2016-03-24 20:40:36 +00:00
|
|
|
type: Chan.Type.QUERY,
|
2017-11-15 06:35:15 +00:00
|
|
|
name: target,
|
2016-03-24 20:40:36 +00:00
|
|
|
});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
2016-03-24 20:40:36 +00:00
|
|
|
this.emit("join", {
|
|
|
|
network: network.id,
|
2017-12-03 14:29:50 +00:00
|
|
|
chan: newChan.getFilteredClone(true),
|
2017-11-01 09:16:19 +00:00
|
|
|
shouldOpen: true,
|
2018-03-12 12:42:59 +00:00
|
|
|
index: network.addChannel(newChan),
|
2016-03-24 20:40:36 +00:00
|
|
|
});
|
2018-01-30 16:46:34 +00:00
|
|
|
this.save();
|
2017-11-28 17:56:53 +00:00
|
|
|
newChan.loadMessages(this, network);
|
2016-03-24 20:40:36 +00:00
|
|
|
};
|