2024-02-15 23:01:22 +01:00
|
|
|
import Msg from "../../models/msg";
|
2022-06-19 02:25:21 +02:00
|
|
|
import Helper from "../../helper";
|
|
|
|
import {PluginInputHandler} from "./index";
|
|
|
|
import {IgnoreListItem} from "../../models/network";
|
2024-02-15 23:01:22 +01:00
|
|
|
import {MessageType} from "../../../shared/types/msg";
|
2018-03-11 19:17:57 +01:00
|
|
|
|
2024-04-14 13:44:39 +02:00
|
|
|
const commands = ["ignore", "unignore"];
|
2018-03-11 19:17:57 +01:00
|
|
|
|
2022-06-19 02:25:21 +02:00
|
|
|
const input: PluginInputHandler = function (network, chan, cmd, args) {
|
2018-03-11 19:17:57 +01:00
|
|
|
const client = this;
|
2022-06-19 02:25:21 +02:00
|
|
|
let target: string;
|
|
|
|
// let hostmask: cmd === "ignoreList" ? string : undefined;
|
|
|
|
let hostmask: IgnoreListItem | undefined;
|
2018-03-11 19:17:57 +01:00
|
|
|
|
|
|
|
if (cmd !== "ignorelist" && (args.length === 0 || args[0].trim().length === 0)) {
|
2019-07-17 11:33:59 +02:00
|
|
|
chan.pushMessage(
|
|
|
|
client,
|
|
|
|
new Msg({
|
2022-06-19 02:25:21 +02:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 11:33:59 +02:00
|
|
|
text: `Usage: /${cmd} <nick>[!ident][@host]`,
|
|
|
|
})
|
|
|
|
);
|
2018-03-11 19:17:57 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd !== "ignorelist") {
|
|
|
|
// Trim to remove any spaces from the hostmask
|
|
|
|
target = args[0].trim();
|
2022-06-19 02:25:21 +02:00
|
|
|
hostmask = Helper.parseHostmask(target) as IgnoreListItem;
|
2018-03-11 19:17:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
2019-07-17 11:33:59 +02:00
|
|
|
case "ignore": {
|
|
|
|
// IRC nicks are case insensitive
|
2022-06-19 02:25:21 +02:00
|
|
|
if (hostmask!.nick.toLowerCase() === network.nick.toLowerCase()) {
|
2019-07-17 11:33:59 +02:00
|
|
|
chan.pushMessage(
|
|
|
|
client,
|
|
|
|
new Msg({
|
2022-06-19 02:25:21 +02:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 11:33:59 +02:00
|
|
|
text: "You can't ignore yourself",
|
|
|
|
})
|
|
|
|
);
|
2024-04-14 13:33:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
network.ignoreList.some(function (entry) {
|
2022-06-19 02:25:21 +02:00
|
|
|
return Helper.compareHostmask(entry, hostmask!);
|
2019-07-17 11:33:59 +02:00
|
|
|
})
|
|
|
|
) {
|
|
|
|
chan.pushMessage(
|
|
|
|
client,
|
|
|
|
new Msg({
|
2022-06-19 02:25:21 +02:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 11:33:59 +02:00
|
|
|
text: "The specified user/hostmask is already ignored",
|
|
|
|
})
|
|
|
|
);
|
2024-04-14 13:33:22 +02:00
|
|
|
return;
|
2019-07-17 11:33:59 +02:00
|
|
|
}
|
2018-03-11 19:17:57 +01:00
|
|
|
|
2024-04-14 13:33:22 +02:00
|
|
|
hostmask!.when = Date.now();
|
|
|
|
network.ignoreList.push(hostmask!);
|
|
|
|
|
|
|
|
client.save();
|
|
|
|
chan.pushMessage(
|
|
|
|
client,
|
|
|
|
new Msg({
|
|
|
|
type: MessageType.ERROR, // TODO: Successfully added via type.Error 🤔 ?
|
|
|
|
text: `\u0002${hostmask!.nick}!${hostmask!.ident}@${
|
|
|
|
hostmask!.hostname
|
|
|
|
}\u000f added to ignorelist`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return;
|
2019-07-17 11:33:59 +02:00
|
|
|
}
|
2018-03-11 19:17:57 +01:00
|
|
|
|
2019-07-17 11:33:59 +02:00
|
|
|
case "unignore": {
|
2020-03-21 21:55:36 +01:00
|
|
|
const idx = network.ignoreList.findIndex(function (entry) {
|
2022-06-19 02:25:21 +02:00
|
|
|
return Helper.compareHostmask(entry, hostmask!);
|
2019-07-17 11:33:59 +02:00
|
|
|
});
|
|
|
|
|
2024-04-14 13:33:22 +02:00
|
|
|
if (idx === -1) {
|
2019-07-17 11:33:59 +02:00
|
|
|
chan.pushMessage(
|
|
|
|
client,
|
|
|
|
new Msg({
|
2022-06-19 02:25:21 +02:00
|
|
|
type: MessageType.ERROR,
|
2019-07-17 11:33:59 +02:00
|
|
|
text: "The specified user/hostmask is not ignored",
|
|
|
|
})
|
|
|
|
);
|
2024-04-14 13:33:22 +02:00
|
|
|
return;
|
2019-07-17 11:33:59 +02:00
|
|
|
}
|
2018-03-11 19:17:57 +01:00
|
|
|
|
2024-04-14 13:33:22 +02:00
|
|
|
network.ignoreList.splice(idx, 1);
|
|
|
|
client.save();
|
|
|
|
|
|
|
|
chan.pushMessage(
|
|
|
|
client,
|
|
|
|
new Msg({
|
|
|
|
type: MessageType.ERROR, // TODO: Successfully removed via type.Error 🤔 ?
|
|
|
|
text: `Successfully removed \u0002${hostmask!.nick}!${hostmask!.ident}@${
|
|
|
|
hostmask!.hostname
|
|
|
|
}\u000f from ignorelist`,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2018-03-11 19:17:57 +01:00
|
|
|
}
|
|
|
|
};
|
2022-06-19 02:25:21 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
commands,
|
|
|
|
input,
|
|
|
|
};
|