const { program } = require('commander') const fetch = require('node-fetch'); const javalon = require('javalon') program .option('-d, --debug', 'Output extra debugging') .option('-U, --url ', 'Talk to an alternate blacklist service', "https://avalonblacklist.nannal.com/") .option('-l,--list ', 'Which list to add the target to', "black") .option('-a,--approve ', 'Expand the list of approved list editors') .option('-r,--reason ', 'Justify why a user should be added to the provided list') .option('-t,--target ', 'Which user will be added to the list') .requiredOption('-k,--key ', 'Any valid private key for your DTube user') .requiredOption('-u,--user ', 'Your DTube username') program.parse(process.argv) if (!program.list=="black" && program.approve){ console.log("Please choose either -a or -l, you can't approve and add someone to a list at the same time") } else if (program.target && !program.reason) { console.log("Please inform other users why you put the user on the chosen list") } else { if (program.approve){ approve() } else if (program.list) { addToList() } else { console.log("Please choose either -a or -l, you can't approve and add someone to a list at the same time") } } async function approve() { body = javalon.sign(program.key, program.user, {user:program.approve}) console.log(body) const response = await fetch(program.url+'approve', { method: 'post', body: JSON.stringify(body), headers: {'Content-Type': 'application/json'} }); const json = await response.json(); console.log(json); } async function addToList() { body = javalon.sign(program.key, program.user, {user: program.target, status: program.list, reason: program.reason}) const response = await fetch(program.url+'submit', { method: 'post', body: JSON.stringify(body), headers: {'Content-Type': 'application/json'} }); const json = await response.json(); console.log(json); }