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