-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
69 lines (62 loc) · 2.32 KB
/
start.js
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
59
60
61
62
63
64
65
66
67
68
69
const readline = require('readline');
const fs = require('fs')
const spawn = require("child_process").spawn;
let {PythonShell} = require('python-shell')
let rawdata = fs.readFileSync('./package.json');
let data = JSON.parse(rawdata);
const path = data.tokens
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function askQuestion(query) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise(resolve => rl.question(query, ans => {
rl.close();
resolve(ans);
}))
}
if (fs.existsSync(path)) {
PythonShell.run('./src/main.py', function (err) {
if (err) throw err;
});
} else {
console.log("Miscord was not able to detect a tokens.json file in the current directory.")
rl.question('Have it on another directory? Specify it here (leave in blank if not): ', (answer) => {
if (fs.existsSync(answer)) {
var newData = JSON.stringify(data).replace(/tokens/g, `"${answer}"`); //convert to JSON string
fs.truncate('package.json', 0, function(){
fs.writeFile('package.json', newData, 'utf8', callback);
});
newDataParsed = JSON.parse(newData)
fs.appendFile('.gitignore', newData.tokens, function (err) {
if (err) throw err;
});
PythonShell.run('./src/main.py', function (err) {
if (err) throw err;
});
} else {
console.log("\nMiscord was not able to detect a tokens.json file in the specified directory. It will now proceed to generate it.")
const ans = askQuestion("\nDiscord bot app token (https://discordapp.com/developers): ");
console.log(`\tBot token: ${ans}`);
var tokensJSON = {
table: []
};
const ans2 = askQuestion("\t\tGenius lib token: ");
console.log(`\t\t\tGenius token: ${ans2}`);
tokensJSON.table.push({discord_bot_token: ans, genius_login_token: ans2});
var json = JSON.stringify(tokensJSON);
fs.writeFile('tokens.json', json, 'utf8', callback);
console.log("Generated file")
fs.appendFile('.gitignore', path, function (err) {
if (err) throw err;
});
PythonShell.run('./src/main.py', function (err) {
if (err) throw err;
});
}
});
}