24 |
const path = require('path'); |
const path = require('path'); |
25 |
const fs = require('fs/promises'); |
const fs = require('fs/promises'); |
26 |
const readline = require('readline'); |
const readline = require('readline'); |
27 |
|
const bcrypt = require('bcrypt'); |
28 |
|
|
29 |
const CONFIG_DIR = path.resolve(__dirname, 'config'); |
const CONFIG_DIR = path.resolve(__dirname, 'config'); |
30 |
const { version } = require('./package.json'); |
const { version } = require('./package.json'); |
139 |
} |
} |
140 |
} |
} |
141 |
|
|
|
rl.close(); |
|
|
|
|
142 |
if (existsSync(CONFIG_PATH)) |
if (existsSync(CONFIG_PATH)) |
143 |
await fs.rename(CONFIG_PATH, path.join(CONFIG_DIR, 'config-old-' + Math.round(Math.random() * 100000) + '.json')); |
await fs.rename(CONFIG_PATH, path.join(CONFIG_DIR, 'config-old-' + Math.round(Math.random() * 100000) + '.json')); |
144 |
|
|
145 |
await fs.writeFile(CONFIG_PATH, JSON.stringify(config, undefined, ' ')); |
await fs.writeFile(CONFIG_PATH, JSON.stringify(config, undefined, ' ')); |
146 |
|
|
147 |
console.log("Setup complete!"); |
console.log("Config File Created!"); |
148 |
console.table([ |
console.table([ |
149 |
{ |
{ |
150 |
prefix, |
prefix, |
151 |
homeGuild |
homeGuild |
152 |
} |
} |
153 |
]); |
]); |
154 |
|
|
155 |
|
if (!existsSync(path.join(__dirname, ".env"))) { |
156 |
|
const input = (await promptDefault("Generate a `.env' file? [y/N]: ", "n")).toLowerCase(); |
157 |
|
|
158 |
|
if (input !== 'yes' && input !== 'y') { |
159 |
|
return; |
160 |
|
} |
161 |
|
|
162 |
|
const token = await promptLoop("What's your bot token? ", input => { |
163 |
|
if (input.trim() !== '' && input.indexOf(' ') === -1) { |
164 |
|
return true; |
165 |
|
} |
166 |
|
|
167 |
|
console.log("That's not a valid token."); |
168 |
|
return false; |
169 |
|
}); |
170 |
|
|
171 |
|
const clientID = await promptLoop("What's your bot's client ID? ", snowflakeValidator); |
172 |
|
|
173 |
|
const mongoURI = await promptLoop("Enter the MongoDB URI for the bot to connect: ", input => { |
174 |
|
if (input.trim() !== '' && input.indexOf(' ') === -1) { |
175 |
|
return true; |
176 |
|
} |
177 |
|
|
178 |
|
console.log("That's not a valid MongoDB URI."); |
179 |
|
return false; |
180 |
|
}); |
181 |
|
|
182 |
|
const jwtSecret = (await promptLoop("Enter a JWT secret key (hit enter to generate automatically): ", input => { |
183 |
|
if (input.trim() !== '') { |
184 |
|
return true; |
185 |
|
} |
186 |
|
|
187 |
|
console.log("That's not a valid secret."); |
188 |
|
return false; |
189 |
|
}, null)) ?? bcrypt.hashSync(Math.random() + '', bcrypt.genSaltSync()); |
190 |
|
|
191 |
|
const webhook = await promptLoop("Enter a webhook URL for sending debug logs: ", input => { |
192 |
|
if (input.trim() !== '' && input.indexOf(' ') === -1) { |
193 |
|
return true; |
194 |
|
} |
195 |
|
|
196 |
|
console.log("That's not a valid webhook URL."); |
197 |
|
return false; |
198 |
|
}); |
199 |
|
|
200 |
|
await fs.writeFile(path.join(__dirname, ".env"), `# Environment Configuration |
201 |
|
|
202 |
|
TOKEN=${token} |
203 |
|
ENV=dev |
204 |
|
CLIENT_ID=${clientID} |
205 |
|
GUILD_ID=${homeGuild} |
206 |
|
MONGO_URI=${mongoURI} |
207 |
|
JWT_SECRET=${jwtSecret} |
208 |
|
DEBUG_WEBHOOK_URL=${webhook} |
209 |
|
`); |
210 |
|
} |
211 |
|
|
212 |
|
rl.close(); |
213 |
})().catch(console.error); |
})().catch(console.error); |