<commit_before>const Filter = require('./../../query/utils/Filter');

class ViewerBuilder
{
    /**
     * Execute the Viewer Builder method.
     */
    static run(ts3) {
        this.ts3 = ts3;

        return new Promise(this.viewerBuilder.bind(this));
    }

    /**
     * Get viewer data.
     *
     * @param {callback} resolve
     * @param {callback} reject
     */
    static async viewerBuilder(resolve, reject) {
        let channels;
        let clients;

        try {
            channels = await this.ts3.channelList();
            clients = await this.ts3.clientList({ client_type: 0 });
        } catch (error) {
            reject(error);
        }

        let result = this.getChannels(channels, clients);
        resolve(result);
    }

    /**
     * Organize all channels/clients.
     *
     * @param {array} channels
     * @param {array} clients
     * @param {number} parentChannelID
     * @returns {array}
     */
    static getChannels(channels, clients, parentChannelID = 0) {
        let result = [];
        let filteredChannels = Filter.run(channels, 'data', { pid: parentChannelID });

        filteredChannels.forEach(channel => {
            result.push({
                channel,
                clients: channel.clients(clients),
                subChannels: this.getChannels(channels, clients, channel.data.cid)
            });
        });

        return result;
    }
}

module.exports = ViewerBuilder;<commit_msg>ViewerBuilder: Give objects, not classes<commit_after>const Filter = require('./../../query/utils/Filter');

class ViewerBuilder
{
    /**
     * Execute the Viewer Builder method.
     */
    static run(ts3) {
        this.ts3 = ts3;

        return new Promise(this.viewerBuilder.bind(this));
    }

    /**
     * Get viewer data.
     *
     * @param {callback} resolve
     * @param {callback} reject
     */
    static async viewerBuilder(resolve, reject) {
        let channels;
        let clients;

        try {
            channels = await this.ts3.channelList();
            clients = await this.ts3.clientList({ client_type: 0 });
        } catch (error) {
            reject(error);
        }

        let result = this.getChannels(channels, clients);
        resolve(result);
    }

    /**
     * Organize all channels/clients.
     *
     * @param {array} channels
     * @param {array} clients
     * @param {number} parentChannelID
     * @returns {array}
     */
    static getChannels(channels, clients, parentChannelID = 0) {
        let result = [];
        let filteredChannels = Filter.run(channels, 'data', { pid: parentChannelID });

        filteredChannels.forEach(channel => {
            let channelClients = [];
            channel.clients(clients).forEach(client => {
                channelClients.push(client.getObject());
            });

            result.push({
                channel: channel.getObject(),
                clients: channelClients,
                subChannels: this.getChannels(channels, clients, channel.data.cid)
            });
        });

        return result;
    }
}

module.exports = ViewerBuilder;
{'fraction_non_alphanumeric': 0.12211538461538461, 'fraction_numerical': 0.004487179487179487, 'mean_word_length': 1.8738489871086557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5983553', 'n_tokens_mistral': 881, 'n_tokens_neox': 855, 'n_words': 190}