<commit_before>"use strict";

var AdminCommand = require("./AdminCommand");

var adminCommands = {};

adminCommands.help = AdminCommand.makeHelpCommand(adminCommands);

adminCommands.list = new AdminCommand({
    desc: "list the linked rooms",
    func: function(bridge, args, respond) {
        bridge._rooms.forEach((room) => {
            var matrix_room_ids = room.getMatrixRoomIds();

            var slack_channel_id = room.getSlackChannelId() || "--pending--";
            var slack_channel_name = room.getSlackChannelName() || "UNKNOWN";

            var slack = slack_channel_name + "(" + slack_channel_id + ")";

            var status = room.getStatus();
            if (status !== "ready") status = status.toUpperCase();

            if (!matrix_room_ids.length) {
                respond(status + " " + slack + " unlinked");
            }
            else if (matrix_room_ids.length == 1) {
                respond(status + " " + slack + " -- " + matrix_room_ids[0]);
            }
            else {
                respond(status + " " + slack + " linked:");
                matrix_room_ids.forEach((id) => respond(" +- " + id));
            }
        });
    },
});

adminCommands.link = new AdminCommand({
    desc: "connect a Matrix and a Slack room together",
    opts: {
        "channel_id|I": "Slack channel ID",
        "channel|C": "Slack channel name",
        "room|R": "Matrix room ID",
        "webhook_url|u": "Slack webhook URL",
        "token|t": "Slack webhook token",
    },
    func: function(bridge, opts, args, respond) {
        if (!opts.channel && !opts.channel_id) {
            return Promise.reject("Require either --channel or --channel_id");
        }

        return bridge.actionLink({
            matrix_room_id: opts.room,
            slack_channel_name: opts.channel,
            slack_channel_id: opts.channel_id,
            slack_token: opts.token,
            slack_webhook_uri: opts.webhook_url,
        }).then(
            (room) => {
                respond("Room is now " + room.getStatus());
            },<commit_msg>Allow 'list' to filter by rooms for one particular team<commit_after>"use strict";

var AdminCommand = require("./AdminCommand");

var adminCommands = {};

function quotemeta(s) { return s.replace(/\W/g, '\\$&'); }

adminCommands.help = AdminCommand.makeHelpCommand(adminCommands);

adminCommands.list = new AdminCommand({
    desc: "list the linked rooms",
    opts: {
        "team|T": "Filter only rooms for this Slack team domain",
    },
    func: function(bridge, opts, args, respond) {
        var name_filter;

        if (opts.team) {
            name_filter = new RegExp("^" + quotemeta(opts.team) + "\.#");
        }

        var found = 0;
        bridge._rooms.forEach((room) => {
            var matrix_room_ids = room.getMatrixRoomIds();

            var slack_channel_id = room.getSlackChannelId() || "--pending--";
            var slack_channel_name = room.getSlackChannelName() || "UNKNOWN";

            if (name_filter && !name_filter.exec(slack_channel_name)) {
                return;
            }

            var slack = slack_channel_name + "(" + slack_channel_id + ")";

            var status = room.getStatus();
            if (status !== "ready") status = status.toUpperCase();

            found++;

            if (!matrix_room_ids.length) {
                respond(status + " " + slack + " unlinked");
            }
            else if (matrix_room_ids.length == 1) {
                respond(status + " " + slack + " -- " + matrix_room_ids[0]);
            }
            else {
                respond(status + " " + slack + " linked:");
                matrix_room_ids.forEach((id) => respond(" +- " + id));
            }
        });

        if (!found) {
            respond("No rooms found");
        }
    },
});

adminCommands.link = new AdminCommand({
    desc: "connect a Matrix and a Slack room together",
    opts: {
        "channel_id|I": "Slack channel ID",
        "channel|C": "Slack channel name",
        "room|R": "Matrix room ID",
        "webhook_url|u": "Slack webhook URL",
        "token|t": "Slack webhook token",
    },
    func: function(bridge, opts, args, respond) {
        if (!opts.channel && !opts.channel_id) {
            return Promise.reject("Require either --channel or --channel_id");
        }

        return bridge.actionLink({
            matrix_room_id: opts.room,
            slack_channel_name: opts.channel,
            slack_channel_id: opts.channel_id,
            slack_token: opts.token,
            slack_webhook_uri: opts.webhook_url,
        }).then(
            (room) => {
                respond("Room is now " + room.getStatus());
            },
{'fraction_non_alphanumeric': 0.13897729683853172, 'fraction_numerical': 0.0010608953957139827, 'mean_word_length': 1.9797724399494312, 'pattern_counts': {'":': 11, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '193682', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1353, 'n_words': 303}