<commit_before>/**
 * @file Image sourcer command via SauceNAO
 * @author Capuccino
 * @author Ovyerus
 */
/* eslint-env node */

const Sagiri = require('sagiri');

const urlRegex = /^(?:(?:https?:)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
let sourcer;

exports.init = bot => {
    sourcer = new Sagiri(bot.config.sauceKey);
};

exports.commands = [
    'source'
];

exports.source = {
    desc: 'Tries to find the source for an image.',
    usage: '<url or attachment>',
    main(bot, ctx) { 
        return new Promise((resolve, reject) => {
            if (!ctx.attachments[0] && (!ctx.suffix || !urlRegex.test(ctx.suffix))) {
                ctx.createMessage('Please provide an image.').then(resolve).catch(reject);
            } else {
                let url = ctx.attachments[0] ? ctx.attachments[0].url : ctx.suffix;

                ctx.channel.sendTyping().then(() => sourcer.getSource(url)).then(res => {
                    return ctx.createMessage({embed: {
                        title: 'Source Found',
                        description: `[**Source URL**](${res[0].url})`,
                        thumbnail: {url: res[0].thumbnail},
                        fields: [<commit_msg>also pull from the recent attachment form a recent image because im fuckn gay<commit_after>/**
 * @file Image sourcer command via SauceNAO
 * @author Capuccino
 * @author Ovyerus
 */
/* eslint-env node */

const Sagiri = require('sagiri');

const urlRegex = /^(?:(?:https?:)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
let sourcer;

exports.init = bot => {
    sourcer = new Sagiri(bot.config.sauceKey);
};

exports.commands = [
    'source'
];

exports.source = {
    desc: 'Tries to find the source for an image.',
    usage: '<url or attachment>',
    main(bot, ctx) { 
        return new Promise((resolve, reject) => {
            if (!ctx.attachments[0] || ctx.attachments[1] && (!ctx.suffix || !urlRegex.test(ctx.suffix))) {
                ctx.createMessage('Please provide an image.').then(resolve).catch(reject);
            } else {
                let url = ctx.attachments[0] ? ctx.attachments[0].url : ctx.suffix;

                ctx.channel.sendTyping().then(() => sourcer.getSource(url)).then(res => {
                    return ctx.createMessage({embed: {
                        title: 'Source Found',
                        description: `[**Source URL**](${res[0].url})`,
                        thumbnail: {url: res[0].thumbnail},
                        fields: [
{'fraction_non_alphanumeric': 0.2852328431372549, 'fraction_numerical': 0.060355392156862746, 'mean_word_length': 2.58397365532382, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5811162', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1301, 'n_words': 166}