2022-06-18 20:25:21 -04:00
|
|
|
import {PluginInputHandler} from "./index";
|
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
|
|
|
import Chan, {ChanType} from "../../models/chan";
|
2016-10-09 15:14:02 -04:00
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
const commands = ["query", "msg", "say"];
|
2019-05-13 03:07:45 -04:00
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
function getTarget(cmd: string, args: string[], chan: Chan) {
|
2019-05-13 03:07:45 -04:00
|
|
|
switch (cmd) {
|
2019-07-17 05:33:59 -04:00
|
|
|
case "msg":
|
|
|
|
case "query":
|
|
|
|
return args.shift();
|
|
|
|
default:
|
|
|
|
return chan.name;
|
2019-05-13 03:07:45 -04:00
|
|
|
}
|
|
|
|
}
|
2016-03-14 00:21:42 -04:00
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
2019-07-31 17:16:00 -04:00
|
|
|
let targetName = getTarget(cmd, args, chan);
|
2019-05-13 03:07:45 -04:00
|
|
|
|
|
|
|
if (cmd === "query") {
|
|
|
|
if (!targetName) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-18 20:25:21 -04:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 05:33:59 -04:00
|
|
|
text: "You cannot open a query window without an argument.",
|
|
|
|
})
|
|
|
|
);
|
2019-05-13 03:07:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const target = network.getChannel(targetName);
|
|
|
|
|
|
|
|
if (typeof target === "undefined") {
|
|
|
|
const char = targetName[0];
|
|
|
|
|
2019-07-17 05:33:59 -04:00
|
|
|
if (
|
|
|
|
network.irc.network.options.CHANTYPES &&
|
|
|
|
network.irc.network.options.CHANTYPES.includes(char)
|
|
|
|
) {
|
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-18 20:25:21 -04:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 05:33:59 -04:00
|
|
|
text: "You can not open query windows for channels, use /join instead.",
|
|
|
|
})
|
|
|
|
);
|
2019-05-13 03:07:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < network.irc.network.options.PREFIX.length; i++) {
|
|
|
|
if (network.irc.network.options.PREFIX[i].symbol === char) {
|
2019-07-17 05:33:59 -04:00
|
|
|
chan.pushMessage(
|
|
|
|
this,
|
|
|
|
new Msg({
|
2022-06-18 20:25:21 -04:00
|
|
|
type: MessageType.ERROR,
|
2022-02-09 18:27:34 -05:00
|
|
|
text: "You can not open query windows for names starting with a user prefix.",
|
2019-07-17 05:33:59 -04:00
|
|
|
})
|
|
|
|
);
|
2019-05-13 03:07:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const newChan = this.createChannel({
|
2022-06-18 20:25:21 -04:00
|
|
|
type: ChanType.QUERY,
|
2019-05-13 03:07:45 -04:00
|
|
|
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-10 21:19:09 -04:00
|
|
|
|
2022-06-18 20:25:21 -04:00
|
|
|
if (args.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!targetName) {
|
2016-05-10 21:19:09 -04:00
|
|
|
return true;
|
2014-09-13 17:29:45 -04:00
|
|
|
}
|
2016-03-08 08:36:25 -05:00
|
|
|
|
2018-01-11 06:33:36 -05:00
|
|
|
const msg = args.join(" ");
|
2016-05-25 03:23:03 -04:00
|
|
|
|
|
|
|
if (msg.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-13 03:07:45 -04:00
|
|
|
network.irc.say(targetName, msg);
|
2016-03-08 08:36:25 -05:00
|
|
|
|
2016-04-22 12:38:13 -04:00
|
|
|
if (!network.irc.network.cap.isEnabled("echo-message")) {
|
2019-07-31 17:16:00 -04:00
|
|
|
const parsedTarget = network.irc.network.extractTargetGroup(targetName);
|
|
|
|
let targetGroup;
|
|
|
|
|
|
|
|
if (parsedTarget) {
|
2022-06-18 20:25:21 -04:00
|
|
|
targetName = parsedTarget.target as string;
|
2019-07-31 17:16:00 -04:00
|
|
|
targetGroup = parsedTarget.target_group;
|
|
|
|
}
|
|
|
|
|
2019-05-13 03:07:45 -04:00
|
|
|
const channel = network.getChannel(targetName);
|
2018-02-20 02:28:04 -05:00
|
|
|
|
2016-04-22 12:38:13 -04:00
|
|
|
if (typeof channel !== "undefined") {
|
2018-01-11 06:33:36 -05:00
|
|
|
network.irc.emit("privmsg", {
|
|
|
|
nick: network.irc.user.nick,
|
2018-09-22 06:27:03 -04:00
|
|
|
ident: network.irc.user.username,
|
|
|
|
hostname: network.irc.user.host,
|
2019-07-31 17:16:00 -04:00
|
|
|
target: targetName,
|
|
|
|
group: targetGroup,
|
2017-11-15 01:35:15 -05:00
|
|
|
message: msg,
|
2016-04-22 12:38:13 -04:00
|
|
|
});
|
|
|
|
}
|
2014-09-13 17:29:45 -04:00
|
|
|
}
|
2016-03-06 04:24:56 -05:00
|
|
|
|
|
|
|
return true;
|
2014-09-13 17:29:45 -04:00
|
|
|
};
|
2022-06-18 20:25:21 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
commands,
|
|
|
|
input,
|
|
|
|
};
|