<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
 */
exports.commands = [
    'saucenao'
];

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

exports.saucenao = {
    desc: 'Grab an image\'s source using saucenao API.',
    longDesc: 'Gets the image source from sacuenao.',
    usage: '(Image URL [If not provided, it would grab the last message with image attachment\'s URL and sends it to the API])',
    main(bot, ctx) {
        if (!ctx.suffix) {
            //grab the last message with an attachment
            if (!ctx.msg.channel.attachments) {
                ctx.msg.channel.createMessage('Aw, no Image here.');
            } else {
                let imgUrl = ctx.msg.channel.attachments[0].url;
                got(`https://saucenao.com`, {
                    method: 'POST',
                    'Content-Type': 'application/json',
                    body: JSON.stringify({url: imgUrl})
                }).then(res => {
                    //only return the top result
                    const fields = [];<commit_msg>fix error?<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
 */
exports.commands = [
    'saucenao'
];

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

exports.saucenao = {
    desc: 'Grab an image\'s source using saucenao API.',
    longDesc: 'Gets the image source from sacuenao.',
    usage: '(Image URL [If not provided, it would grab the last message with image attachment\'s URL and sends it to the API])',
    main(bot, ctx) {
        if (!ctx.suffix) {
            //grab the last message with an attachment
            if (!ctx.msg.channel.attachments) {
                ctx.msg.channel.createMessage('Aw, no Image here.').then(reject);
            } else {
                let imgUrl = ctx.msg.channel.attachments[0].url;
                got(`https://saucenao.com`, {
                    method: 'POST',
                    'Content-Type': 'application/json',
                    body: JSON.stringify({url: imgUrl})
                }).then(res => {
                    //only return the top result
                    const fields = [];
{'fraction_non_alphanumeric': 0.15118956254796623, 'fraction_numerical': 0.00844205679201842, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3290623', 'n_tokens_mistral': 824, 'n_tokens_neox': 786, 'n_words': 225}