"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 msg_2 = require("../../../shared/types/msg");
const chan_1 = require("../../../shared/types/chan");
const commands = ["topic", "cleartopic"];
const input = function ({ irc }, chan, cmd, args) {
    if (chan.type !== chan_1.ChanType.CHANNEL) {
        chan.pushMessage(this, new msg_1.default({
            type: msg_2.MessageType.ERROR,
            text: `${cmd} command can only be used in channels.`,
        }));
        return;
    }
    if (cmd === "cleartopic") {
        irc.clearTopic(chan.name);
        return;
    }
    const cleanArgs = args.map((s) => s.trim()).filter((s) => s !== "");
    if (cleanArgs.length === 0) {
        irc.raw("TOPIC", chan.name);
        return;
    }
    // we use the non trimmed args here, the user may have added white space on purpose
    irc.setTopic(chan.name, args.join(" "));
    return true;
};
exports.default = {
    commands,
    input,
};
