-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
58 lines (48 loc) · 1.64 KB
/
Copy pathsetup.js
File metadata and controls
58 lines (48 loc) · 1.64 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
const fs = require("fs");
const readline = require("readline");
const CONFIG_FILE = "config.json";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const configExsists = fs.existsSync(CONFIG_FILE);
const shouldAutoAccept = process.argv.slice(2).some(x => [ "-y", "--yes", "--accept" ].includes(x));
if (configExsists) {
promptDeleteConfig(() => {
promptCreateConfig();
});
}
rl.on("close", () => {
process.exit(0);
});
promptCreateConfig();
function promptDeleteConfig(callback = undefined) {
if (shouldAutoAccept) process.exit(0);
rl.question(`File '${CONFIG_FILE}' already exists. Do you want to overwrite it? (y/N) `, answer => {
rl.pause(); // Do not 'close' to allow for other questions as well.
if (![ "y", "yes" ].includes(answer.toLowerCase())) {
process.exit(0);
}
callback && callback();
});
}
function promptCreateConfig(callback = undefined) {
rl.question("Enter the bot token: ", token => {
rl.question("Enter the owner's user ID: ", ownerID => {
if ([...ownerID].some(x => isNaN(parseInt(x)))) {
console.log("Owner ID is invalid!");
process.exit(1);
}
const configObj = {
botToken: token,
botOwnerID: ownerID
};
const configJSON = JSON.stringify(configObj, undefined, 2);
fs.writeFileSync(CONFIG_FILE, configJSON);
console.log(`-- created file '${CONFIG_FILE}' --`);
rl.close()
callback && callback();
})
});
}