<commit_before>var discord = require('discord.js');
var request = require('request');
var config = require('./config.js');

var bot = new discord.Client({
    autoReconnect: true
});

var epBase = 'https://ep.decapi.me';
var urlTemplates = {
    twitch: epBase + '/t/2/{id}.png',
    bttv: epBase + '/b/2/{id}.{type}'
};

var emotes = {
    twitch: {},
    bttv: {}
};

var authUrl = 'https://discordapp.com/oauth2/authorize?client_id=' + config.discord.client_id + '&scope=bot&permissions=19456';

/**
 * Sends a GET request for the specified URL
 *
 * @param  {String}   url     Request URL
 * @param  {Object}   headers HTTP headers to send with the request
 * @param  {Function} cb      Callback function
 * @return {void}
 */
var get = function(url, headers, cb) {
    request({
        url: url,
        headers: headers
    }, cb);
};

/**
 * Refreshes all cached Twitch emotes.
 *
 * @return {void}
 */
var getTwitchEmotes = function() {
    get("https://api.twitch.tv/kraken/chat/emoticon_images", {'Client-ID': config.twitch.client_id}, function(error, response, body) {
        if (response.statusCode === 200) {
            body = JSON.parse(body);

            body.emoticons.forEach(function(emote) {
                emotes.twitch[emote.code.toLowerCase()] = {
                    id: emote.id,
                    set: emote.emoticon_set
                };
            });
            console.log("Added Twitch emotes");
        }

        // Global emotes override all else:
        get("https://api.twitch.tv/kraken/chat/emoticon_images?emotesets=0,457", {'Client-ID': config.twitch.client_id}, function(error, response, body) {
            if (response.statusCode === 200) {
                body = JSON.parse(body);

                body.emoticon_sets[0].forEach(function(emote) {
                    emotes.twitch[emote.code.toLowerCase()] = {
                        id: emote.id,
                        set: 0
                    };
                });

                body.emoticon_sets[457].forEach(function(emote) {
                    emotes.twitch[emote.code.toLowerCase()] = {
                        id: emote.id,
                        set: 457
                    };
                });
                console.log("Added and prioritized Twitch global emotes");
            }
        });
    });
};

/**
 * Refreshes all BTTV emotes (including channel emotes)
 *
 * @return {void}
 */
var getBttvEmotes = function() {
    get("https://api.betterttv.net/2/emotes", {}, function(error, response, body) {
        if (response.statusCode === 200) {
            body = JSON.parse(body);

            body.emotes.forEach(function(emote) {
                emotes.bttv[emote.code.toLowerCase()] = {
                    id: emote.id,
                    type: emote.type
                };
            });
            console.log("Added global BTTV emotes");
        }
    });

    config.bttv.channels.forEach(function(channel) {
        get("https://api.betterttv.net/2/channels/" + channel, {}, function(error, response, body) {
            if (response.statusCode === 200) {
                body = JSON.parse(body);

                body.emotes.forEach(function(emote) {
                    emotes.bttv[emote.code.toLowerCase()] = {
                        id: emote.id,
                        type: emote.imageType
                    };
                    console.log("Added BTTV emotes for channel: " + channel);
                });
            }
        });
    });
};

var checkEmote = function(code) {
    if (emotes.twitch[code]) {
        return urlTemplates.twitch.replace('{id}', emotes.twitch[code].id);
    }

    if (emotes.bttv[code]) {
        return urlTemplates.bttv.replace(['{id}', '{type}'], [emote.id, emote.type]);
    }

    return null;
};<commit_msg>Fix BTTV emote lookup<commit_after>var discord = require('discord.js');
var request = require('request');
var config = require('./config.js');

var bot = new discord.Client({
    autoReconnect: true
});

var epBase = 'https://ep.decapi.me';
var urlTemplates = {
    twitch: epBase + '/t/2/{id}.png',
    bttv: epBase + '/b/2/{id}.{type}'
};

var emotes = {
    twitch: {},
    bttv: {}
};

var authUrl = 'https://discordapp.com/oauth2/authorize?client_id=' + config.discord.client_id + '&scope=bot&permissions=19456';

/**
 * Sends a GET request for the specified URL
 *
 * @param  {String}   url     Request URL
 * @param  {Object}   headers HTTP headers to send with the request
 * @param  {Function} cb      Callback function
 * @return {void}
 */
var get = function(url, headers, cb) {
    request({
        url: url,
        headers: headers
    }, cb);
};

/**
 * Refreshes all cached Twitch emotes.
 *
 * @return {void}
 */
var getTwitchEmotes = function() {
    get("https://api.twitch.tv/kraken/chat/emoticon_images", {'Client-ID': config.twitch.client_id}, function(error, response, body) {
        if (response.statusCode === 200) {
            body = JSON.parse(body);

            body.emoticons.forEach(function(emote) {
                emotes.twitch[emote.code.toLowerCase()] = {
                    id: emote.id,
                    set: emote.emoticon_set
                };
            });
            console.log("Added Twitch emotes");
        }

        // Global emotes override all else:
        get("https://api.twitch.tv/kraken/chat/emoticon_images?emotesets=0,457", {'Client-ID': config.twitch.client_id}, function(error, response, body) {
            if (response.statusCode === 200) {
                body = JSON.parse(body);

                body.emoticon_sets[0].forEach(function(emote) {
                    emotes.twitch[emote.code.toLowerCase()] = {
                        id: emote.id,
                        set: 0
                    };
                });

                body.emoticon_sets[457].forEach(function(emote) {
                    emotes.twitch[emote.code.toLowerCase()] = {
                        id: emote.id,
                        set: 457
                    };
                });
                console.log("Added and prioritized Twitch global emotes");
            }
        });
    });
};

/**
 * Refreshes all BTTV emotes (including channel emotes)
 *
 * @return {void}
 */
var getBttvEmotes = function() {
    get("https://api.betterttv.net/2/emotes", {}, function(error, response, body) {
        if (response.statusCode === 200) {
            body = JSON.parse(body);

            body.emotes.forEach(function(emote) {
                emotes.bttv[emote.code.toLowerCase()] = {
                    id: emote.id,
                    type: emote.type
                };
            });
            console.log("Added global BTTV emotes");
        }
    });

    config.bttv.channels.forEach(function(channel) {
        get("https://api.betterttv.net/2/channels/" + channel, {}, function(error, response, body) {
            if (response.statusCode === 200) {
                body = JSON.parse(body);

                body.emotes.forEach(function(emote) {
                    emotes.bttv[emote.code.toLowerCase()] = {
                        id: emote.id,
                        type: emote.imageType
                    };
                    console.log("Added BTTV emotes for channel: " + channel);
                });
            }
        });
    });
};

var checkEmote = function(code) {
    if (emotes.twitch[code]) {
        return urlTemplates.twitch.replace('{id}', emotes.twitch[code].id);
    }

    if (emotes.bttv[code]) {
        var emote = emotes.bttv[code];
        return urlTemplates.bttv.replace(['{id}', '{type}'], [emote.id, emote.type]);
    }

    return null;
};
{'fraction_non_alphanumeric': 0.14718558182055635, 'fraction_numerical': 0.008880762700796657, 'mean_word_length': 1.7477574452816649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 12, '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': '1572787', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2325, 'n_words': 428}