const Discord = require('discord.js');

function random(low, high) {
    low = Math.ceil(low);
    high = Math.floor(high);
    high = high + 1;
    rndm = Math.random();
    return Math.floor(rndm * (high - low) + low);
}

/**
 * 
 * @param {Discord.Message} message 
 */
module.exports.execute = (message) => {
    // 69 nice haha le funny number
    if (message.content.toLowerCase().indexOf('69') > -1) {
        let replies = [
            'You said the funny number nice',
            'Haha funny 69',
            'You did a funny right here:\n> 69',
            'lmao funny number',
            'https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fi.kym-cdn.com%2Fentries%2Ficons%2Foriginal%2F000%2F016%2F588%2Fsixtynine.jpg&f=1&nofb=1',
            'youre\'r funny lmao',
            'haha funny sex number',
            'sex',
            '69 nice'
        ];
        
        let curIndex = 0;
        let continueSearch = true;
        let found = [];
        while (continueSearch) {
            if (message.content.toLowerCase().indexOf('69', curIndex) == -1) {
                continueSearch = false;
                break;
            }
            let f = message.content.toLowerCase().indexOf('69', curIndex);
            curIndex = f + 1;
            found.push(f);
        }
        delete continueSearch;
        delete curIndex;
        
        let send = false;
        found.forEach(index => {
            let charL = message.content.charAt(index - 1);
            let charR = message.content.charAt(index + 2);
            if ((isNaN(charL) || charL == '' || charL == ' ') && (isNaN(charR) || charR == '' || charR == ' ')) send = true;
        });
        
        if (send) message.channel.send(replies[random(0, replies.length - 1)]);
    }
}