<commit_before>const fs = require("fs");
const upone = require("../util/upone")
var Canvas = require("canvas-prebuilt");
var Image = Canvas.Image;

function draw_images(imglist, gid) {
    return new Promise((resolve, reject) => {
        let full_width = (10 % imglist.length == 10 ? 10 : imglist.length) * 100;
        let full_height = Math.ceil(imglist.length / 10) * 100;
        let __upone = upone(__dirname);
        var canvas = new Canvas(full_width, full_height);
        var ctx = canvas.getContext("2d");

        for (img in imglist) {
            let xpos = img % 10 * 100;
            let ypos = Math.floor(img / 10) * 100;
            let imago = new Image();
            imago.src = imglist[img];

            ctx.drawImage(imago, xpos, ypos, 100, 100);
            //ctx.fillText(img, xpos, ypos);

            if (img == imglist.length - 1) {
                let loc = `${__upone}/grids/${gid}.png`;
                canvas.pngStream().pipe(fs.createWriteStream(loc)).on("finish", () => {
                    resolve(loc);
                });
            }
        }
    });
}

function get_image(url) {
    return new Promise((resolve, reject) => {
        fs.readFile(url, (err, data) => {
            if (err) reject(err);
            resolve(data);
        });
    });
}

module.exports = message => {
    let gid = message.channel.guild.id;
    let gcfg = message._client.gcfg[gid];
    let __upone = `${upone(__dirname)}/guilds/${gid}`;

    message.channel.sendTyping().then(() => {
        fs.readdir(__upone, (err, files) => {
            files.sort();
            let requests = files.map(fname => get_image(`${__upone}/${fname}`));
            Promise.all(requests).then(flist => {
                draw_images(flist, gid).then(loc => {
                    fs.readFile(loc, (err, data) => {
                        message.channel.createMessage("heck", {
                            "file": data,
                            "name": "heck.png"
                        }).then(() => {
                            console.log(`sent grid to ${message.channel.guild.name}`);
                        }).catch(err => {
                            console.log(err);
                            message.channel.createMessage("something went wrong :c");
                        });
                    });<commit_msg>code is more and less garbage<commit_after>const fs = require("fs");
const upone = require("../util/upone")
var Canvas = require("canvas-prebuilt");
var Image = Canvas.Image;

function draw_images(imglist, gid) {
    return new Promise((resolve, reject) => {
        let full_width = (5 % imglist.length == 5 ? 5 : imglist.length) * 100;
        let full_height = Math.ceil(imglist.length / 5) * 100;
        let __upone = upone(__dirname);
        var canvas = new Canvas(full_width, full_height);
        var ctx = canvas.getContext("2d");

        for (img in imglist) {
            let xpos = img % 5 * 100;
            let ypos = Math.floor(img / 5) * 100;
            let imago = new Image();
            imago.src = imglist[img];

            ctx.drawImage(imago, xpos, ypos, 100, 100);
            //ctx.fillText(img, xpos, ypos);

            if (img == imglist.length - 1) {
                let loc = `${__upone}/grids/${gid}.png`;
                canvas.pngStream().pipe(fs.createWriteStream(loc)).on("finish", () => {
                    resolve(loc);
                });
            }
        }
    });
}

function get_image(url) {
    return new Promise((resolve, reject) => {
        fs.readFile(url, (err, data) => {
            if (err) reject(err);
            resolve(data);
        });
    });
}

module.exports = message => {
    let gid = message.channel.guild.id;
    let gcfg = message._client.gcfg[gid];
    let __upone = `${upone(__dirname)}/guilds/${gid}`;

    message.channel.sendTyping().then(() => {
        fs.readdir(__upone, (err, files) => {
            files.sort();
            let requests = files.map(fname => get_image(`${__upone}/${fname}`));
            Promise.all(requests).then(flist => {
                draw_images(flist, gid).then(loc => {
                    fs.readFile(loc, (err, data) => {
                        let rows = [];
                        for (fnum in files) {
                            if (fnum % 5 + 1 == 1) rows.push([]);
                            rows[rows.length - 1].push(files[fnum]);
                        }

                        message.channel.createMessage(`${"```js\n"}${rows.map(row => row.join(", ")).join("\n")}${"\n```"}`, {
                            "file": data,
                            "name": "heck.png"
                        }).then(() => {
                            console.log(`sent grid to ${message.channel.guild.name}`);
                        }).catch(err => {
                            console.log(err);
                            message.channel.createMessage("something went wrong :c");
                        });
                    });
{'fraction_non_alphanumeric': 0.15738886663996796, 'fraction_numerical': 0.012414897877452943, 'mean_word_length': 1.5303951367781155, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 30, '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': '5583496', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1457, 'n_words': 291}