<commit_before>var Eris = require('eris');


var e = module.exports = {}
var db;
var config
var CAT_ID = '103347843934212096'
e.init = (configuration, database) => {

    db = database
    config = configuration

    e.bot = new Eris.Client(config.catbot.token, {
        autoReconnect: true,
        disableEvents: {
            PRESENCE_DATE: true,
            VOICE_STATE_UPDATE: true,
            TYPING_START: true
        }
    });

    e.bot.on('ready', () => {
        console.log('stupid cat> YO SHIT WADDUP ITS DA CAT HERE')
    })

    e.bot.on('messageCreate', (msg) => {
        var prefix = config.general.isbeta ? 'catbeta' : 'cat'
        if (msg.content.startsWith(prefix)) {
            var command = msg.content.replace(prefix, '').trim();
            console.log('stupid cat>', msg.author.username, msg.author.id, prefix, command)
            var words = command.split(' ')
            switch (words.shift().toLowerCase()) {
                case 'eval':
                    console.log('evaling')
                    eval1(msg, words.join(' '))
                    break;
                case 'eval2':
                    console.log('eval2ing')
                    eval2(msg, words.join(' '))
                    break;
                case 'avatar':
                    if (msg.author.id === CAT_ID) {
                        var request = require('request').defaults({ encoding: null });
                        var avatarUrl = '';
                        if (msg.attachments.length > 0) {
                            avatarUrl = msg.attachments[0].url;
                        } else if (words.length > 0) {
                            avatarUrl = words[0];
                        } else {
                            e.bot.createMessage(msg.channel.id, "No URL given.");
                        }
                        request.get(avatarUrl, function (error, response, body) {
                            if (!error && response.statusCode == 200) {
                                data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64');
                                console.log(data);
                                var p1 = e.bot.editSelf({ avatar: data });
                                p1.then(function () {
                                    e.bot.createMessage(msg.channel.id, ":ok_hand: Avatar set!");
                                })
                            }
                        });
                    }
                    break;
                case 'pls': // yay markovs
                    var statement = ` from catchat `
                    statement += ` where nsfw <> 1`
                    db.query(`select count(*) as count` + statement, (err, row) => {
                        if (err)
                            console.log(err);
                        db.query(`select varvalue as pos from vars where varname = ?`,
                            ['markovpos'], (err2, row2) => {
                                if (err2) console.log(err2)
                                if (!row2) {
                                    db.query(`insert into vars (varname, varvalue) values ("markovpos", 0)`)
                                    e.bot.createMessage(msg.channel.id, `Markov initiated! Please try again.`)
                                } else {

                                    var max = row.count;

                                    if (max >= 100) {
                                        var diff = getRandomInt(0, 100) - 50
                                        var pos = parseInt(row2.pos) + diff
                                        if (pos < 0) {
                                            pos += max
                                        }
                                        if (pos > max) {
                                            pos -= max
                                        }
                                        console.log('Getting message at pos', pos)
                                        db.query(`select id, content, attachment` + statement + ` limit 1 offset ?`,
                                            [pos], (err3, row3) => {
                                                if (err3) console.log(err3)
                                                if (row3) {
                                                    var messageToSend = `${row3.content} ${row3.attachment == 'none' ? '' :
                                                        row3.attachment}`;
                                                    e.bot.createMessage(msg.channel.id, `\u200B` + messageToSend);
                                                    db.query(`update vars set varvalue = ? where varname="markovpos"`,
                                                        [pos])
                                                }
                                            })

                                    } else {
                                        e.bot.createMessage(msg.channel.id, `I don't have a big enough sample size.`);
                                    }

                                }<commit_msg>fixed catbot markov<commit_after>var Eris = require('eris');


var e = module.exports = {}
var db;
var config
var CAT_ID = '103347843934212096'
e.init = (configuration, database) => {

    db = database
    config = configuration

    e.bot = new Eris.Client(config.catbot.token, {
        autoReconnect: true,
        disableEvents: {
            PRESENCE_DATE: true,
            VOICE_STATE_UPDATE: true,
            TYPING_START: true
        }
    });

    e.bot.on('ready', () => {
        console.log('stupid cat> YO SHIT WADDUP ITS DA CAT HERE')
    })

    e.bot.on('messageCreate', (msg) => {
        var prefix = config.general.isbeta ? 'catbeta' : 'cat'
        if (msg.content.startsWith(prefix)) {
            var command = msg.content.replace(prefix, '').trim();
            console.log('stupid cat>', msg.author.username, msg.author.id, prefix, command)
            var words = command.split(' ')
            switch (words.shift().toLowerCase()) {
                case 'eval':
                    console.log('evaling')
                    eval1(msg, words.join(' '))
                    break;
                case 'eval2':
                    console.log('eval2ing')
                    eval2(msg, words.join(' '))
                    break;
                case 'avatar':
                    if (msg.author.id === CAT_ID) {
                        var request = require('request').defaults({ encoding: null });
                        var avatarUrl = '';
                        if (msg.attachments.length > 0) {
                            avatarUrl = msg.attachments[0].url;
                        } else if (words.length > 0) {
                            avatarUrl = words[0];
                        } else {
                            e.bot.createMessage(msg.channel.id, "No URL given.");
                        }
                        request.get(avatarUrl, function (error, response, body) {
                            if (!error && response.statusCode == 200) {
                                data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64');
                                console.log(data);
                                var p1 = e.bot.editSelf({ avatar: data });
                                p1.then(function () {
                                    e.bot.createMessage(msg.channel.id, ":ok_hand: Avatar set!");
                                })
                            }
                        });
                    }
                    break;
                case 'pls': // yay markovs
                    var statement = ` from catchat `
                    statement += ` where nsfw <> 1`
                    db.query(`select count(*) as count` + statement, (err, row) => {
                        if (err)
                            console.log(err);
                        db.query(`select varvalue as pos from vars where varname = ?`,
                            ['markovpos'], (err2, row2) => {
                                if (err2) console.log(err2)
                                if (!row2[0]) {
                                    db.query(`insert into vars (varname, varvalue) values ("markovpos", 0)`)
                                    e.bot.createMessage(msg.channel.id, `Markov initiated! Please try again.`)
                                } else {

                                    var max = row[0].count;
                                    console.log(max)
                                    if (max >= 100) {
                                        var diff = getRandomInt(0, 100) - 50
                                        var pos = parseInt(row2[0].pos) + diff
                                        if (pos < 0) {
                                            pos += max
                                        }
                                        if (pos > max) {
                                            pos -= max
                                        }
                                        console.log('Getting message at pos', pos)
                                        db.query(`select id, content, attachment` + statement + ` limit 1 offset ?`,
                                            [pos], (err3, row3) => {
                                                if (err3) console.log(err3)
                                                if (row3[0]) {
                                                    var messageToSend = `${row3[0].content} ${row3[0].attachment == 'none' ? '' :
                                                        row3[0].attachment}`;
                                                    e.bot.createMessage(msg.channel.id, `\u200B` + messageToSend);
                                                    db.query(`update vars set varvalue = ? where varname="markovpos"`,
                                                        [pos])
                                                }
                                            })
                                    } else {
                                        e.bot.createMessage(msg.channel.id, `I don't have a big enough sample size.`);
                                    }

                                }
{'fraction_non_alphanumeric': 0.1040268456375839, 'fraction_numerical': 0.013135186960690316, 'mean_word_length': 0.811251953464143, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 101, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5658918', 'n_tokens_mistral': 2395, 'n_tokens_neox': 2224, 'n_words': 519}