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); |
78 |
console.log(`SudoBot version ${version}`); |
console.log(`SudoBot version ${version}`); |
79 |
console.log(`Copyright (C) OSN Inc 2022`); |
console.log(`Copyright (C) OSN Inc 2022`); |
80 |
console.log(`Thanks for using SudoBot! We'll much appreciate if you star the repository on GitHub.\n`); |
console.log(`Thanks for using SudoBot! We'll much appreciate if you star the repository on GitHub.\n`); |
81 |
|
|
82 |
|
let prefix = '-', homeGuild = '', owners = []; |
83 |
|
let config = Object.entries(JSON.parse((await fs.readFile(SAMPLE_CONFIG_PATH)).toString())); |
84 |
|
|
85 |
prefix = (await promptLoop(`What will be the bot prefix? [${prefix}]: `, input => { |
config[1][1].prefix = (await promptLoop(`What will be the bot prefix? [${prefix}]: `, input => { |
86 |
if (input.trim().includes(' ')) { |
if (input.trim().includes(' ')) { |
87 |
console.log(`Prefixes must not contain spaces!`); |
console.log(`Prefixes must not contain spaces!`); |
88 |
return false; |
return false; |
89 |
} |
} |
90 |
|
|
91 |
return true; |
return true; |
92 |
}, prefix)).trim(); |
}, "-")).trim(); |
93 |
|
|
94 |
homeGuild = await promptLoop(`What will be the Home/Support Guild ID?: `, snowflakeValidator); |
homeGuild = await promptLoop(`What will be the Home/Support Guild ID?: `, snowflakeValidator); |
95 |
|
config[1][0] = homeGuild; |
96 |
|
|
97 |
|
config = Object.fromEntries(config); |
98 |
|
|
99 |
|
config.global.id = homeGuild; |
100 |
|
config.global.owners = (await promptLoop(`Who will be the owner? Specify the owner user IDs separated with comma (,): `, input => { |
101 |
|
const splitted = input.split(','); |
102 |
|
|
103 |
|
for (const snowflake of splitted) { |
104 |
|
if (!snowflakeValidator(snowflake)) { |
105 |
|
console.log(`Invalid snowflake given! Make sure that the IDs are correctly given!`); |
106 |
|
return false; |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
return true; |
111 |
|
})).split(',').map(s => s.trim()); |
112 |
|
|
113 |
|
// config[1][0] = homeGuild; |
114 |
|
// config[1][1].prefix = prefix; |
115 |
|
|
116 |
|
// config.global.owners = owners; |
117 |
|
|
118 |
|
const guildConfig = {...config[homeGuild]}; |
119 |
|
|
120 |
|
guildConfig.mod_role = await promptLoop(`What will be the moderator role ID?: `, snowflakeValidator); |
121 |
|
guildConfig.admin = await promptLoop(`What will be the safe role ID?: `, snowflakeValidator); |
122 |
|
guildConfig.mute_role = await promptLoop(`What will be the muted role ID?: `, snowflakeValidator); |
123 |
|
guildConfig.gen_role = await promptLoop(`What will be the general role ID? [${homeGuild}]: `, snowflakeValidator, homeGuild); |
124 |
|
guildConfig.logging_channel = await promptLoop(`What will be the main logging channel ID?: `, snowflakeValidator); |
125 |
|
guildConfig.logging_channel_join_leave = await promptLoop(`What will be the join/leave logging channel ID?: `, snowflakeValidator); |
126 |
|
|
127 |
|
config[homeGuild] = guildConfig; |
128 |
|
|
129 |
|
console.log(config); |
130 |
|
|
131 |
|
if (existsSync(CONFIG_PATH)) { |
132 |
|
const input = await promptDefault("The config file (config/config.json) already exists. Do you want to overwrite the file? [y/N]: ", "n"); |
133 |
|
|
134 |
|
if (input.trim().toLowerCase() !== "y" && input.trim().toLowerCase() !== "yes") { |
135 |
|
console.log("Aborting setup."); |
136 |
|
rl.close(); |
137 |
|
process.exit(1); |
138 |
|
} |
139 |
|
} |
140 |
|
|
141 |
rl.close(); |
rl.close(); |
142 |
|
|
143 |
|
if (existsSync(CONFIG_PATH)) |
144 |
|
await fs.rename(CONFIG_PATH, path.join(CONFIG_DIR, 'config-old-' + Math.round(Math.random() * 100000) + '.json')); |
145 |
|
|
146 |
|
await fs.writeFile(CONFIG_PATH, JSON.stringify(config, undefined, ' ')); |
147 |
|
|
148 |
console.log("Setup complete!"); |
console.log("Setup complete!"); |
149 |
console.table([ |
console.table([ |
150 |
{ |
{ |