File size: 1,398 Bytes
30c32c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const uid = require('./uid');
const alwaysUnsafe = [
    "jgPrism_evaluate",
    "jgPrism_evaluate2",
    "jgPrism_evaluate3",
    "jgFiles_downloadFile",
    "videoSensing_videoToggle",
    "jgPrism_screenshotStage"
];

/**
 * gets if the current save contains any of the listed blocks
 * @param {array} blockOpcodes a list of blocks to check for
 * @param {array} targets all the current targets in the save
 * @returns {boolean} if any of the listed blocks are in save
 */
const workspaceContains = (blockOpcodes, targets) => {
    for (const target of targets) {
        for (const block of Object.keys(target.blocks._blocks)) {
            if (blockOpcodes.includes(block.opcode)) return true;
        }
    }
    return false;
};

/**
 * asks a user if they agree to something
 * @param {string} msg the what to ask the user for
 * @param {array} targets all of the current targets
 * @returns {boolean} if the user agreed to it or not
 */
const ask = (msg, targets) => {
    if (workspaceContains(alwaysUnsafe, targets)) {
        const confirmId = uid();
        const userAccepts = prompt(
            `${msg}\nto confirm type "${confirmId}"`, 
            `to confirm type the text above`
        );
        return userAccepts === confirmId;
    }
    const userAccepts = prompt(msg, 'i decline');
    return userAccepts === 'yes' || userAccepts === 'i accept';
};

module.exports = ask;