<commit_before>/**
 * @file Various utility functions to inject into the bot instance.
 * @author Ovyerus
 */

/* eslint-env node */

const got = require('got');
const Eris = require('eris');

module.exports = bot => {

    /**
    * Wait for a message in the specified channel from the specified user.
    *
    * @param {String} channelID ID of channel to wait in.
    * @param {String} userID ID of user to wait for.
    * @param {Function} [filter] Filter to pass to message. Must return true.
    * @param {Number} [timeout=15000] Time in milliseconds to wait for message.
    * @returns {Promise<Eris.Message>} Awaited message.
    */
    bot.awaitMessage = (channelID, userID, filter = () => true, timeout = 15000) => {
        return new Promise((resolve, reject) => {
            if (!channelID || typeof channelID !== 'string') {
                reject(new TypeError('channelID is not string.'));
            } else if (!userID || typeof userID !== 'string') {
                reject(new TypeError('userId is not string.'));
            } else {
                var responded, rmvTimeout;

                var onCrt = msg => {
                    if (msg.channel.id === channelID && msg.author.id === userID && filter(msg)) {
                        responded = true;
                        return msg;
                    }
                };

                var onCrtWrap = msg => {
                    var res = onCrt(msg);
                    if (responded) {
                        bot.removeListener('messageCreate', onCrtWrap);
                        clearInterval(rmvTimeout);
                        resolve(res);
                    }
                };

                bot.on('messageCreate', onCrtWrap);

                rmvTimeout = setTimeout(() => {
                    if (!responded) {
                        bot.removeListener('messageCreate', onCrtWrap);
                        reject(new Error('Message await expired.'));
                    }
                }, timeout);
            }
        });
    };

    /**
    * POSTs guild count to DBots.
    */
    bot.postGuildCount = () => {
        if (bot.config.discordBotsPWKey) {
            got(`https://bots.discord.pw/api/bots/${bot.user.id}/stats`, {
                method: 'POST',
                headers: {Authorization: bot.config.discordBotsPWKey, 'Content-Type': 'application/json'},
                body: JSON.stringify({server_count: bot.guilds.size})
            }).then(() => {
                logger.info('POSTed to DBots.');
            }).catch(err => logger.warn(`Unable to POST to DBots.pw: ${err}`));
        }
        if (bot.config.discordBotsOrgKey) {<commit_msg>whoops<commit_after>/**
 * @file Various utility functions to inject into the bot instance.
 * @author Ovyerus
 */

/* eslint-env node */

const got = require('got');
const Eris = require('eris');

module.exports = bot => {

    /**
    * Wait for a message in the specified channel from the specified user.
    *
    * @param {String} channelID ID of channel to wait in.
    * @param {String} userID ID of user to wait for.
    * @param {Function} [filter] Filter to pass to message. Must return true.
    * @param {Number} [timeout=15000] Time in milliseconds to wait for message.
    * @returns {Promise<Eris.Message>} Awaited message.
    */
    bot.awaitMessage = (channelID, userID, filter = () => true, timeout = 15000) => {
        return new Promise((resolve, reject) => {
            if (!channelID || typeof channelID !== 'string') {
                reject(new TypeError('channelID is not string.'));
            } else if (!userID || typeof userID !== 'string') {
                reject(new TypeError('userId is not string.'));
            } else {
                var responded, rmvTimeout;

                var onCrt = msg => {
                    if (msg.channel.id === channelID && msg.author.id === userID && filter(msg)) {
                        responded = true;
                        return msg;
                    }
                };

                var onCrtWrap = msg => {
                    var res = onCrt(msg);
                    if (responded) {
                        bot.removeListener('messageCreate', onCrtWrap);
                        clearInterval(rmvTimeout);
                        resolve(res);
                    }
                };

                bot.on('messageCreate', onCrtWrap);

                rmvTimeout = setTimeout(() => {
                    if (!responded) {
                        bot.removeListener('messageCreate', onCrtWrap);
                        reject(new Error('Message await expired.'));
                    }
                }, timeout);
            }
        });
    };

    /**
    * POSTs guild count to DBots.
    */
    bot.postGuildCount = () => {
        if (bot.config.discordBotsPWKey) {
            got(`https://bots.discord.pw/api/bots/${bot.user.id}/stats`, {
                method: 'POST',
                headers: {Authorization: bot.config.discordBotsPWKey, 'Content-Type': 'application/json'},
                body: JSON.stringify({server_count: bot.guilds.size})
            }).then(() => {
                logger.info('POSTed to DBots.org');
            }).catch(err => logger.warn(`Unable to POST to DBots.pw: ${err}`));
        }
        if (bot.config.discordBotsOrgKey) {
{'fraction_non_alphanumeric': 0.1305649083426861, 'fraction_numerical': 0.0037411148522259632, 'mean_word_length': 1.5498330948974726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '4305446', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1400, 'n_words': 368}