-
Notifications
You must be signed in to change notification settings - Fork 6
/
Setup.js
96 lines (78 loc) · 4.55 KB
/
Setup.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const notifier = require('node-notifier');
const fs = require('fs');
const path = require('path');
const Logger = require('./Module/Logger');
const { Login, Prompt } = require('./Module/TokenInit');
const { FileManager } = require('./Module/FileManager');
const { ConfigManager } = require('./Module/Manager');
const Utils = require('./Module/Utils');
const { version: ClientVersion } = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8"))
const { github: ClientGithub } = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8"))
const { author } = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8"));
const Creator = author?.name || "Unknown Author";
function Tag() {
console.log(`
██╗ ██╗██╗ ██╗██╗ ██╗██╗ ██╗██████╗ ██╗ ██████╗██╗ ██╗███████╗███╗ ██╗████████╗
██║ ██╔╝██║ ██║██║ ██╔╝██║ ██║██╔══██╗██║ ██╔════╝██║ ██║██╔════╝████╗ ██║╚══██╔══╝
█████╔╝ ██║ ██║█████╔╝ ██║ ██║██████╔╝██║ ██║ ██║ ██║█████╗ ██╔██╗ ██║ ██║
██╔═██╗ ██║ ██║██╔═██╗ ██║ ██║██╔══██╗██║ ██║ ██║ ██║██╔══╝ ██║╚██╗██║ ██║
██║ ██╗╚██████╔╝██║ ██╗╚██████╔╝██║ ██║██║ ╚██████╗███████╗██║███████╗██║ ╚████║ ██║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝╚══════╝╚═╝╚══════╝╚═╝ ╚═══╝ ╚═╝
`)
Logger.info(`Made by ${Creator} (${ClientGithub})`);
Logger.info(`Client version: ${ClientVersion}`)
}
async function main() {
Tag()
await Utils.sleep(2000)
const fileManager = new FileManager();
const configManager = new ConfigManager();
const updateChoice = await Prompt.ask('Do you want to run Update? (y/n): ');
if (updateChoice.toLowerCase() === 'y') {
Logger.info('Starting Update process...');
await fileManager.checkMissingFiles();
await fileManager.installDependencies();
process.exit(0);
}
Utils.clear();
Tag()
await Setup(fileManager, configManager);
}
async function Setup(fileManager, configManager) {
Logger.info('Setup service Started!');
// Load or create settings config
const settingsConfig = configManager.getDefaultConfigs().settings;
settingsConfig.notification = (await Prompt.ask('Enable Desktop Notifications? (y/n): ')).toLowerCase() === 'y';
settingsConfig.prefix = await Prompt.ask('Set new prefix? (default is .): ');
settingsConfig.webhook = await Prompt.ask('Enter Discord Webhook URL (optional): ');
configManager.saveConfig('settings', settingsConfig);
// Handle login and save token
try {
const login = new Login();
const token = await login.start();
configManager.saveConfig('token', { token });
} catch (error) {
Logger.expection(`Login failed: ${error.message}`);
return;
}
// Save default client config
configManager.saveConfig('client', configManager.getDefaultConfigs().client);
// Validate all configs
if (!configManager.validateConfigs()) {
Logger.expection('Setup failed due to invalid configurations');
return;
}
notifier.notify({
title: 'Kukuri Client',
message: 'Setup Complete!',
sound: true,
wait: false
});
Logger.load('Setup successfully! All configurations saved');
// Check and download missing files
await fileManager.checkMissingFiles();
Logger.warning("Server setup successfully! You can now run Start.js")
}
main().catch(error => {
Logger.expection(`Something went wrong: ${error.message}`);
});