UNPKG

twiedenbein-thelounge

Version:

The self-hosted Web IRC client

75 lines (74 loc) 3.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const msg_1 = __importDefault(require("../../models/msg")); const helper_1 = __importDefault(require("../../helper")); const msg_2 = require("../../../shared/types/msg"); const commands = ["ignore", "unignore"]; const input = function (network, chan, cmd, args) { const client = this; if (args.length === 0 || args[0].trim().length === 0) { chan.pushMessage(client, new msg_1.default({ type: msg_2.MessageType.ERROR, text: `Usage: /${cmd} <nick>[!ident][@host]`, })); return; } const target = args[0].trim(); const hostmask = helper_1.default.parseHostmask(target); switch (cmd) { case "ignore": { // IRC nicks are case insensitive if (hostmask.nick.toLowerCase() === network.nick.toLowerCase()) { chan.pushMessage(client, new msg_1.default({ type: msg_2.MessageType.ERROR, text: "You can't ignore yourself", })); return; } if (network.ignoreList.some(function (entry) { return helper_1.default.compareHostmask(entry, hostmask); })) { chan.pushMessage(client, new msg_1.default({ type: msg_2.MessageType.ERROR, text: "The specified user/hostmask is already ignored", })); return; } network.ignoreList.push({ ...hostmask, when: Date.now(), }); client.save(); chan.pushMessage(client, new msg_1.default({ type: msg_2.MessageType.ERROR, // TODO: Successfully added via type.Error 🤔 ? text: `\u0002${hostmask.nick}!${hostmask.ident}@${hostmask.hostname}\u000f added to ignorelist`, })); return; } case "unignore": { const idx = network.ignoreList.findIndex(function (entry) { return helper_1.default.compareHostmask(entry, hostmask); }); if (idx === -1) { chan.pushMessage(client, new msg_1.default({ type: msg_2.MessageType.ERROR, text: "The specified user/hostmask is not ignored", })); return; } network.ignoreList.splice(idx, 1); client.save(); chan.pushMessage(client, new msg_1.default({ type: msg_2.MessageType.ERROR, // TODO: Successfully removed via type.Error 🤔 ? text: `Successfully removed \u0002${hostmask.nick}!${hostmask.ident}@${hostmask.hostname}\u000f from ignorelist`, })); } } }; exports.default = { commands, input, };