27 |
|
|
28 |
const CONFIG_DIR = path.resolve(__dirname, 'config'); |
const CONFIG_DIR = path.resolve(__dirname, 'config'); |
29 |
const { version } = require('./package.json'); |
const { version } = require('./package.json'); |
30 |
|
const { existsSync } = require('fs'); |
31 |
const SAMPLE_CONFIG_PATH = path.resolve(CONFIG_DIR, 'sample-config.json'); |
const SAMPLE_CONFIG_PATH = path.resolve(CONFIG_DIR, 'sample-config.json'); |
32 |
|
const CONFIG_PATH = path.resolve(CONFIG_DIR, 'config.json'); |
|
let prefix = '-', homeGuild = ''; |
|
33 |
|
|
34 |
const isSnowflake = text => /^\d+$/.test(text); |
const isSnowflake = text => /^\d+$/.test(text); |
35 |
|
|
56 |
fn = prompt; |
fn = prompt; |
57 |
} |
} |
58 |
|
|
59 |
const input = await fn(text); |
const input = await fn(text, defaultValue); |
60 |
|
|
61 |
if (!(await validator(input ?? ''))) { |
if (!(await validator(input ?? ''))) { |
62 |
return promptLoop(text, validator, defaultValue); |
return promptLoop(text, validator, defaultValue); |
74 |
return true; |
return true; |
75 |
}; |
}; |
76 |
|
|
77 |
|
let prefix = '-', homeGuild = '', owners = []; |
78 |
|
|
79 |
(async () => { |
(async () => { |
80 |
console.log(`SudoBot version ${version}`); |
console.log(`SudoBot version ${version}`); |
81 |
console.log(`Copyright (C) OSN Inc 2022`); |
console.log(`Copyright (C) OSN Inc 2022`); |
89 |
|
|
90 |
return true; |
return true; |
91 |
}, prefix)).trim(); |
}, prefix)).trim(); |
92 |
|
|
93 |
homeGuild = await promptLoop(`What will be the Home/Support Guild ID?: `, snowflakeValidator); |
homeGuild = await promptLoop(`What will be the Home/Support Guild ID?: `, snowflakeValidator); |
94 |
|
owners = (await promptLoop(`Who will be the owner? Specify the owner user IDs separated with comma (,): `, input => { |
95 |
|
const splitted = input.split(','); |
96 |
|
|
97 |
|
for (const snowflake of splitted) { |
98 |
|
if (!snowflakeValidator(snowflake)) { |
99 |
|
console.log(`Invalid snowflake given! Make sure that the IDs are correctly given!`); |
100 |
|
return false; |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
|
return true; |
105 |
|
})).split(',').map(s => s.trim()); |
106 |
|
|
107 |
|
let config = Object.entries(JSON.parse((await fs.readFile(SAMPLE_CONFIG_PATH)).toString())); |
108 |
|
config[1][0] = homeGuild; |
109 |
|
config[1][1].prefix = prefix; |
110 |
|
config = Object.fromEntries(config); |
111 |
|
|
112 |
|
config.global.id = homeGuild; |
113 |
|
config.global.owners = owners; |
114 |
|
|
115 |
|
console.log(config); |
116 |
|
|
117 |
|
if (existsSync(CONFIG_PATH)) { |
118 |
|
const input = await promptDefault("The config file (config/config.json) already exists. Do you want to overwrite the file? [y/N]: ", "n"); |
119 |
|
|
120 |
|
if (input.trim().toLowerCase() !== "y" && input.trim().toLowerCase() !== "yes") { |
121 |
|
console.log("Aborting setup."); |
122 |
|
rl.close(); |
123 |
|
process.exit(1); |
124 |
|
} |
125 |
|
} |
126 |
|
|
127 |
rl.close(); |
rl.close(); |
128 |
|
|