← Back to context

Comment by nedt

1 year ago

I just don't have enough time to do it manually. Writing a little script that automates crafting was quicker for me. It found me "Star Trek: The Rockapocalypse"

    const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); 
    
    let elements = [
        ' Water',
        ' Fire',
        ' Wind',
        ' Earth'
    ];
    
    let pairs = {};
    
    async function getResponse(left, right) {
        const url = `https://neal.fun/api/infinite-craft/pair?first=${left}&second=${right}`;
        return await (await fetch(url)).json();
    }
    
    function getRandom() {
        return elements[Math.floor(Math.random() * elements.length)];
    }
    
    async function run() {
        while (true) {
            let left = getRandom();
            let right = getRandom();
            if (pairs[`${left} + ${right}`]) {
                continue;
            }
            let result = await getResponse(left.split(' ').slice(1).join(' '), right.split(' ').slice(1).join(' '));
            if (result.isNew) {
                console.log('‼ new one ‼');
            }
            result = `${result.emoji} ${result.result}`;
            console.log(`${left} + ${right} = ${result}`);
            if (result != ' Nothing') {
                pairs[`${left} + ${right}`] = result;
                elements.push(result);          
            }
            await sleep(1000);      
        }
    }
    
    run();

A check has been added to the API. So you will be getting "Not allowed" as response now. I won't state what the check is, that would be an arms race. But it was fun for a day.