<commit_before>/*
 * saucenao.js - grab a image's source using saucenao. Grabs the last message attachment/URL, provided along with the command
 * or providing an attachment using the command as the caption.
 * 
 *  Contributed by Capuccino
 */

/* eslint-env node */

//this handles the SauceNao handling
const ayaneru = new (require('./sauceQueryHandler'))();
//this regex is gay

const urlRegex = str => /(http(s)?:\/\/)?(www\.)?[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi.test(str);

exports.commands = [
    'saucenao'
];

exports.saucenao = {
    desc: 'Gets the image from the recent attachment or via a image link and looks for saucenao to check for the source of the image.',
    main(bot, ctx) { 
        return new Promise((resolve, reject) => {
            if (!ctx.attachments[0]) {
                return ctx.createMessage('Aw, no image here.');
            } else if (!ctx.suffix === urlRegex) {
                return ctx.createMessage('Oi, your URL is invalid!');
            } else if (ctx.attachments[0]) {
                ayaneru.getSauce(ctx.attachments[0].url).then(res => {
                    for (res.url of res) {
                        var fields = [];
                        fields.push(`${{name: 'Item', value: res.url, inline: true}}`);
                    }
                    ctx.createMessage({embed: {
                        title: 'Saucenao query results',
                        description: 'This is the closest I can find. Sorry if it is not accurate.',
                        fields
                    }}).then(resolve).catch(reject);
                });
            }
        });
    }
};<commit_msg>put the resolve and reject in proper place<commit_after>/*
 * saucenao.js - grab a image's source using saucenao. Grabs the last message attachment/URL, provided along with the command
 * or providing an attachment using the command as the caption.
 * 
 *  Contributed by Capuccino
 */

/* eslint-env node */

//this handles the SauceNao handling
const ayaneru = new (require('./sauceQueryHandler'))();
//this regex is gay

const urlRegex = str => /(http(s)?:\/\/)?(www\.)?[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi.test(str);

exports.commands = [
    'saucenao'
];

exports.saucenao = {
    desc: 'Gets the image from the recent attachment or via a image link and looks for saucenao to check for the source of the image.',
    main(bot, ctx) { 
        return new Promise((resolve, reject) => {
            if (!ctx.attachments[0]) {
                return ctx.createMessage('Aw, no image here.');
            } else if (!ctx.suffix === urlRegex) {
                return ctx.createMessage('Oi, your URL is invalid!');
            } else if (ctx.attachments[0]) {
                ayaneru.getSauce(ctx.attachments[0].url).then(res => {
                    for (res.url of res) {
                        var fields = [];
                        fields.push(`${{name: 'Item', value: res.url, inline: true}}`);
                    }
                    ctx.createMessage({embed: {
                        title: 'Saucenao query results',
                        description: 'This is the closest I can find. Sorry if it is not accurate.',
                        fields
                    }});
                }).then(resolve).catch(reject);
            }
        });
    }
};
{'fraction_non_alphanumeric': 0.1528962069979418, 'fraction_numerical': 0.007644810349897089, 'mean_word_length': 1.8208955223880596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3377833', 'n_tokens_mistral': 1046, 'n_tokens_neox': 995, 'n_words': 283}